2
There's something I don't understand about Git and completion in Zsh.
I am using a Windows machine with Git (v2.11. for Windows) and Cygwin with Zsh (with Babun). When I type git checkout
and hit TAB
twice, I get a completion prompt for branches and object names:
Pretty neat! Now, on my OS X machine with Git (2.13.0 for Mac, installed via Homebrew) and Zsh, when I type git checkout
and hit TAB
twice, I only get this:
Where does the functionality in the first prompt come from? In other words, what do I have to install under OS X / Zsh to make that happen?
Some things I tried:
- I've already ruled out that it's Oh-my-Zsh's
git
plugin doing it, because when I disable that under Windows/Cygwin, I still get the same fancy completion. - All I have to do in Windows starting with an empty
.zshrc
to get this completion to work is to runautoload -U compinit && compinit
- I tried adding
fpath=(/usr/local/share/zsh/site-functions/ $fpath)
to my.zshrc
in the hope that it'd pick up what Homebrew installed (as mentioned in thebrew info git
output), but it didn't change anything. - I tried installing
zsh-completions
from Homebrew, addingfpath=(/usr/local/share/zsh-completions $fpath)
to my.zshrc
as suggested. Still no change. - What confuses me even more is that recently, I used a MacBook from a colleague who didn't know much about Git. He had only Git installed. He got the same extended completion without having configured anything.
- My
.zcompdump
, if that helps: https://pastebin.com/raw/UzrZ2NqD - My
.zshrc
: https://github.com/slhck/dotfiles/blob/master/.zshrc
Some more debugging output from OS X, when I type git
, then Ctrl-X
, then h
:
tags in context :completion::complete:git::
argument-1 options (_arguments __git_zsh_main _git)
use-compctl (_default _git)
globbed-files (_files _default _git)
tags in context :completion::complete:git:argument-1:
alias-commands common-commands all-commands (__git_zsh_main _git)
alias-commands (__git_zsh_cmd_alias __git_zsh_main _git)
common-commands (__git_zsh_cmd_common __git_zsh_main _git)
all-commands (__git_zsh_cmd_all __git_zsh_main _git)
Whereas when I do the same on Windows/Cygwin, I get:
tags in context :completion::complete:git::
argument-1 options (_arguments _git)
tags in context :completion::complete:git:argument-1:
aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)
Output of ls -l ${^fpath}/_git
ls: /Users/werner/.oh-my-zsh/completions/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/functions/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/brew/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/docker-compose/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/docker/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/gem/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git-extras/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git-flow/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/git/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/github/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/osx/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/python/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/rails/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/ruby/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/svn/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/vagrant/_git: No such file or directory
ls: /Users/werner/.oh-my-zsh/plugins/virtualenv/_git: No such file or directory
ls: /usr/local/share/zsh-completions/_git: No such file or directory
-rw-r--r-- 1 werner admin 336270 Dec 21 19:42 /usr/local/Cellar/zsh/5.3.1/share/zsh/functions/_git
lrwxr-xr-x 1 werner admin 56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
lrwxr-xr-x 1 werner admin 56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
lrwxr-xr-x 1 werner admin 56 May 18 17:26 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
Can you please check the zsh version numbers on both machines? With the current git version (5.3.1-dev-0) I get your desired behavior. The relevant completion function has a size of 336319 bytes (usually installed under
/usr/share/zsh/VERSION/functions/_git
, although I don't know anything about homebrew...). – mpy – 2017-05-18T16:34:11.257I'm using 5.3.1 on the Mac. Does
.zcompdump
help in troubleshooting? See the pastebin link in my updated post. – slhck – 2017-05-18T17:06:05.863There are several
_git
functions autoloaded according to your.zcompdump
. Please provide the output ofls -l ${^fpath}/_git
. – mpy – 2017-05-18T17:34:02.770Added to the post. I also cannot get this kind of completion to work with a completely new user account, when I just open Terminal, enter
/usr/local/bin/zsh
, runautoload -U compinit && ocmpinit
. – slhck – 2017-05-18T17:57:42.247To be honest, that's not what I expected. My assumption was, that there are several
_git
completion functions in your$fpath
, of which at least one is outdated. To rule out that you have some weird global config, can you runzsh -f
(load almost no config files) and try again -- afterautoload -U compinit && compinit
of course. My$fpath
in that case consists of/usr/local/share/zsh/site-functions
,/usr/share/zsh/site-functions
and/usr/share/zsh/5.3.1-dev-0/functions
. – mpy – 2017-05-18T18:20:29.537Hm, no dice, my fpath being
/usr/local/share/zsh/site-functions /usr/local/Cellar/zsh/5.3.1/share/zsh/functions
in that case. Which does link to../../../Cellar/git/2.13.0/share/zsh/site-functions/_git
. I'm thinking about nuking everything (at least Zsh, Git, and the various plugins) and starting from scratch… – slhck – 2017-05-18T18:29:39.887Solved the issue, although I think it's a bug with whatever Homebrew does w.r.t. the Git completions it installs for Zsh. – slhck – 2017-05-18T18:41:30.410