Life changing shell function.
This snippet from .bashrc/.bash_profile was gifted from Marcel Molina, but I
thought I would share because it’s life changing. Put this in your .bashrc or
.bash_profile:
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \
cut -f 1 -d ‘ ’ | \
sed -e s/,.*//g | \
uniq | \
egrep -v [0123456789]) )
complete -o default -W ”${SSH_COMPLETE[*]}” ssh
cut -f 1 -d ‘ ’ | \
sed -e s/,.*//g | \
uniq | \
egrep -v [0123456789]) )
complete -o default -W ”${SSH_COMPLETE[*]}” ssh
Re-source it (. .bashrc) and type ‘ssh somethin’ and hit tab. Voila - tab
completion for ssh’ing to remote hosts.