Linux/macOS 下,按 tab tab 提示/補齊指令的參數 (Bash Completion)

2017090407:44
 
user@mac ~ $ git [tab][tab]  按兩下tab後 可提示 git 這個指令的相關參數 
add                  clean                grep                 pull                 shortlog
am                   clone                help                 push                 show
annotate             commit               imap-send            rebase               show-branch
apply                config               init                 reflog               stage
archive              describe             instaweb             relink               stash
bisect               diff                 interpret-trailers   remote               status
blame                difftool             log                  repack               submodule
branch               fetch                merge                replace              subtree
bundle               filter-branch        mergetool            request-pull         svn
checkout             format-patch         mv                   reset                tag
cherry               fsck                 name-rev             revert               verify-commit
cherry-pick          gc                   notes                rm                   whatchanged
citool               get-tar-commit-id    p4                   send-email           worktree
user@firemac ~ $ git

或是
 
user@mac ~ $ git com  再按一下tab後,自動幫你補齊 commit 參數


只要安裝 bash-completion 即可
 

Linux


debian系列
apt-get install bash-completion

CentOS
yum install bash-completion


再將下面三行加到 .bash_profile 檔案中,重新登入即可
 

if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi



 

macOS

 
$ brew install bash-completion
$ brew tap homebrew/completions
 

下面三行加到 ~/.bash_profile 檔案中,重開終端機即可

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



** homebrew 的安裝
https://brew.sh/index_zh-tw.html




參考
为 Mac OS 添加 Bash Completion


自訂 bash 提示符號的工具:

Halloween Bash Profile Generator

Easy Bash Prompt Generator