Skip to content

Instantly share code, notes, and snippets.

@ypetya
Last active December 19, 2015 08:29
Show Gist options
  • Save ypetya/5926421 to your computer and use it in GitHub Desktop.
Save ypetya/5926421 to your computer and use it in GitHub Desktop.
ssh Host completion by .ssh/config and known_hosts files in case their exists.
# ssh completion
if [ -f ~/.ssh/config ] ; then
SSH_COMPLETE=( $(grep "^Host " ~/.ssh/config | cut -f2 -d ' ' | sort -u ) )
SSH_COMPLETE=( ${SSH_COMPLETE[*]} $(grep "\w*User " ~/.ssh/config | cut -f2 -d ' ' | sort -u ) )
fi
if [ -f ~/.ssh/known_hosts ] ; then
SSH_COMPLETE=( ${SSH_COMPLETE[*]} $(cut -f1 -d' ' ~/.ssh/known_hosts | cut -f1 -d',' | sort -u ))
fi
complete -o default -W "${SSH_COMPLETE[*]}" ssh
complete -o default -W "${SSH_COMPLETE[*]}" scp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment