Expand git's autocomplete feature to plumbing commands

大憨熊 提交于 2019-12-10 10:36:43

问题


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.

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?


回答1:


It is possible to enable the plumbing commands but you will need to provide some of the implementation yourself.

Find the git-completion.sh script you are using.

In my /users/andrewc/.bashrc I have

# GIT STUFF 
if [ -f ~/.git-completion.bash ] 
then
    . ~/.git-completion.bash 
fi

So I pull up /users/andrewc/git-completion.bash

Find the function __git_list_porcelain_command()) and comment out the line for update-ref

        #update-ref)       : plumbing;;

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.



来源:https://stackoverflow.com/questions/26798130/expand-gits-autocomplete-feature-to-plumbing-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!