Using Auto Completion for CLIs

. 1 min read

As a developer, we are often required to use CLI for one or the other utilitiy. It could be anything from Git, Azure CLI, AWS CLI, Kubernetes Control (kubectl) etc. While a lot of these functionalities are available out of the box through UI or some other plugin, CLI is the bible of everything.

Unfortunately, it is not that easy to use. If you are using Linux, Mac or a Linux Shell on Windows, I highly recommended using the auto completion feature of the shells. Almost all the shells and all the major CLIs offer auto competition that really offers power to user.

I highly recommend to use Bash for auto-completion, while this is also possible in other shells. Also, its plain simple.

  1. Make sure you are using bash 4 or more. While, it is also available in lower versions, it is not powerful enough. Also, Mac OS comes with default version lower than 4.
bash --version

2. I recommend to use Homebrew while other tools can also be used.

brew install bash

3. Set up auto completion package. In Ubuntu, it is available in default repository.

sudo apt install bash-completion

4. Add the auto completion script of your CLI. While it is available for almost all major CLIs, installation process may vary. For setting up AWS CLI, use the following.

Find the aws completer location.

which aws_completer

Adding AWS Completer location to bash auto completion configs.

complete -C '/usr/local/bin/aws_completer' aws

4. Test the commands. Type the command followed by a TAB. Make sure to restart the shell before testing.

aws TAB

Quick and Simple, yet extremely effective for productivity.