Ignore zero-ips in print_hostnames

This would be a lot of useless options for those who block via hosts.
This commit is contained in:
Fabian Homborg 2016-02-27 00:30:16 +01:00
parent 61fd8b9861
commit a5f5e6c1ef

View file

@ -1,11 +1,18 @@
function __fish_print_hostnames -d "Print a list of known hostnames" function __fish_print_hostnames -d "Print a list of known hostnames"
# HACK: This only deals with ipv4
# Print all hosts from /etc/hosts # Print all hosts from /etc/hosts
if type -q getent if type -q getent
getent hosts 2>/dev/null | tr -s ' ' ' ' | cut -d ' ' -f 2- | tr ' ' '\n' # Ignore zero ips
getent hosts | grep -v '^0.0.0.0' \
| string replace -r '[0-9.]*\s*' '' | string split " "
else if test -r /etc/hosts else if test -r /etc/hosts
tr -s ' \t' ' ' < /etc/hosts | sed 's/ *#.*//' | cut -s -d ' ' -f 2- | __fish_sgrep -o '[^ ]*' # Ignore commented lines and functionally empty lines
grep -v '^\s*0.0.0.0\|^\s*#\|^\s*$' /etc/hosts \
# Strip comments
| string replace -ra '#.*$' '' \
| string replace -r '[0-9.]*\s*' '' | string trim | string replace -ra '\s+' '\n'
end end
# Print nfs servers from /etc/fstab # Print nfs servers from /etc/fstab
if test -r /etc/fstab if test -r /etc/fstab