Created
July 12, 2013 17:33
-
-
Save sontek/5986226 to your computer and use it in GitHub Desktop.
autocomplete ssh via /etc/hosts and ssh_config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_complete_hosts () { | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
host_list=`{ | |
for c in /etc/ssh_config /etc/ssh/ssh_config ~/.ssh/config | |
do [ -r $c ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' $c | |
done | |
for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts ~/.ssh/known_hosts | |
do [ -r $k ] && egrep -v '^[#\[]' $k|cut -f 1 -d ' '|sed -e 's/[,:].*//g' | |
done | |
sed -n -e 's/^[0-9][0-9\.]*//p' /etc/hosts; }|tr ' ' '\n'|grep -v '*'` | |
COMPREPLY=( $(compgen -W "${host_list}" -- $cur)) | |
return 0 | |
} | |
complete -F _complete_hosts ssh | |
complete -F _complete_hosts host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment