Mac下解決git沒有自動補全


1. Install homebrew

2. Install Git and bash-completion: brew install git bash-completion (Note: If this install fails with a 404 error, and you already have git installed, just remove the git part of this brew install)

在我電腦上已經安裝了git,現在只需要安裝bash-completion即可,執行如下命令

uxiaolei@duxiaoleideMacBook-Pro:~$brew install bash-completion
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (bazelbuild/tap).
==> Updated Formulae
bazelbuild/tap/bazel

==> Downloading https://homebrew.bintray.com/bottles/bash-completion-1.3_3.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring bash-completion-1.3_3.high_sierra.bottle.tar.gz
==> 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
==> Summary
🍺  /usr/local/Cellar/bash-completion/1.3_3: 189 files, 608.2KB

查看bash-completion安裝信息

duxiaolei@duxiaoleideMacBook-Pro:~$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 Differing version of same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.2KB) *
  Poured from bottle on 2020-03-08 at 14:34:43
From: https://mirrors.ustc.edu.cn/homebrew-core.git/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: 13,177 (30 days), 38,962 (90 days), 174,605 (365 days)
install_on_request: 12,152 (30 days), 36,129 (90 days), 160,356 (365 days)
build_error: 0 (30 days)

4. 主要看bash-completion安裝信息中Caveats下面的提示,將如下內容添加到~/.bash_profile中,執行如下命令:

duxiaolei@duxiaoleideMacBook-Pro:~$echo "[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . \"/usr/local/etc/profile.d/bash_completion.sh\"" >> ~/.bash_profile
duxiaolei@duxiaoleideMacBook-Pro:~$tail -n 1 .bash_profile
[[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
duxiaolei@duxiaoleideMacBook-Pro:~$source .bash_profile

5. 在source完bash_profile 加載完環境變量后,切換到git 目錄下執行git 命令可以看到,git 已經支持自動補全

uxiaolei@duxiaoleideMacBook-Pro:ogl-runtime$git che
checkout      cherry        cherry-pick   
duxiaolei@duxiaoleideMacBook-Pro:ogl-runtime$git checkout 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM