Skip to content

Instantly share code, notes, and snippets.

@cgswong
Created May 15, 2017 14:14
Show Gist options
  • Save cgswong/bc74598a22a0b7f266c5f0f4f7ab8070 to your computer and use it in GitHub Desktop.
Save cgswong/bc74598a22a0b7f266c5f0f4f7ab8070 to your computer and use it in GitHub Desktop.
SSH hostname auto complete
_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