zsh git autocomplete: __git_find_on_cmdline error
Asked Answered
C

1

3

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?

Copycat answered 20/5, 2021 at 16:58 Comment(2)
script ~/.zsh/git-completion.bash Bash completion in zsh? Shouldn't it also be zsh completion?Atombomb
The bash completion scripts are not always zsh-compatible. There's ongoing work to fix this up, but when they don't work, it just means someone missed something. You can use bash instead of zsh, or use the zsh scripts, or participate in the ongoing work, or whatever you like, here.Spiraea
G
8

Zsh ships with excellent Git completion out of the box. Just throw everything you posted away, except this:

autoload -Uz compinit
compinit

Then it'll work just fine.

Grande answered 20/5, 2021 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.