Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I feel like this should be straighforward to some degree...

Basically, for some command, I want to be able to invoke another command that will scope all params to that command. so...

git commit -am "test"

would become...

./shell_comand git
>commit -am "test"

so, obviously things like autocomplete and whatnot wouldn't work, but I would expect otherwise this should be doable to some degree? I'm just not quite clear on how...

share|improve this question

I assume this should be doable in git itself, but since I'm no git expert I would use at shell functions. In a sh-compatible one (e.g. bash) you can easily write a function called git which will be invoked instead of the git binary (be careful to use full path to the binary inside of the function - or command git in BASH - to prevent unwanted recursion):

function git () {
    case "$1" in
        # do your stuff
        /path/to/git ...
        # call git binary with the same arguments
        /path/to/git "$@"

You could use just command aliasing (alias), but functions give you way more flexibility.

As for the completion, check your shell completion functionality (for bash look for complete in the man page) - it's certainly possible to make it work and it doesn't even have to be too complicated.

share|improve this answer
Instead of /path/to/git you could write command git – glenn jackman Jan 1 '13 at 20:55
@glennjackman thanks, updating. – peterph Jan 1 '13 at 21:20

One way would be to define aliases for every git command. You could still run ordinary shell commands; if this is not desired, set PATH to a nonexistent directory. If you want to run the shell command and not the git command, put a backslash before the command (e.g. \rm foo to remove a file).

git_commands=$(COLUMNS=2 git --help --all | sed -n -e '1,/^----/d' -e '1,/^$/p')
for c in $git_commands; do
  alias "$c=git $c"

In zsh, you'll even have completion if you have the complete_aliases option set. I don't know about bash.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.