Skip to content

Instantly share code, notes, and snippets.

@nmyers
Forked from aliang/Mac SSH Autocomplete
Last active June 1, 2018 08:39
Show Gist options
  • Save nmyers/d6e1ba51170b55da2c3f62a34936aac9 to your computer and use it in GitHub Desktop.
Save nmyers/d6e1ba51170b55da2c3f62a34936aac9 to your computer and use it in GitHub Desktop.
Add auto complete to your ssh, put into your .bash_profile - Mac SSH Autocomplete
_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