所以我从here下载了git-completion.bash
,如下面的输出所示:
$ ls ~ | grep git-completion
-rw-r--r-- 1 waldyr staff 64720 Jul 21 23:43 .git-completion.bash
我正在运行macOS High Sierra版本10.13.6,并且从以下输出中可以看到,我使用自制软件下载了bash-completion:
$ brew info bash-completion
bash-completion: stable 1.3 (bottled)
Programmable completion for Bash 3.2
https://salsa.debian.org/debian/bash-completion
Conflicts with:
bash-completion@2 (because Differing version of same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.2KB) *
Poured from bottle on 2018-07-18 at 11:25:01
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bash-completion.rb
==> Caveats
Add the following line to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
我的.bash_profile
源于一个名为.bashrc
的文件,该文件同时告诉{1>并同时bash-completion
和git completion
$ cat ~/.bash_profile
. ~/.bashrc
$ cat ~/.bashrc
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
__git_complete gp _git_push
fi
alias gp='git push'
每当我在终端中输入gp
并按Tab要求完成时,脚本均能正常运行:
$ gp <tab>
origin production
在我选择了存储库之后,对于refspec来说,完成工作不起作用:
在没有任何内容后,它会继续显示存储库:
$ gp origin <tab>
origin production
如果至少有一个字母(例如m
中的master
),它将在当前目录中查找文件
$ gp origin m<tab>
Makefile Minafile
我知道我可以在git
中将bashrc
别名为g
,并在git-push
中将别名gitconfig
别名为p
,使命令{{ 1}},它的完成效果很好,但是我觉得很烦,必须输入空格。
使第二个参数(refspec)完成工作时我缺少什么?那是一个git bug吗?
Here is the link for my dotfiles,以便您可以检查整个文件。