Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.
brew install bash-completionBash completion will be installed in /usr/local/etc/bash_completion.d.
For it to work, add this to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completionOr simply type:
echo "[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion" >> ~/.bash_profileRestart your bash session:
source ~/.bash_profileOnce you've done this, you can use bash completion by pressing the tab key twice after a command. For example:
$ git [tab] [tab]
add blame cherry-pick config format-patch gui merge push repack rm stage whatchanged
am branch citool describe fsck help mergetool range-diff replace send-email stash worktree
apply bundle clean diff gc init mv rebase request-pull shortlog status
archive checkout clone difftool gitk instaweb notes reflog reset show submodule
bisect cherry commit fetch grep log pull remote revert show-branch tagYou can list additional completion packages are available by typing:
brew search completionAnd you can install them using brew install commands, for example:
brew install docker-completionYou can also manually add a bash completion file into
/usr/local/etc/bash_completion.d