Super User is a question and answer site for computer enthusiasts and power users. 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

So I have this (bad) habit of typing git , pausing for a sec to glance at the output of the git status command I just typed, then typing git add ... afterwards, resulting in the rather unsuccessful git git add ....

Is there any functionality of zsh that would allow me to always replace git git with its singular equivalent?

share|improve this question
haha I did that exact thing yesterday with another command. wish i could help but i'm a bash user and don't understand that fancy z-shell. :) – quack quixote Oct 4 '09 at 1:48
i do this all the time – Roy Rico Oct 4 '09 at 1:58
up vote 3 down vote accepted

I can't edit comments, so here is a working version for all bourne shells:

git(){ if [ "$1" = git ]; then shift; fi; command git "$@"; }
share|improve this answer
This seems to work brilliantly - many thanks. My shell-fu is quite weak, but I've slowly been strengthening and this shows more than a few things I think will come in handy. – Rufo Sanchez Oct 4 '09 at 19:12

One way would be with a wrapper function:

function git { if [[ $1 == "git" ]]; then shift; fi; /path/to/git $@; }

This discards the second "git" if it's present and runs git with the parameters requested. This should work in zsh, Bash and ksh.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .