2006-02-12 21:14:21 +08:00
|
|
|
|
|
|
|
function __fish_print_hostnames -d "Print a list of known hostnames"
|
|
|
|
|
|
|
|
# Print all hosts from /etc/hosts
|
2015-06-19 16:42:48 +08:00
|
|
|
if type -q getent
|
|
|
|
getent hosts 2>/dev/null | tr -s ' ' ' ' | cut -d ' ' -f 2- | tr ' ' '\n'
|
|
|
|
else if test -r /etc/hosts
|
2015-09-10 02:55:04 +08:00
|
|
|
tr -s ' \t' ' ' < /etc/hosts | sed 's/ *#.*//' | cut -s -d ' ' -f 2- | __fish_sgrep -o '[^ ]*'
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|
|
|
|
# Print nfs servers from /etc/fstab
|
2013-04-04 09:46:50 +08:00
|
|
|
if test -r /etc/fstab
|
2015-09-10 02:55:04 +08:00
|
|
|
__fish_sgrep </etc/fstab "^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\|[a-zA-Z.]*\):"|cut -d : -f 1
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Print hosts with known ssh keys
|
2013-09-19 23:18:35 +08:00
|
|
|
# Does not match hostnames with @directives specified
|
2015-09-29 02:06:20 +08:00
|
|
|
__fish_sgrep -Eoh '^[^#@|, ]*' ~/.ssh/known_hosts{,2} ^/dev/null | string replace -r '^\[([^]]+)\]:[0-9]+$' '$1'
|
2009-02-03 05:02:42 +08:00
|
|
|
|
2014-01-11 03:58:54 +08:00
|
|
|
# Print hosts from system wide ssh configuration file
|
|
|
|
if [ -e /etc/ssh/ssh_config ]
|
2014-09-29 14:08:09 +08:00
|
|
|
awk -v FS="[ =]+" -v OFS='\n' 'tolower($0) ~ /^ *host[^*?!]*$/{ $1=""; print }' /etc/ssh/ssh_config
|
2014-01-11 03:58:54 +08:00
|
|
|
end
|
|
|
|
|
2009-02-03 05:02:42 +08:00
|
|
|
# Print hosts from ssh configuration file
|
|
|
|
if [ -e ~/.ssh/config ]
|
2014-09-29 14:08:09 +08:00
|
|
|
awk -v FS="[ =]+" -v OFS='\n' 'tolower($0) ~ /^ *host[^*?!]*$/{ $1=""; print }' ~/.ssh/config
|
2009-02-03 05:02:42 +08:00
|
|
|
end
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|