Git completion not working in zsh on OS X Yosemite with Homebrew
I just stumbled upon the answer!
In my case I was missing a few important pieces in my .zshrc
file. But first a little background:
What I'm trying to do is setup the "zsh Completion System". It comes with a lot of commands all named something with comp*
. I tried to run these a few times but in many cases zsh would just tell me it didn't know them. So aparently you have to autoload
them, among other things.
This is what I did:
I added the following lines to my .zshrc
file:
autoload -U compinit && compinit
zmodload -i zsh/complist
Then I opened a new terminal and ran:
rm -f ~/.zcompdump; compinit
Then I opened a new terminal and now git <tab>
worked as expected :)
If you are setting up a custom $fpath
in your .zshrc
file I would recommend adding these lines after you've modified the $fpath
(though I don't know if it makes a difference).
Since macOS Catalina,...
Apple has switched from bash to zsh as their default shell.
Now the only brew command you need to activate zsh-completion (which includes git completion) is this...
brew install zsh-completion
Then add this block to your ~/.zshrc file (which you may have to create first):
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
See my answer on AskDifferent for more details:
https://apple.stackexchange.com/a/392382/77452