Last active
August 29, 2015 14:15
-
-
Save nikcorg/c670c8bc92b367e0bb9e to your computer and use it in GitHub Desktop.
Tab completion for Host entries in `~/.ssh/config`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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