Skip to content

Instantly share code, notes, and snippets.

@samsargent
Created January 24, 2017 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsargent/31d42f095d11292d5044735713e9dad3 to your computer and use it in GitHub Desktop.
Save samsargent/31d42f095d11292d5044735713e9dad3 to your computer and use it in GitHub Desktop.
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
@samsargent
Copy link
Author

SSH autocomplete snippet taken from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment