Bash – How to Enable Autocomplete in SSH Session

autocompletebashssh

It seems that bash doesn't want to autocomplete commands (what's annoying me right now is not autocompleting apt-get) when I'm logged into my machine from SSH. Is there some setting that will allow bash to autocomplete inside an ssh session?

Best Answer

In short: source /etc/bash_completion should do the trick (run it in the shell within the SSH session).

Long story: in order for bash completion to work, you have to tell bash how to complete each command's arguments. This requires a long sequence of invocations of the bash built-in command complete; therefore, they are usually collected in a separate script (or several ones in /etc/bash.complete.d/*) that loads them all.

Being a regular shell script, you can always load the bash_completion in any shell startup script (~/.bash_profile, ~/.bash_login, ~/.bashrc)

Further reading:

  • section Programmable Completion in the man page bash(1)
  • help text for the complete command (run: help complete in bash)