diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index b5f06da48..094113d4c 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -1,11 +1,18 @@ function __fish_print_hostnames -d "Print a list of known hostnames" + # HACK: This only deals with ipv4 # Print all hosts from /etc/hosts 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 - 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 # Print nfs servers from /etc/fstab if test -r /etc/fstab