Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created August 5, 2011 22:13
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 bunnymatic/1128651 to your computer and use it in GitHub Desktop.
Save bunnymatic/1128651 to your computer and use it in GitHub Desktop.
SSH Completion for bash based on .ssh/config file
__from_ssh_config() {
SSHCONFIG=$HOME/.ssh/config
COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '$(cat ~/.ssh/config | grep Host | cut -d" " -f2-)' -- $cur))
}
complete -F __from_ssh_config -o default ssh
@bunnymatic
Copy link
Author

save this somewhere and add the following to your profile

if [-f /path/to/ssh_completion/ ]; then
. /path/to/ssh_completion
fi

This will autocomplete the ssh command for any host you have defined in your .ssh/config file

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