aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_print_hostnames.fish
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2016-02-27 00:30:16 +0100
committerGravatar Fabian Homborg <FHomborg@gmail.com>2016-03-02 15:16:42 +0100
commita5f5e6c1ef3f8faece23f7bfc2ea0be04cf345c8 (patch)
tree53be15d5ce7cae6b9cc3ed17bbe6077f57cefb45 /share/functions/__fish_print_hostnames.fish
parent61fd8b98611b978d4f0e0c2d3f76ec59b544ce94 (diff)
Ignore zero-ips in print_hostnames
This would be a lot of useless options for those who block via hosts.
Diffstat (limited to 'share/functions/__fish_print_hostnames.fish')
-rw-r--r--share/functions/__fish_print_hostnames.fish11
1 files changed, 9 insertions, 2 deletions
diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish
index b5f06da4..094113d4 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