Created
May 15, 2017 14:14
-
-
Save cgswong/bc74598a22a0b7f266c5f0f4f7ab8070 to your computer and use it in GitHub Desktop.
SSH hostname auto complete
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/config ~/.ssh/conf.d/*.ssh | \ | |
grep "^Host " | grep -v '\*' | uniq | \ | |
awk '{print $2}') | |
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