Bash – Why bash disables autocompletion for some commands and how can I enable it

autocompletebash

It often happens to me that bash disables auto completion for certain commands. This forces me to add random symbol to name of command, use autocompletion, and than fix the command name. This is rather annoying. For example:

# I type:
openvpn s<tab>
# Nothing happens, so I add x
openvpnx s<tab>
# Now this expands to
openvpnx somepath

# Same with ./configure or many other commands...

Is there a way to disable the disabling so that auto-completion ALWAYS works?

Best Answer

Listing completions

You can see what Bash/Readline uses for completing a command using complete -p command, e.g., if I run complete -p openvpn, I get

bash: complete: openvpn: no completion specification

This shows that Readline used by my shell doesn’t have any specific completion for the openvpn command so it defaults to the traditional form of completion, i.e., filenames.

Another example (to demonstrate a defined completion):

$ complete -p dillo
complete -F _filedir_xspec dillo

This indicates that a function named _filedir_xspec is used to provide completions for the dillo command.

Removing completions

To remove a defined completion, use the -r option with the complete builtin:

complete -r openvpn