Skip to content

Instantly share code, notes, and snippets.

@falvarez
Last active August 16, 2019 12:56
Show Gist options
  • Save falvarez/2c4adbf1f76b30040da63f464d57c025 to your computer and use it in GitHub Desktop.
Save falvarez/2c4adbf1f76b30040da63f464d57c025 to your computer and use it in GitHub Desktop.
ssh host autocompletion for macOS
_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 "\[" ;
cat ~/.ssh/config | \
grep "^Host " | \
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