adr*_*anp 5 git bash autocomplete bash-completion
我正在使用Git和git-completion,一切正常,只有一个例外:当我这样做时
git p some_remote [TAB]
我得到自动完成建议当前目录中的文件(错误).p是一个Git别名:
$ cat ~/.gitconfig
[alias]
p = push
Run Code Online (Sandbox Code Playgroud)
当我做的时候:
git push some_remote [TAB]
Run Code Online (Sandbox Code Playgroud)
我得到了当前存储库中的分支的建议(正确).在这两种情况下,完成some_remote工作正常.
这是什么原因?
这是一个错误!
git-completion.bash 确实 通过您的 git aliases,将每个连接到正确的完成功能。
但随后这些-的功能为四个git push,fetch,pull,和remote-delegate到__git_complete_remote_or_refspec(),这开始是这样:
__git_complete_remote_or_refspec ()
{
local cur_="$cur" cmd="${words[1]}"
...
Run Code Online (Sandbox Code Playgroud)
$words只是来自命令行的令牌列表,再往下几行,它开始检查$cmd而不扩展别名,例如:
case "$cmd" in
fetch)
# ...
pull|remote)
# ...
Run Code Online (Sandbox Code Playgroud)
据我所知,Gábor Szeder 两年前在一个关于使用 shell 别名完成补全的帖子中首次报道了这一点。
他在2012年再次提到它在回复补丁从费利佩孔特雷拉斯(@felipec)。上个月,Felipe宣布了他的 git 分支,它实际上有一个独立的补丁:b7b6be72.
我不知道这是否已提交给上游,但与此同时……如果您想对其进行测试,请将补丁应用于您的git-completion.bash:
curl https://github.com/felipec/git/commit/b7b6be72d60d.diff |
patch -d [directory containing git-completion.bash]
# useful options for patch: --verbose --dry-run
Run Code Online (Sandbox Code Playgroud)
如果您不知道自己现在git-completion.bash住在哪里,请尝试declare -F:
dirname "$(shopt -s extdebug; declare -F __git_complete | awk '{ print $3 }')"
Run Code Online (Sandbox Code Playgroud)
(修补后git-completion.bash,它会提示您git-completion.zsh应用第二个大块的位置……您可以直接^C跳过它。)
| 归档时间: |
|
| 查看次数: |
1612 次 |
| 最近记录: |