Skip to content

Instantly share code, notes, and snippets.

@c9n
Created January 14, 2015 04:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9n/e19b199847a8e6ecfcf7 to your computer and use it in GitHub Desktop.
Save c9n/e19b199847a8e6ecfcf7 to your computer and use it in GitHub Desktop.
ssh 自动补全别名
_complete_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
host_list=`{
for c in ~/.ssh/config
do [ -r $c ] && sed -n -e 's/^[[:space:]]*Host[[:space:]]//p' $c
done
} | tr ' ' '\n'|grep -v '*'`
COMPREPLY=( $(compgen -W "${host_list}" -- $cur))
return 0
}
complete -F _complete_hosts ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment