Last active
August 29, 2015 14:10
-
-
Save RyanNielson/cef1a18cf37d4b6a1357 to your computer and use it in GitHub Desktop.
Autocomplete ssh hosts using tab
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_ssh_hosts () | |
{ | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \ | |
cut -f 1 -d ' ' | \ | |
sed -e s/,.*//g | \ | |
grep -v ^# | \ | |
uniq | \ | |
grep -v "\[" ; | |
if [ -f ~/.ssh/config ]; then | |
cat ~/.ssh/config | \ | |
grep "^Host " | \ | |
awk '{print $2}' | |
fi | |
` | |
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur)) | |
return 0 | |
} | |
complete -F complete_ssh_hosts ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment