mac git命令按tab键自动补全

mac上命令行比windows好用不少,可是git默认按tab键是不会自动补全的,很不爽。下面咱们按步骤来介绍怎么作到自动补全。 git

1.安装home-brew,相应你们装装过了,若是没装,直接去官网看下命令行,copy过来装下就行了。github

2.执行 brew install bash-completionwindows

3.bash

if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi

把上面这段代码copy到 ~/.bash_profile 中,若是没有,就建立下这个文件,怎么建立文件?touch .bash_profile curl

4.打开https://github.com/git/git/bl...,把这个文件下下来,而后url

cp git-completion.bash ~/.git-completion.bash这个命令意思就是把这个文件拷贝到 ~/目录下,而且名字前面加了个点。 命令行

5.在~/.bashrc文件(该目录下若是没有,新建一个)中添加下边的内容code

source ~/.git-completion.bash

6.运行get

test -f ~/.git-completion.bash && . $_

而后重启终端,试试按tab键吧。git命令就自动补全了。it


方法二:

一共分两步,就能够作到在终端里用git按tab键自动不全命令了:
第一步:
首先下载自动补齐脚本,在终端输入使用curl命令以下,而后回车,就开始下载了。

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

第二步:
编辑~/.bash_profile 文件,在最后增长以下代码。若是没有该文件,就新建一个。
在终端里输入:vi ~/.bash_profile
而后粘贴下面的代码到文件的最后面:

if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
fi

重启终端后应该就能够愉快的使用tab来自动补全了。

相关文章
相关标签/搜索