This GitHub repository contains bash-completion.el, a script that adds programmable bash completion to Emacs shell-mode. It is based on bash completion and is aware of bash builtins, aliases, and functions. It supports file expansion inside colon-separated variables and after redirections (> or <), escapes special characters when expanding file names, and is configurable through programmable bash completion. It works on remote shells, through TRAMP.
Installing bash-completion with Homebrew
To install bash-completion, you have to:
brew install bash-completion
And add the following to your ~/.bash_profile:
if -f $(brew --prefix)/etc/bash_completion » ; then
. $(brew --prefix)/etc/bash_completion
fi