Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Update git completion on macOS



jost.schulte@xxxxxxxxxxxx wrote:
> Here's my problem: Running on macOS 10.15, I've set up zsh with completion of
> git commands. It must be the complete function that comes with the os
> installation of zsh, because I didn't add it and I don't use oh-my-zsh. In
> this complete function the newer git commands like "switch" or "restore" are
> not included, so I want to update it.

The best way to do this would be to install a newer zsh on your system.
A common way to do this on macOS is to use something like macports,
homebrew or fink. These install an additional zsh in somewhere like
/opt/local/bin/zsh and leave the system one alone. You could also
take the more manual approach of downloading the source code tarball,
unpacking it and running ./configure followed by make and make install.

> I've researched a while and found the function in /usr/share/zsh/5.7.1/
> functions/ in the file _git. What I couldn't find is a current complete
> function and also I wasn't able to modify the contents of the file. Even using
> "sudo" I get the error that I don't have permissions to edit it.
>
> Can anyone help me out please?

Overwriting system installed files is not a good idea in general. If you
want to use a modified completion function, the best approach is to put
it in a dedicated directory and point zsh to look in that directory
before the system directories.

So you might do:

  mkdir ~/.zfunc

Install your custom _git in there. Then in your .zshrc file you would
need to add ~/.zfunc to the beginning of the $fpath array. So you might
have a line like:

  fpath=( ~/.zfunc $fpath )

But note that this needs to come before you run compinit to enable the
completions.

To get a current completion function, the best approach is to checkout
the zsh sources from git and look below the Completion directory. Mostly
that will work but in this particular case, I happen to know that it
won't. The latest _git function makes use of new zsh features that were
only added after zsh 5.7. You might be able to manually patch together
an _git that does what you want. The patch for git switch and restore is
here:
  https://www.zsh.org/mla/workers/2019/msg00815.html

If it doesn't apply cleanly to the file you have for 5.7.1, grabbing
just the _git-restore and _git-switch functions should be sufficient.

Oliver




Messages sorted by: Reverse Date, Date, Thread, Author