
It happened When I input tig and then tap ‘tab’ button.
zsh:12: command not found: __tig_main
Some info:
tig --version
tig version 2.4.1
ncurses version 5.7.20081102
readline version 8.0
git --version
git version 2.22.0
I have/had the same problem.
I installed the completion file from this repository to ~/.completion but it did not work.
reading in the logs of zsh -lx I saw that some _git completion file was loaded and defined _tig I found this in /usr/share/zsh/functions/Completion/Unix/_git which is probably different for you, but it might hint in the right direction.
I renamed that file so it gets ignored by zsh-completion and now the completion file that comes with this repo is used as advertised.
@rohieb proposed an updated version of the completion for tig in #960, could you give it a try with zsh ?
tried the updated version of completion and it didn't help - but likely not because of that PR itself, since the issue seems to be coming from something else.
as @Garonenur mentions, if I remove the _git file located in /usr/local/share/zsh/site-functions/_git(this is where Homebrew installs it), then completion works as expected.
i suspect the reason has to do with the bottom of _git, where, within the _git() method, it says:
if (( $+functions[__${service}_zsh_main] )); then
__${service}_zsh_main
else
emulate ksh -c __${service}_main
fi
the emulate ksh line is what causes it to look for __tig_main (as evidenced by commenting out that line no longer giving the same error, but also not doing any completion for tig). i am not sure why pressing tab on tig kicks off the _git() method though.
our workaround is not working for me anymore, I removed the _git file that came with ubuntu (WSL) and I have git and tig compiled from source, the respective completion files are in my $fpath (I use zsh).
If I have the system installed _git I get the above mentioned error, __tig_main not found. If I remove that _git file, and thus only have the one from gits github source I now get tig-completion.bash:98: command not found: __git_complete the first time I try completion and
_tig:3: parse error: condition expected: 1
_tig:30: command not found: __git_complete_command
_tig:31: command not found: __gitcompappend
the second time I tap tab.
this part of the code:
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--) command="log"; break;;
-*) ;;
*) command="$i"; break ;;
esac
c=$((++c))
done
breaks, because cword is apparently not defined. and a -lt is no valid syntax.
I don't understand zsh completion enough...
after rm ~/.zcompdump and making sure I really have only the correct completion files in fpath – if I start a new shell and try tig-completion it does not work. If I then use git-completion, which works right of the bat, tig-completion starts to work. So for some reasons, the completion of git is not available to the tig-completion unless I used it.
If you need any more information, I am happy to help.
On 12 March 2020 12:53:39 CET, Dirk Willrodt notifications@github.com wrote:
this part of the code:
while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in --) command="log"; break;; -*) ;; *) command="$i"; break ;; esac c=$((++c)) donebreaks, because
cwordis apparently not defined. anda -ltis no valid syntax.
The cword variable is set up by the git completion wrapper, which wraps the _tig function (see setup at the end of the file). So yes, the git completion needs to be available first, but sadly I also don't know anything about how zsh completion works on the inside and how to force loading the git completion first…
Try the following patch on /usr/local/share/zsh/site-functions/_tig (or wherever you have it installed):
diff --git a/contrib/tig-completion.zsh b/contrib/tig-completion.zsh
index 585df16..0e5ea12 100644
--- a/contrib/tig-completion.zsh
+++ b/contrib/tig-completion.zsh
@@ -14,6 +14,10 @@
_tig () {
local e
+ e=$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
+ if [ -f $e ]; then
+ GIT_SOURCING_ZSH_COMPLETION=y . $e
+ fi
e=$(dirname ${funcsourcetrace[1]%:*})/tig-completion.bash
if [ -f $e ]; then
. $e
Try the following patch on /usr/local/share/zsh/site-functions/_tig (or wherever you have it installed):
diff --git a/contrib/tig-completion.zsh b/contrib/tig-completion.zsh index 585df16..0e5ea12 100644 --- a/contrib/tig-completion.zsh +++ b/contrib/tig-completion.zsh @@ -14,6 +14,10 @@ _tig () { local e + e=$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash + if [ -f $e ]; then + GIT_SOURCING_ZSH_COMPLETION=y . $e + fi e=$(dirname ${funcsourcetrace[1]%:*})/tig-completion.bash if [ -f $e ]; then . $e
seems not working either T.T
Indeed. It did work when I sent it but after a subsequent git upgrade it stopped working. It looks like our zsh completion would need a complete revamp as was done for bash. Unfortunately I'm not using zsh myself so unless some zsh user is volunteering to contribute it our best option will be to remove it and to rely on the basic one provided by zsh.
It seems oh my zsh (god bless this tool and its the community 😀) interferes with zsh completion in /usr/local/share/zsh/site-functions/tig-completion.bash or where ever you may have installed it (for me – on mac os – it comes automatically with the installation package of tig). oh my zsh uses compinit to do tab completion. I just removed the links in above directory as
rm /usr/local/share/zsh/site-functions/_tig
rm /usr/local/share/zsh/site-functions/tig-completion.bash
This works at least for me.
I got this error when git wasn't installed by brew. Doing "brew install git" fixed it.
@Garonenur cword is set by Git completion helpers. In the case of Bash it's the __git_func_wrap function, in the case of Zsh its the _git function.
The idea is that __git_complete git __git_main creates a __git_wrap__git_main function, and that is what Bash uses instead of _git.
However, in Zsh git calls __git_main directly. So in tig it should be called __tig_main.
I sent a pull request with those changes, which includes renaming the main completion function.
Most helpful comment
I got this error when git wasn't installed by brew. Doing "brew install git" fixed it.