You may have noticed that when you installed the AWS CLI via pip install awscli
that you got a aws_bash_completer
command added to your path. But, how do you use it?
I'm only going to address the use of Homebrew for Mac because that is how I do things.
Let's assume you have done brew install bash-completion
in a process similar to this. If so, then your ~/.bash_profile
will include something like this:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
Then you can make the following observations:
$ brew --prefix
/usr/local
$ ls -l $(brew --prefix)/etc/bash_completion
lrwxr-xr-x /usr/local/etc/bash_completion -> ../Cellar/bash-completion/1.3_1/etc/bash_completion
$ ls -lad $(brew --prefix)/etc/bash_completion.d
drwxr-xr-x /usr/local/etc/bash_completion.d
$ ls -l $(brew --prefix)/etc/bash_completion.d
lrwxr-xr-x aspell -> ../../Cellar/bash-completion/1.3_1/etc/bash_completion.d/aspell
lrwxr-xr-x autoconf -> ../../Cellar/bash-completion/1.3_1/etc/bash_completion.d/autoconf
lrwxr-xr-x automake -> ../../Cellar/bash-completion/1.3_1/etc/bash_completion.d/automake
lrwxr-xr-x brew -> ../../Homebrew/completions/bash/brew
lrwxr-xr-x docker-compose.bash-completion -> /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
lrwxr-xr-x docker-machine.bash-completion -> /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
lrwxr-xr-x docker.bash-completion -> /Applications/Docker.app/Contents/Resources/etc/docker.bash-
... lots more ...
So, this suggests that we can simply link any completer into the bash_completion.d directory and either start a new bash/terminal session, or rerun . $(brew --prefix)/etc/bash_completion
that we see in our ~/.bash_profile
ln -s $(which aws_bash_completer) $(brew --prefix)/etc/bash_completion.d/
. $(brew --prefix)/etc/bash_completion
And that should do it no matter where your installation paths are.