将git的自动完成功能展开为管道命令 [英] Expand git's autocomplete feature to plumbing commands
问题描述
作为后续这个问题,我问自己是否有可能告诉git为进一步的命令提供自动完成功能(分支等),特别是管道命令如。
As a follow up to this question, I asked myself if it would be possible to tell git to provide it's autocomplete feature (branches etc.) for further commands, in particular plumbing commands like update-ref
.
虽然 update-ref
分支-f
,使用起来相当麻烦,因为您必须输入完整的引用名称。这反过来不会让我想用它。
Although update-ref
provides more flexibility than branch -f
, it's quite a hassle to use since you always have to type the full reference name. Which in turn doesn't make me want to use it.
有关于此的任何想法?
Any ideas on this?
推荐答案
可以启用管道命令,但您需要自己提供一些实现。
It is possible to enable the plumbing commands but you will need to provide some of the implementation yourself.
找到 git-completion.sh
您正在使用的脚本。
Find the git-completion.sh
script you are using.
在我的 /users/andrewc/.bashrc
我有
In my /users/andrewc/.bashrc
I have
# GIT STUFF
if [ -f ~/.git-completion.bash ]
then
. ~/.git-completion.bash
fi
所以我拉起 /users/andrewc/git-completion.bash
找到函数 __ git_list_porcelain_command())
并注释掉 update-ref
#update-ref) : plumbing;;
这将允许 update-ref
本身自动完成。但脚本不知道如何填写任何参数到 update-ref
。看起来您需要为 __ git_update_ref
提供实现来实现此目的。我会用一个类似的命令(`__git_branch也许)作为模板并从那里开始。
This will allow update-ref
itself to autocomplete. The script won't know how to fill in any of the args to update-ref
though. It looks like you will need to provide an implementation for __git_update_ref
to achieve this. I would use a similar command (`__git_branch maybe) as a template and go from there.
这篇关于将git的自动完成功能展开为管道命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!