Skip to content

Instantly share code, notes, and snippets.

@jtopper
Last active January 4, 2016 19:29
Show Gist options
  • Save jtopper/8667226 to your computer and use it in GitHub Desktop.
Save jtopper/8667226 to your computer and use it in GitHub Desktop.
Autocomplete known ssh hosts and filenames when using ssh or scp
# Add this to .profile or .bashrc
_complete_ssh() {
local cur=${COMP_WORDS[COMP_CWORD]}
local hosts=$(awk -F'[ ,]' '{ print $1 }' ~/.ssh/known_hosts | sort -u)
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) )
}
complete -o default -F _complete_ssh ssh scp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment