Fri 21 Dec 2007
Git is split up into a whole bunch of executables like git-commit and git-status, but you can also run them by doing git commit and git status. Cool, right? But it doesn’t work with your own scripts, so you can’t just put git-wip in your PATH and have it work. To fill this need I cooked up a Zsh function that does what git should be doing itself:
git() {
for p in $(echo $PATH | tr ':' '\n'); do
if [[ -x "$p/git-$1" ]]; then
eval "$p/git-$1 $argv[2,-1]" && return
fi
done
eval "/usr/bin/env git $argv"
}
Update: The above function has the annoying side-effect that if the git command fails or any valid reasons (such as canceling a commit by not providing any message), it’ll try to run it again. For that reason, and since Coda showed me how to shell out with git aliases, I recommend not using this function.