Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.