Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Add to ~/.bash_profile or put in /etc/bash_completion.d/ssh
- # NB: May not be as "complete" as, say, /usr/share/bash-completion/completions/ssh,
- # but at least it hits all the files I need and only uses a single awk to do it
- # (a lot of other implementations are far less efficient or overly complicated).
- # NB: Supports known_hosts(5) and ssh_config(5) formats based on filename
- #
- _ssh()
- {
- local file files=
- for file in \
- ~/.ssh/config ~/.ssh/config.d/* \
- ~/.ssh/known_hosts /etc/ssh/known_hosts \
- ; do [ -e "$file" ] && files="$files $file"; done
- [ ! "$files" ] || COMPREPLY=( $( compgen -W "$( awk '
- FILENAME ~ /config/ && tolower($1) == "host" {
- for (n = 2; n <= NF; n++) if ($n !~ /[?*]/) print $n
- }
- FILENAME ~ /hosts/ {
- for (n = split($1, hosts, /,/); n > 0; n--) {
- if ((len = length(hosts[n])) < 1) continue
- if ((host = hosts[n]) ~ /^\[.*\]$/)
- host = substr(host, 2, len - 2)
- print host
- }
- }
- ' $files 2> /dev/null )" -- ${COMP_WORDS[COMP_CWORD]} ) ) || : ok
- }
- complete -F _ssh ssh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement