Skip to content

Instantly share code, notes, and snippets.

@nikcorg
Last active August 29, 2015 14:15
Show Gist options
  • Save nikcorg/c670c8bc92b367e0bb9e to your computer and use it in GitHub Desktop.
Save nikcorg/c670c8bc92b367e0bb9e to your computer and use it in GitHub Desktop.
Tab completion for Host entries in `~/.ssh/config`
_find_all_ssh_hosts() {
grep "^Host " ~/.ssh/config | cut -d " " -f 2 | sort | uniq
}
_find_ssh_host() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(_find_all_ssh_hosts)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -o default -F _find_ssh_host ssh
complete -o default -F _find_ssh_host scp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment