Motivation

I have inherited several Bash installation scripts for our software developed in CertiCon. What a user could do was to call the following command in the terminal and the application behaved as requested.

$ myApp start|stop|restart

The magic was hidden in the keyword complete in a file called autocomplete_app.sh.

autocomplete_app.sh
complete -o nospace -F _myApp_autocomplete myApp
complete -o nospace -F _myApp_autocomplete /opt/myApp/compose.sh

Autocompletion

Bash auto completion is quite a well-known feature from user point of view. You write something in Terminal, hit TAB twice and behold - the command is either autocompleted or a list of possible options for completion appears.

This is done via /etc/bash_completion. The autocompletion is usually enabled in ~/.bashrc and thus available after terminal start. If there is no bash_completion file, you will have to install the package called bash_completion (Ubuntu apt install bash_completion)

The bash_completion defines the complete command.