【发布时间】:2020-10-27 05:06:04
【问题描述】:
git-completion.zsh和git-completion.bash在运行brew install git时会自动安装:
❯ ls -l /usr/local/share/zsh/site-functions/_git
lrwxr-xr-x 56 quanta 7 Jul 18:54 /usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.27.0/share/zsh/site-functions/_git
❯ ls -l /usr/local/share/zsh/site-functions/git-completion.bash
lrwxr-xr-x 71 quanta 7 Jul 18:54 /usr/local/share/zsh/site-functions/git-completion.bash -> ../../../Cellar/git/2.27.0/share/zsh/site-functions/git-completion.bash
/usr/local/share/zsh/site-functions 包含在fpath 中:
❯ echo $fpath
/usr/local/share/zsh-completions
/usr/local/share/zsh/site-functions
/usr/share/zsh/site-functions
/usr/share/zsh/5.7.1/functions
由于某些原因,有时当我输入git reba 并按tab 时:
❯ git reba
__git_func_wrap:3: : not found
__git_func_wrap:3: : not found
❯ type __git_func_wrap
__git_func_wrap is a shell function from /usr/local/share/zsh/site-functions/git-completion.bash
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash#L3517-L3522
❯ grep -A5 '^__git_func_wrap' /usr/local/share/zsh/site-functions/git-completion.bash
__git_func_wrap ()
{
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
$1
}
默认补全是什么:
❯ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap_tig tig
complete _bash bash
继续检查:
❯ type __git_wrap_tig
__git_wrap_tig is a shell function from /usr/local/share/zsh/site-functions/tig-completion.bash
问题是我在tig-completion.bash找不到这个功能
tig: stable 2.5.1 (bottled), HEAD
Text interface for Git repositories
https://jonas.github.io/tig/
/usr/local/Cellar/tig/2.5.1 (15 files, 875.9KB) *
Poured from bottle on 2020-07-06 at 16:01:38
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/tig.rb
==> Dependencies
Required: readline ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
A sample of the default configuration has been installed to:
/usr/local/opt/tig/share/tig/examples/tigrc
to override the system-wide default configuration, copy the sample to:
/usr/local/etc/tigrc
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions and functions have been installed to:
/usr/local/share/zsh/site-functions
最近好像有一些变化:https://github.com/jonas/tig/commit/26ab51d28133354bfaa94d064bff37d29b3c30e3
但是__git_wrap_tig 函数在哪里?
PS:正如我上面所说,这个问题并非每次都会发生。有时,当我打开一个新选项卡并检查默认完成时,它只是:
❯ complete -p git
complete _bash bash
并且git 完成按预期工作。
回复@user1934428:
❯ grep '__git_complete ' /usr/local/share/zsh/site-functions/git-completion.bash
__git_complete ()
__git_complete git __git_main
__git_complete gitk __gitk_main
__git_complete git.exe __git_main
__git_complete 的另一个调用位于tig-completion.bash:
# we use internal git-completion functions, so wrap _tig for all necessary
# variables (like cword and prev) to be defined
__git_complete tig _tig
【问题讨论】:
-
函数
__git_func_wrap的第3行出现错误信息,你找到了函数的定义位置。你为什么不发布违规行? -
对不起,它在这里:github.com/git/git/blob/master/contrib/completion/…。我将它添加到我的问题中。谢谢。
-
不要发布链接。您链接的功能可能与您机器上的版本相同,也可能不同。复制该功能的相关部分并将其发布在此处。由于错误出现在第 3 行,因此发布前 4 行左右就足够了。
-
它们是一样的;我在发布前检查了。我发布链接的原因是帮助其他人可以环顾四周。无论如何,我更新了我的问题以包含我机器上文件中的该函数。
-
您是否还检查了文件的其余部分是否也相同?因为你得到的错误意味着
__git_func_wrap中的$1 是空的,这反过来意味着__git_complete中的$2 是空的。但是,我只看到了 3 次__git_complete调用,而且它们看起来都很好。
标签: git autocomplete zsh tig