jabal
jabal

Reputation: 12347

How to make bash suppose all commands to be git commands?

Can I make bash to suppose the command always to be a git command?

I mean:

If I wrote push origin master then it would execute git push origin master?

Note: I would use it in git bash (Windows environment), so I do not need regular commands (ls, cd, etc.) to work.

Upvotes: 3

Views: 106

Answers (4)

chepner
chepner

Reputation: 531375

You may want to try this small git shell, instead:

gitsh () {
    while read -r -p "gitsh> " -a GITCOMMAND; do
        git "${GITCOMMAND[@]}"
    done
}

After that function is defined, run it once, and it will sit in an infinite loop, reading a command line and passing it as options to the git command.

EDIT: Adding the -e option to the read command, as suggested by gniourf_gniourf, gives you a nice Readline-based environment where you can retrieve and edit your history.

Upvotes: 2

glenn jackman
glenn jackman

Reputation: 246877

Assuming "git bash" is like regular bash, use the command_not_found_handle function:

function command_not_found_handle {
  command git "$0" "$@"
}

http://www.gnu.org/software/bash/manual/bashref.html#Command-Search-and-Execution

The possibility for sending git inadvertent commands exists, but that's what you're asking for in the question.

Upvotes: 1

Pedro Lamarão
Pedro Lamarão

Reputation: 531

You may add scripts named push, commit etc. to your PATH. This way your shell would have push, commit etc. "commands". This should work with whatever shell you are using, not only bash.

Upvotes: 0

samuil
samuil

Reputation: 5081

You could add aliases for commonly used commands e.g. push would become git push etc. This solution needs to specify all commands you are using, but should not break anything.

Upvotes: 2

Related Questions