Posted by Thomas Fri, 15 Sep 2006 19:20:21 +0000
http://kasparov.skife.org/blog/tech/ssh_completion.html has a pretty cool implementation of being lazy for your ~/.bash_completion file:
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
Because I am meddlesome, and since his was excluding some hosts, I seasoned to taste:
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
sort | \
uniq | \
egrep -v "^\|[0123456789]") )
complete -o default -W "${SSH_COMPLETE[*]}" ssh
It’s rather cool, becuase it will use hosts out of your known_hosts file for input, which is nice because it practically always be up to date. Be sure to add completion to your shell by editing your .bash_profile or whatever on your distro. Yes, I know that can do sort -u vs sort | uniq. Old habits die hard. Potato/Potatoe.
Keywords: bash auto completion ssh
Woot, thanks for the improvements!