Hi everyone, I wanted to search the archive before posting, following the documentation, but I don't see an archive link in the list menu. 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. 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?
> On Oct 23, 2020, at 4:16 AM, jost.schulte@tutanota.com 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. > > 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? Assuming that installing 5.8 isn't an option, I think your best bet is to extract _git from 5.8 (http://zsh.sourceforge.net/Arc/source.html) and modify your fpath so the completion system finds it before the system's outdated copy. It's fine to keep it somewhere in your home directory. (Hopefully the 5.8 _git works with 5.7.1, but if it doesn't you can always edit it.) vq
On Fri, Oct 23, 2020 at 10:42 AM Lawrence Velázquez <vq@larryv.me> wrote: > > Assuming that installing 5.8 isn't an option [...] To expand on this: The best solution would be to upgrade to zsh 5.8. Apart from adding support for `git switch` and `git restore` commands, it has many other improvements compared to 5.7.1. The most common and perhaps the easiest way to install zsh 5.8 on macOS is via Homebrew: brew install zsh If you don't have the `brew` command, you'll need to install it first. See https://brew.sh/. Roman.
jost.schulte@tutanota.com 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
Oliver Kiddle wrote on Fri, 23 Oct 2020 08:49 +00:00:
> 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.
If you do, feel free to publish the patch. The idea of a "backport
branch" of the Completion/ tree has been raised before; it simply lacks
a volunteer to drive it.
Cheers,
Daniel
P.S. I always treated that underscore as silent...