问题描述
运行 brew install git
时,会自动安装 git-completion.zsh
和 git-completion.bash
:
❯ls -l/usr/local/share/zsh/site-functions/_gitlrwxr-xr-x 56量子7月7日18:54/usr/local/share/zsh/site-functions/_git->../../../地窖/git/2.27.0/share/zsh/site-functions/_git❯ls -l/usr/local/share/zsh/site-functions/git-completion.bashlrwxr-xr-x 71量子7月7日18:54/usr/local/share/zsh/site-functions/git-completion.bash->../../../地窖/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
并按时:
❯git reba__git_func_wrap:3::找不到__git_func_wrap:3::找不到❯输入__git_func_wrap__git_func_wrap是/usr/local/share/zsh/site-functions/git-completion.bash中的shell函数
https://github.com.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(){本地诅咒词prev_get_comp_words_by_ref -n =:当前单词cword prev$ 1}
默认补全是什么
❯完成-p git完整-o bashdefault -o默认-o nospace -F __git_wrap_tig tig完整的_bash bash
继续检查:
❯类型__git_wrap_tig__git_wrap_tig是/usr/local/share/zsh/site-functions/tig-completion.bash中的Shell函数
问题是我在 tig-completion中找不到此函数.bash
tig:稳定的2.5.1(瓶装),HEADGit存储库的文本界面https://jonas.github.io/tig//usr/local/Cellar/tig/2.5.1(15个文件,875.9KB)*从2020-07-06在16:01:38从瓶子里倒来自:https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/tig.rb==>依存关系必填:readline✔==>选项- 头安装HEAD版本==>注意事项默认配置示例已安装到:/usr/local/opt/tig/share/tig/examples/tigrc要覆盖系统范围的默认配置,请将示例复制到:/usr/local/etc/tigrcBash完成已安装到:/usr/local/etc/bash_completion.dzsh补全和功能已安装到:/usr/local/share/zsh/site-functions
最近似乎有所更改: https://github.com/jonas/tig/commit/26ab51d28133354bfaa94d064bff37d29b3c30e3
但是 __ git_wrap_tig
函数在哪里?
PS:正如我上面所说,此问题并非每次都会发生.有时,当我打开一个新标签并检查默认完成时,它只是:
❯完成-p git完整的_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 :
#我们使用内部git-completion函数,因此将_tig包裹起来即可#要定义的变量(例如cword和prev)__git_complete tig _tig
TL; DR
这是 tig
完成定义的问题,而不是 git
完成定义的问题.
在 tig
上激活完成会中断 git
的完成.
- 如果在
git
之后激活了tig
,则tig
完成会起作用,而git
完成会中断. li> - 如果
tig
完成在git
之前被激活,则它们都将被破坏.
缓解措施:
安装旧版本的完成脚本.
取消链接/usr/local/share/zsh/site-functions
中的_tig和tig-completion.bash并替换为这些旧版本.下载时将 tig-completion.zsh
重命名为 _tig
.
- https://raw.githubusercontent.com/jonas/tig/91912eb97da4f6907015dab41ef9bba315730854/contrib/tig-completion.zsh
- https://raw.githubusercontent.com/jonas/tig/c72aa4dab21077231a97dcca8e3821d7b35fe7db/contrib/tig-completion.bash
cd/usr/local/share/zsh/site-functions&&\rm -f _tig tig-completion.bash&&\wget -O _tig https://raw.githubusercontent.com/jonas/tig/91912eb97da4f6907015dab41ef9bba315730854/contrib/tig-completion.zsh&\wget -O tig-completion.bash https://raw.githubusercontent.com/jonas/tig/c72aa4dab21077231a97dcca8e3821d7b35fe7db/contrib/tig-completion.bash
解决方案:
TODO:tig的文件问题.这是在 jonas/tig#960 中实现的新完成脚本的回归.>
状态:
我先从git选项卡完成工作开始,然后在某个时候外壳变质了".我实际上有三种状态
- 初始状态.在职的.
complete
未定义.%已完成
- 在第一个制表符完成后仍可正常工作,该操作为
complete
创建了一个定义%git< TAB>添加-将文件内容添加到索引二等分-通过二进制搜索找到引入错误的更改...完成的百分比完全的 () {返回0}
- 不起作用.
complete
函数定义了引用bashcomplete(){模拟-L zsh局部args void cmd打印删除args =("$ @")zparseopts -D -a void o:A:G:W:C:F:P:S:X:a b c d e f g j k u v p =打印r =删除如果[[-n $ print]]然后printf'complete%2 $ s%1 $ s \ n'" $ {(@ kv)_comps [(R)_bash *]#*}"elif [[-n $ remove]]然后对于cmd做取消设置"_comps [$ cmd]"完毕别的compdef _bash_complete \ $ {(j ..)$ {(q)args [1,-1-$#]}}"$ @"科幻}
研究
complete()函数:
取消完成功能 unset -f complete
不能神奇地修复它.我认为这可能会使我无法完成git吗?
虚拟环境
我跳入和跳出虚拟环境,并认为是相关的,但是一个跳入跳出并手动设置VIRTUAL_ENV等的受控示例并没有渗出并影响完成系统.
分心,无关
局部变量
深入研究,我发现在第三种情况下,坏外壳"中设置了很多局部变量.
我删除了这些局部变量,但没有任何积极效果:
%未设置REPLY未设置的百分比__git_repo_path未设置__tig_commands的百分比未设置__tig_options的百分比未设置_ack_raw_types的百分比未设定百分比$ _cmd_variant未设置_cmd_variant的百分比
tig
进度!我可以通过在tig上调用完成从状态1移到状态2:
%git< TAB>添加-将文件内容添加到索引二等分-通过二进制搜索找到引入错误的更改...%tig< TAB>%git< TAB>__git_func_wrap:3::找不到
首先通过使用tig完成相关的断开状态:
%tig< TAB>__git_complete:5:找不到命令:已完成完成的百分比完全的 () {模拟-L zsh局部args void cmd打印删除args =("$ @")zparseopts -D -a void o:A:G:W:C:F:P:S:X:a b c d e f g j k u v p =打印r =删除如果[[-n $ print]]然后printf'complete%2 $ s%1 $ s \ n'" $ {(@ kv)_comps [(R)_bash *]#*}"elif [[-n $ remove]]然后对于cmd做取消设置"_comps [$ cmd]"完毕别的compdef _bash_complete \ $ {(j ..)$ {(q)args [1,-1-$#]}}"$ @"科幻}%git< TAB>__git_func_wrap:3::找不到
fpath和tig完成
%echo $ fpath/usr/local/share/zsh/site-functions/usr/share/zsh/site-functions/usr/share/zsh/5.7.1/functions$ fpath中f的%;做ls $ f/* tig *;完成|猫/usr/local/share/zsh/site-functions/_tig/usr/local/share/zsh/site-functions/tig-completion.bashzsh:找不到匹配项:/usr/share/zsh/site-functions/* tig *zsh:未找到匹配项:/usr/share/zsh/5.7.1/functions/*tig*
为git,tig提取了站点功能的源代码
- tig版本2.5.1中的
- tig完成
- git版本2.28.0中的git完成
%cd/usr/local/share/zsh/site-functions%ls -l * tig *_tig->../../../Cellar/tig/2.5.1/share/zsh/site-functions/_tigtig-completion.bash->../../../Cellar/tig/2.5.1/share/zsh/site-functions/tig-completion.bash%ls -l * git *_git->../../../地窖/git/2.28.0/share/zsh/site-functions/_gitgit-completion.bash->../../../地窖/git/2.28.0/share/zsh/site-functions/git-completion.bash
/usr/local/share/zsh/site-functions
中的补全-
_tig
#compdef tig##tig的zsh完成包装器#==============================##您需要使用tig-completion.bash将此脚本安装到zsh fpath.##安装此脚本的推荐方法是复制此脚本和tig-completion.bash#到'〜/.zsh/_tig'和'〜/.zsh/tig-completion.bash'和#然后将以下内容添加到您的〜/.zshrc文件中:##fpath =(〜/.zsh $ fpath)_tig(){本地电子e = $(目录名$ {funcsourcetrace [1]%:*})/git-completion.bash如果[-f $ e];然后GIT_SOURCING_ZSH_COMPLETION = y.$ e科幻e = $(目录名$ {funcsourcetrace [1]%:*})/tig-completion.bash如果[-f $ e];然后.$ e科幻}
-
tig-completion.bash
#compdef git gitk#git的zsh完成包装器##版权所有(c)2012-2013 Felipe Contreras< [email protected]>##您需要在某处安装git的bash完成脚本,默认情况下#将是bash-completion使用的位置.##如果您的脚本在其他地方,则可以在〜/.zshrc上对其进行配置:##zstyle':completion:*:*:git:*'脚本〜/.git-completion.zsh##安装此脚本的推荐方法是在以下位置复制该脚本#〜/.zsh/目录作为〜/.zsh/git-completion.zsh,然后添加以下内容#到您的〜/.zshrc文件中:##fpath =(〜/.zsh $ fpath)完全的 (){# 没做什么返回0}zstyle -T':completion:*:*:git:*'标签顺序&&\zstyle':completion:*:*:git:*'标签顺序'common-commands'zstyle -s":completion:*:*:git:*"脚本脚本如果[-z"$ script"];然后本地-a位置本地电子位置=($(dirname $ {funcsourcetrace [1]%:*})/git-completion.bash'/etc/bash_completion.d/git'#fedora,旧的debian'/usr/share/bash-completion/completions/git'#arch,ubuntu,新的debian'/usr/share/bash-completion/git'#gentoo)对于$ locations中的e;做测试-f $ e&&script ="$ e"&&休息完毕科幻GIT_SOURCING_ZSH_COMPLETION = y."$ script"__gitcomp(){模拟-L zsh本地cur _ ="$ {3- $ cur}"情况"$ cur_"在-* =);;*)本地c IFS = $'\ t \ n'本地-a数组对于$ {= 1}中的c;做c ="$ c $ {4-}"案例$ c-* = * | *.);;*)c =" $ c";;埃萨克array + =("$ c")完毕compset -P'* [=:]'compadd -Q -S''-p"$ {2-}";-a-数组&&_ret = 0;;埃萨克}__gitcomp_direct(){模拟-L zsh本地IFS = $'\ n'compset -P'* [=:]'compadd -Q-$ {= 1}&&_ret = 0}__gitcomp_nl(){模拟-L zsh本地IFS = $'\ n'compset -P'* [=:]'compadd -Q -S"$ {4-}";-p"$ {2-}";-$ {= 1}&&_ret = 0}__gitcomp_nl_append(){模拟-L zsh本地IFS = $'\ n'compadd -Q -S"$ {4-}";-p"$ {2-}";-$ {= 1}&&_ret = 0}__gitcomp_file_direct(){模拟-L zsh本地IFS = $'\ n'compset -P'* [=:]'compadd -f-$ {= 1}&&_ret = 0}__gitcomp_file(){模拟-L zsh本地IFS = $'\ n'compset -P'* [=:]'compadd -p" $ {2-}"-f-$ {= 1}&&_ret = 0}__git_zsh_bash_func(){模拟-L ksh本地命令= $ 1本地完成_功能="_ git _ $ {命令//-//}}"声明-f $ completion_func>/dev/null&&$ completion_func&&返回本地扩展= $(__ git_aliased_command``$ command'')如果[-n"$ expansion"];然后单词[1] = $扩展complete_func ="_ git _ $ {扩展//-//_}"声明-f $ completion_func>/dev/null&&$ completion_func科幻}__git_zsh_cmd_common(){本地-a列表列表=(添加:将文件内容添加到索引"bisect:通过二进制搜索找到引入错误的更改"分支:列出,创建或删除分支"检出:检出工作树的分支或路径"clone:将存储库克隆到新目录中"提交:记录对存储库的更改"差异:显示提交,提交和工作树等之间的更改"获取:从另一个存储库下载对象和引用"grep:打印与模式匹配的行"init:创建一个空的Git存储库或重新初始化一个现有的Git存储库"日志:显示提交日志"合并:将两个或多个发展历史结合在一起"mv:移动或重命名文件,目录或符号链接"拉:从另一个存储库或本地分支获取并合并"推送:更新远程引用以及相关对象"重新设置:将本地端口提交到更新的上游头"重置:将当前HEAD重置为指定状态"恢复:恢复工作树文件"rm:'从工作树和索引中删除文件'显示:显示各种类型的对象"状态:显示工作树状态"开关:开关分支"标签:创建,列出,删除或验证使用GPG签名的标签对象")_describe -t通用命令'通用命令'列表&&_ret = 0}__git_zsh_cmd_alias(){本地-a列表list =($ {$ {$ {(0)" $(git config -z --get-regexp'^ alias \.')''}}#alias.}%$'\ n'*})_describe -t alias-commands'别名'列表$ *&&_ret = 0}__git_zsh_cmd_all(){本地-a列表模拟ksh -c __git_compute_all_commandslist =($ {= __ git_all_commands})_describe -t all-commands'所有命令'列表&&_ret = 0}__git_zsh_main(){local curcontext ="$ curcontext"状态state_descr行排版-A opt_args本地-a orig_wordsorig_words =($ {words [@]})_参数-C \'(-p --paginate --no-pager)'{-p,-paginate}'[将所有输出输出到"less"]''\'(-p --paginate)-no-pager [不要将git输出通过管道传到分页器中]'\'--git-dir =-[设置存储库的路径]::_directories'\'--bare [将存储库视为裸存储库]'\'(-:)-version [打印git套件版本]'\'--exec-path =-[安装核心git程序的路径] :::_directories'\'--html-path [打印git的HTML文档的安装路径]'\'--info-path [打印安装信息文件的路径]'\'--man-path [打印手册页的手册路径(参见`man(1)`)]'\'--work-tree =-[设置工作树的路径] :: _ directories'\'--namespace =-[设置git名称空间]'\'--no-replace-objects [请勿使用替换参考来替换git对象]'\'(-:)-help [打印提要和最常用命令的列表]::-> arg'\'(-)::->命令'\'(-)* ::::-> arg'&返回案例$ state in(命令)_选择 \'alias-commands:alias:__ git_zsh_cmd_alias'\'common-commands:common:__ git_zsh_cmd_common'\'all-commands:all:__ git_zsh_cmd_all'&&_ret = 0;;(arg)本地命令="$ {words [1]}"__git_dir如果(($ + opt_args [-bare]));然后__git_dir ='.别的__git_dir = $ {opt_args [-git-dir]}科幻((($ + opt_args [-help]))&&command ='help'words =($ {orig_words [@]})__git_zsh_bash_func $ command;;埃萨克}_git(){本地_ret = 1上一个当地的前剑cur = $ {words [CURRENT]}prev = $ {words [CURRENT-1]}让cword = CURRENT-1if((($ + functions [__ $ {service} _zsh_main])));然后__ $ {service} _zsh_main别的模拟ksh -c __ $ {service} _main科幻让_ret&&_default&&_ret = 0返回_ret}_git
git-completion.zsh
and git-completion.bash
are installed automatically when running 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
is included in 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
For some reasons, sometimes when I type git reba
and press :
❯ 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
}
What the default completion is:
❯ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap_tig tig
complete _bash bash
Continue inspect:
❯ type __git_wrap_tig
__git_wrap_tig is a shell function from /usr/local/share/zsh/site-functions/tig-completion.bash
The thing is I cannot find this function in 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
Looks like there is some changed recently: https://github.com/jonas/tig/commit/26ab51d28133354bfaa94d064bff37d29b3c30e3
but where is __git_wrap_tig
function?
PS: As I said above, this problem is not happen every time. Sometimes, when I opened a new tab and check the default completion and it is just:
❯ complete -p git
complete _bash bash
and git
completion worked as expected.
Reply to @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
and one more invocation of __git_complete
is in 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
TL;DR
This is a problem with the tig
completion definitions, and not with the git
completion definitions.
Activating completion on tig
breaks completion for git
.
- If
tig
is activated aftergit
, thentig
completion works andgit
completion is broken. - If
tig
completion is activated beforegit
, then they are both broken.
Mitigation:
Install the old versions of the completion scripts.
Unlink _tig and tig-completion.bash in /usr/local/share/zsh/site-functions
and replace with these older versions. Rename tig-completion.zsh
as _tig
when downloading.
- https://raw.githubusercontent.com/jonas/tig/91912eb97da4f6907015dab41ef9bba315730854/contrib/tig-completion.zsh
- https://raw.githubusercontent.com/jonas/tig/c72aa4dab21077231a97dcca8e3821d7b35fe7db/contrib/tig-completion.bash
cd /usr/local/share/zsh/site-functions && \
rm -f _tig tig-completion.bash && \
wget -O _tig https://raw.githubusercontent.com/jonas/tig/91912eb97da4f6907015dab41ef9bba315730854/contrib/tig-completion.zsh && \
wget -O tig-completion.bash https://raw.githubusercontent.com/jonas/tig/c72aa4dab21077231a97dcca8e3821d7b35fe7db/contrib/tig-completion.bash
Solution:
TODO: File issue with tig. This is a regression with the new completion script as implemented in jonas/tig#960
States:
I start with git tab completion working, and then at some point the shell "goes bad." I actually have three states
- initial state. working.
complete
not defined.% which complete
- still working after a first tab completion which creates a definition for
complete
% git <TAB> add -- add file contents to the index bisect -- find by binary search the change that introduced a bug ... % which complete complete () { return 0 }
- not working.
complete
function defined referencing bashcomplete () { emulate -L zsh local args void cmd print remove args=("$@") zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v p=print r=remove if [[ -n $print ]] then printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }" elif [[ -n $remove ]] then for cmd do unset "_comps[$cmd]" done else compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@" fi }
Research
complete() function:
unsetting the complete function unset -f complete
does not magically fix it. I think this may leave me with no completion for git?
virtual envs
I jump in and out of virtual envs, and thought that was related, but a controlled example of jumping in and out and manually setting VIRTUAL_ENV and etc did not bleed over and affect the completion system.
distraction, not related
local variables
Digging further I found a lot of local variables set in the third case, "bad shell."
I removed each of these local variables without any positive effect:
% unset REPLY
% unset __git_repo_path
% unset __tig_commands
% unset __tig_options
% unset _ack_raw_types
% unset $_cmd_variant
% unset _cmd_variant
tig
Progress! I can move from state 1 to state 2 by invoking completion on tig:
% git <TAB>
add -- add file contents to the index
bisect -- find by binary search the change that introduced a bug
...
% tig <TAB>
% git <TAB>
__git_func_wrap:3: : not found
related broken state by completing with tig first:
% tig <TAB>
__git_complete:5: command not found: complete
% which complete
complete () {
emulate -L zsh
local args void cmd print remove
args=("$@")
zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v p=print r=remove
if [[ -n $print ]]
then
printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }"
elif [[ -n $remove ]]
then
for cmd
do
unset "_comps[$cmd]"
done
else
compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
fi
}
% git <TAB>
__git_func_wrap:3: : not found
fpath and tig completion
% echo $fpath
/usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.7.1/functions
% for f in $fpath; do ls $f/*tig*; done | cat
/usr/local/share/zsh/site-functions/_tig
/usr/local/share/zsh/site-functions/tig-completion.bash
zsh: no matches found: /usr/share/zsh/site-functions/*tig*
zsh: no matches found: /usr/share/zsh/5.7.1/functions/*tig*
Brew sources for site-functions for git, tig
- tig completions from tig version 2.5.1
- git completions from git version 2.28.0
% cd /usr/local/share/zsh/site-functions
% ls -l *tig*
_tig -> ../../../Cellar/tig/2.5.1/share/zsh/site-functions/_tig
tig-completion.bash -> ../../../Cellar/tig/2.5.1/share/zsh/site-functions/tig-completion.bash
% ls -l *git*
_git -> ../../../Cellar/git/2.28.0/share/zsh/site-functions/_git
git-completion.bash -> ../../../Cellar/git/2.28.0/share/zsh/site-functions/git-completion.bash
Tig completions in /usr/local/share/zsh/site-functions
_tig
#compdef tig # # zsh completion wrapper for tig # ============================== # # You need to install this script to zsh fpath with tig-completion.bash. # # The recommended way to install this script is to copy this and tig-completion.bash # to '~/.zsh/_tig' and '~/.zsh/tig-completion.bash' and # then add following to your ~/.zshrc file: # # fpath=(~/.zsh $fpath) _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 fi }
tig-completion.bash
#compdef git gitk # zsh completion wrapper for git # # Copyright (c) 2012-2013 Felipe Contreras <[email protected]> # # You need git's bash completion script installed somewhere, by default it # would be the location bash-completion uses. # # If your script is somewhere else, you can configure it on your ~/.zshrc: # # zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh # # The recommended way to install this script is to make a copy of it in # ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following # to your ~/.zshrc file: # # fpath=(~/.zsh $fpath) complete () { # do nothing return 0 } zstyle -T ':completion:*:*:git:*' tag-order && \ zstyle ':completion:*:*:git:*' tag-order 'common-commands' zstyle -s ":completion:*:*:git:*" script script if [ -z "$script" ]; then local -a locations local e locations=( $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash '/etc/bash_completion.d/git' # fedora, old debian '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian '/usr/share/bash-completion/git' # gentoo ) for e in $locations; do test -f $e && script="$e" && break done fi GIT_SOURCING_ZSH_COMPLETION=y . "$script" __gitcomp () { emulate -L zsh local cur_="${3-$cur}" case "$cur_" in --*=) ;; *) local c IFS=$' \t\n' local -a array for c in ${=1}; do c="$c${4-}" case $c in --*=*|*.) ;; *) c="$c " ;; esac array+=("$c") done compset -P '*[=:]' compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 ;; esac } __gitcomp_direct () { emulate -L zsh local IFS=$'\n' compset -P '*[=:]' compadd -Q -- ${=1} && _ret=0 } __gitcomp_nl () { emulate -L zsh local IFS=$'\n' compset -P '*[=:]' compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 } __gitcomp_nl_append () { emulate -L zsh local IFS=$'\n' compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 } __gitcomp_file_direct () { emulate -L zsh local IFS=$'\n' compset -P '*[=:]' compadd -f -- ${=1} && _ret=0 } __gitcomp_file () { emulate -L zsh local IFS=$'\n' compset -P '*[=:]' compadd -p "${2-}" -f -- ${=1} && _ret=0 } __git_zsh_bash_func () { emulate -L ksh local command=$1 local completion_func="_git_${command//-/_}" declare -f $completion_func >/dev/null && $completion_func && return local expansion=$(__git_aliased_command "$command") if [ -n "$expansion" ]; then words[1]=$expansion completion_func="_git_${expansion//-/_}" declare -f $completion_func >/dev/null && $completion_func fi } __git_zsh_cmd_common () { local -a list list=( add:'add file contents to the index' bisect:'find by binary search the change that introduced a bug' branch:'list, create, or delete branches' checkout:'checkout a branch or paths to the working tree' clone:'clone a repository into a new directory' commit:'record changes to the repository' diff:'show changes between commits, commit and working tree, etc' fetch:'download objects and refs from another repository' grep:'print lines matching a pattern' init:'create an empty Git repository or reinitialize an existing one' log:'show commit logs' merge:'join two or more development histories together' mv:'move or rename a file, a directory, or a symlink' pull:'fetch from and merge with another repository or a local branch' push:'update remote refs along with associated objects' rebase:'forward-port local commits to the updated upstream head' reset:'reset current HEAD to the specified state' restore:'restore working tree files' rm:'remove files from the working tree and from the index' show:'show various types of objects' status:'show the working tree status' switch:'switch branches' tag:'create, list, delete or verify a tag object signed with GPG') _describe -t common-commands 'common commands' list && _ret=0 } __git_zsh_cmd_alias () { local -a list list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*}) _describe -t alias-commands 'aliases' list $* && _ret=0 } __git_zsh_cmd_all () { local -a list emulate ksh -c __git_compute_all_commands list=( ${=__git_all_commands} ) _describe -t all-commands 'all commands' list && _ret=0 } __git_zsh_main () { local curcontext="$curcontext" state state_descr line typeset -A opt_args local -a orig_words orig_words=( ${words[@]} ) _arguments -C \ '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ '(-p --paginate)--no-pager[do not pipe git output into a pager]' \ '--git-dir=-[set the path to the repository]: :_directories' \ '--bare[treat the repository as a bare repository]' \ '(- :)--version[prints the git suite version]' \ '--exec-path=-[path to where your core git programs are installed]:: :_directories' \ '--html-path[print the path where git''s HTML documentation is installed]' \ '--info-path[print the path where the Info files are installed]' \ '--man-path[print the manpath (see `man(1)`) for the man pages]' \ '--work-tree=-[set the path to the working tree]: :_directories' \ '--namespace=-[set the git namespace]' \ '--no-replace-objects[do not use replacement refs to replace git objects]' \ '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \ '(-): :->command' \ '(-)*:: :->arg' && return case $state in (command) _alternative \ 'alias-commands:alias:__git_zsh_cmd_alias' \ 'common-commands:common:__git_zsh_cmd_common' \ 'all-commands:all:__git_zsh_cmd_all' && _ret=0 ;; (arg) local command="${words[1]}" __git_dir if (( $+opt_args[--bare] )); then __git_dir='.' else __git_dir=${opt_args[--git-dir]} fi (( $+opt_args[--help] )) && command='help' words=( ${orig_words[@]} ) __git_zsh_bash_func $command ;; esac } _git () { local _ret=1 local cur cword prev cur=${words[CURRENT]} prev=${words[CURRENT-1]} let cword=CURRENT-1 if (( $+functions[__${service}_zsh_main] )); then __${service}_zsh_main else emulate ksh -c __${service}_main fi let _ret && _default && _ret=0 return _ret } _git
这篇关于Zsh中的git完成:__git_func_wrap:3::未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!