Skip to content

Instantly share code, notes, and snippets.

@MohamedMohsenX2
Forked from mauzeh/Mac SSH Autocomplete
Created March 7, 2018 11:46
Show Gist options
  • Save MohamedMohsenX2/c7f5744475658e9fa49204b79e5b072f to your computer and use it in GitHub Desktop.
Save MohamedMohsenX2/c7f5744475658e9fa49204b79e5b072f to your computer and use it in GitHub Desktop.
_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 -i "^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