mac系统下git自动补全功能

20150512更新
最近把mac的shell换成了zsh,使用oh-my-zsh,安装很简单,使用也很方便,按照官网下面的教程安装即可。


最近开始使用mac系统,使用git时发现无自动补全功能。随查找了一些资料,开启了git 自动补全功能,在此做个记录,方便以后查阅。

1.安装Homebrew
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

2.安装bash-completion
$ brew install bash-completion

3.配置bash-completion

输入命令

$ brew info bash-completion
其中有以下一段:

==> Caveats

Add the following lines to your ~/.bash_profile:

if [ -f $(brew –prefix)/etc/bash_completion ]; then

. $(brew –prefix)/etc/bash_completion

fi

把从if开始这3行添加到 ~/.bash_profile中,配置完成。
然后重启终端或者输入 $ source ~/.bash_profile

4.下载git源码
$ git clone https://github.com/git/git.git

找到 子目录cd git/contrib/completion/中
有一个文件 git-completion.bash

5.配置
$ vim ~/.bashrc

增加下面这一行,这个是我电脑的路径,其他人要找到自己的路径

#git
source /Users/liangqilong/dev/git/contrib/completion/git-completion.bash

然后使用命令 source ~/.bashrc 使上面的配置生效

6..测试
输入 git –h
按[tab]键,会自动变程 git – help