陈银山 发表于 2018-1-13 18:30:39

Mac系统实现git命令自动补全

  

$ brew install 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
  

  
Homebrew's own bash completion script has been installed to
  /usr/local/etc/bash_completion.d
  

  将if…then…那一句添加到~/.bash_profile(如果没有该文件,新建一个)
  重启终端,以上为安装bash-completion部分。

二、拷贝文件、设置路径
  访问下面网站

https://github.com/git/git.git
  找到”contrib/completion/”目录下的git-completion.bash ,然后点击编辑,拷贝其内容,复制到文本文件,保存为 git-completion.bash 文件
  
然后将文件用命令拷贝到 ~/ 目录下
  

$ cp xxx/git-completion.bash ~/.git-completion.bash  

  xxx 为文件所在目录,注意拷贝后的文件名称为 .git-completion.bash
  在~/.bashrc文件(该目录下如果没有,新建一个)中添加下边的内容:
  

source ~/.git-completion.bash  

三、 启动: 终端输入
  

$ source ~/.git-completion.bas  

  注:不输入的话,不会起作用
  将下面这句话 添加到~/.bash_profile
  

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

  不添加想要补全起作用,每次都需要执行
  
source ~/.git-completion.bash
  
补全才能生效
  注:原文地址:http://blog.csdn.net/chenbifeng/article/details/51570606
页: [1]
查看完整版本: Mac系统实现git命令自动补全