Once upon a long time ago, I had autocomplete set up in ZSH to complete hosts that I connected to through SSH. Only in the last few days have I set it up again in bash.

I was reading through Luciano Fiandesio’s blog on how to configure Mutt and I saw that he has shared his dotfiles. I took a look at his bash configuration and saw this line:

[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2 | tr ' ' '\n')" scp sftp ssh

complete is a bash builtin function, which you can read more about in this TheGeekStuff article. This line will add the hosts in your ~/.ssh/config file to the autocomplete list for scp, sftp, and ssh.

Pretty handy!