__fish_print_hostnames: do a better job of searching SSH files

This commit is contained in:
David Adam
2013-09-19 23:18:35 +08:00
parent df300e042b
commit c2dcfc9176

View File

@@ -13,11 +13,13 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
end
# Print hosts with known ssh keys
cat ~/.ssh/known_hosts{,2} ^/dev/null | grep -v '^|' | cut -d ' ' -f 1| cut -d , -f 1
# Does not match hostnames with @directives specified
sgrep -Eoh '^[^#@|, ]*' ~/.ssh/known_hosts{,2} ^/dev/null
# Print hosts from ssh configuration file
if [ -e ~/.ssh/config ]
sgrep -i '^ *host' ~/.ssh/config | grep -v '[*?]' | cut -d ' ' -f 2
# Ignore lines containing wildcards
sgrep -Eoi '^ *host[^*]*$' ~/.ssh/config | cut -d '=' -f 2 | tr ' ' '\n'
end
end