gitzsh

zsh git autocomplete: __git_find_on_cmdline error


I am trying to get git autocomplete working with zsh and am running into a weird error (even though the autocomplete appears to complete successfully):

Installation:

mkdir -p ~/.zsh
cd ~/.zsh
curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh

Added to ~/.zshrc:

zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)

autoload -Uz compinit && compinit

I open a new shell and run git checkout + "ty" + tab and I expect it to autocomplete with "typescript" with no errors:

raine[npm-check-updates]% gc ty__git_find_on_cmdline:[:7: unknown condition: -lt                                    ✓
__git_find_on_cmdline:[:7: unknown condition: -lt
__git_find_on_cmdline:[:7: unknown condition: -lt
pescript

It does autocomplete to "typescript" but with an error in between, right where I hit tab. What is causing this and how do I make it go away?


Solution

  • Zsh ships with excellent Git completion out of the box. To make it work, the only thing you need to do is have this in your ~/.zshrc file:

    autoload -Uz compinit
    compinit