美文网首页
Mac下Git命令自动补全

Mac下Git命令自动补全

作者: 404d67ac8c12 | 来源:发表于2019-02-03 16:33 被阅读0次

在 Mac 中,使用 bash-completion 进行git命令自动补全。

安装 bash-completion

# 查看是否已经安装。
$ brew list

# 若未安装,请执行
$ brew install bash-completion

安装完成后,信息如下:

$ brew info bash-completion

==> 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 文件中。

[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

下载 git-completion.bash

访问:https://github.com/git/git
选择 branch 为本地 git 版本的 tag 分支,比如:

$ git version
git version 2.11.0 (Apple Git-81)

注意:
请使用相匹配的版本,否则会导致 git 命令补全时报错 Unknown option:

选好分支后,找到 contrib/completion/git-completion.bash 文件,点击Raw,复制地址栏的地址。

$ cd /usr/local/opt/bash-completion/etc/bash_completion.d
$ curl -L -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash

最后,退出终端重新打开。

相关文章

网友评论

      本文标题:Mac下Git命令自动补全

      本文链接:https://www.haomeiwen.com/subject/higysqtx.html