自定义git命令自动完成 [英] Custom git command autocompletion

查看:149
本文介绍了自定义git命令自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过编写位于/usr/local/bin中的shell脚本实现了自定义git命令.它工作正常,但是我希望脚本像git checkout [TAB][TAB]一样在命令行中自动完成分支.该怎么办?

I have implemented a custom git command by writing a shell script located in /usr/local/bin. It works fine, but I would like the script to autocomplete branches in the command line, just like git checkout [TAB][TAB]. How could this be done?

只需添加一些上下文:git允许您通过创建脚本git-$subcommandName非常容易地 添加自己的命令.在我的案例git-install中,该脚本有助于检出分支,构建,打包和安装源代码.

Just adding some context: git allows you to very easily add your own commands by creating a script git-$subcommandName. In my case here git-install, the script facilitates checking out a branch, building, packaging, and installing the source code.

推荐答案

弄清楚了.我需要下载git bash补全(此处 ),请在/etc/bash_completion.d中创建一个包含以下内容的新文件:

Figured it out. I needed to download git bash completion (here), create a new file in /etc/bash_completion.d with the following contents:

source ~/.git-completion.bash
_git_install ()
{
  __gitcomp_nl "$(__git_refs)"
}

然后exec bash重新加载完成脚本.

and then exec bash to reload completion scripts.

这篇关于自定义git命令自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆