Tweaking zsh git autocompletion

I just switched from bash to using zsh 4.3.4 on Ubuntu Hardy. I'm developing with git and I find myself constantly fighting with the default git completions: filename completion tries to be smart by detecting what you've added or removed (using git-ls-files) but sometimes it gets things wrong---e.g., if you are in a sub-directory. It also doesn't know about my custom git aliases (e.g., git ci as an alias for commit).

zsh superusers, how should I improve this situation?

Here are some of my thoughts, though I don't know how to implement them as I'm new to zsh, so maybe you can help or offer your own:

  • Disable git filename completion, leaving just branch/tag/command-name/command-option completion.
  • Replace the "smart" filename completion with the regular zsh filename completion.
  • Get a newer _git completion file, if it fixes these bugs, and override the system one.

Thanks!


For large projects, even the newer git completion scripts are far too slow. To disable them and just use normal file completion, place the following command in your .zshrc:

compdef -d git

Try upgrading to the latest version of Zsh. I just upgraded from 4.3.4 to 4.3.10 and it at least fixes the problem with Git aliases not completing.

Instead of hacking my installation I added this to my local .zshrc:

customzsh=/usr/local/src/zsh-4.3.10/bin/zsh-4.3.10
if [ "$SHELL" != "$customzsh" ]; then
  export SHELL=$customzsh
  exec $customzsh
fi