zsh completion seems not work on most distros except openSUSE
Current implementation of zsh completion for tig relies upon _git completion installed from git-core package (from git's contrib/completion/git-completion.zsh into /usr/share/zsh/site-functions/_git). This is true for openSUSE only! See for reference https://pkgs.org/search/?q=_git&on=files (Only in openSUSE it's installed from zsh and git-core, with git-core's version overriding zsh's version).
For all other distribution (I tested on Fedora, Ubuntu, and ALT) the _git is installed into /usr/share/zsh/Completion/Unix/_git from zsh package itself. This is completely different script maintained by Zsh community, it's richer, and is not compatible with _tig completion script.
This causes zsh completion for tig to not fully work on all distributions except for openSUSE.
On Fedora bash completion is sourced and it seems only file completion is working, but not commands and options.
On Ubuntu tig completes as an alias for git log (because zsh's _git have this and only this defined).
On ALT _tig is installed from contrib/tig-completion.zsh making completion to not work at all, because _git is from zsh and not from git-core.
I'm not expert in zsh so cannot suggest a right solution for this. But you may know there are problems.
Here's an alternate _tig completion script which uses the zsh authored completions:
#compdef tig
#description tui for git
_tig() {
_arguments -C -S -s \
'-C=[start in path]' \
': :->command' \
'*::: := ->option-or-argument'
case $state in
(command)
local -a commands
commands=(
blame:'start a blame viewer'
grep:'print lines matching a pattern'
log:'show commit logs'
reflog:'manage reflog information'
refs:'display branches, remotes and tags'
stash:'manage stash entries'
status:'show working-tree status'
show:'show various types of objects'
)
_alternative \
'commands:: _describe -t commands command commands' \
'arguments:: _git-log' && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*}-$line[1]:
case $line[1] in
(-*|--)
words=(log "${words[@]:1}")
_git-log
;;
(blame)
_git-blame
;;
(grep)
_git-grep
;;
(log)
_git-log
;;
(reflog)
_git-reflog
;;
(refs)
_git-branch
;;
(stash)
_git-stash
;;
(status)
_git-status
;;
(show)
_git-show && ret=0
;;
esac
esac
return ret
}
_git # force git completion functions to load
_tig
I'm not an expert, but i know enough to get stuff like this working. Tested on macOS with homebrew.
Thanks @forivall. We don't want Tig to depend on anything else than Git so it would not make sense to include your implementation in Tig. However it would be incredibly valuable if you could submit a PR to https://github.com/zsh-users/zsh. This way, those who want to install their specific _git implementation could also benefit from a corresponding _tig.
Cool. I'll probably submit them to https://github.com/zsh-users/zsh-completions instead of core zsh.