No matter what I try and do I can't seem to make git tab/auto completion work in my zsh shell. I've downloaded the bash-completion script and the zsh-completion one and followed the instructions, but I can't make it work.
I've reinstalled oh-my-zsh but that didn't seem to help or make any difference.
Can anyone who's got it working describe to me their setup so I can try an emulate it to get it working for me?
To be specific, what I've done so far is:
~/.completion/git/git-completion.sh
~/.zsh/_git
zstyle ':completion:*:*:git:*' script ~/.completion/git/git-completion.sh
No luck.
Actually, ZSH does know how to do git completion out of the box, but you need to turn on the completion feature itself (which from the steps you described I guess you haven't done)
Adding this to your .zshrc
should be enough:
autoload -Uz compinit && compinit
After you put the line .zshrc
file, don't forget to restart the shell for ZSH to pick up the new config (alternatively, you can execute the line in your current session, that'll enable autocompletion for that one session)
By using the following commands in a terminal, the above-mentioned command can easily be added to the ".zshrc" file even if there is no such a file and you do not need to restart the terminal.
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
source ~/.zshrc
For more info see here https://git-scm.com/book/en/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Zsh
PS Another answer here suggests installing the hub
tool instead: although the tool is handy, it's merely a 3rd party (github community) wrapper around git. Hence, it has nothing to do with the topic of "Git completion in ZSH"