mac上git命令自动补全

之前在windows上开发,下载git后,可以在工程目录下“右键”  > Git Bash Here 打开git的bash命令行窗口,在该命令行窗口中有命令行补全功能(例如:输入 git push origin 后介入tab键会自动带出来分之名字)。此外,也可以“右键”>Git GUI Here 打开git的图形化界面,或者在git bash上直接输入git gui调出图形化界面,方面add和commit操作。

在mac上安装完git后,可以在iterm中输入git gui 调出git的图形界面,但是找不到git bash命令行来,在mac的命令行中又没有git命令的自动补全功能。不过,可以通过如下方法解决:

1、安装bash-completion:

1)查看是否安装:

$ brew list
autoconf	bash-completion	libidn2		libunistring	lrzsz		pkg-config	wget
automake	gettext		libtool		libyaml		[email protected]	readline

如果没有安装,通过如下方式安装:

brew install bash-completion

2、配置:

1)安装后,通过如下命令查看;

$ 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 each are different versions of the same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.6KB) *
  Poured from bottle on 2021-01-28 at 20:53:57
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/bash-completion.rb
==> Caveats
Add the following line to your ~/.bash_profile:
  [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 9,194 (30 days), 26,722 (90 days), 124,363 (365 days)
install-on-request: 8,065 (30 days), 24,047 (90 days), 113,585 (365 days)

从提示中将[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" 拷贝到 ~/.bash_profile中。

2)下载git-completion.bash:

https://github.com/git/git/tree/master/contrib/completion

下载git-completion.bash,将其保存到~下,并且重命名为.git-completion.bash

3)编辑~/.bash_profile,并将添加:

source ~/.git-completion.bash

猜你喜欢

转载自blog.csdn.net/liuxiao723846/article/details/113358668
今日推荐