aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_print_hostnames.fish
diff options
context:
space:
mode:
authorGravatar David Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>2012-11-27 11:47:35 +0800
committerGravatar David Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>2012-11-27 11:49:52 +0800
commit165ba535f0ce885d7c1ebc0676a163268912a242 (patch)
tree1095d9c1998be5080a96591b6e6b9ca471634403 /share/functions/__fish_print_hostnames.fish
parent8253df7c3d99d47f6822fec0e0ef68c4f6b35796 (diff)
use getent for hosts if available, otherwise use more resilient processing of /etc/hosts
Diffstat (limited to 'share/functions/__fish_print_hostnames.fish')
-rw-r--r--share/functions/__fish_print_hostnames.fish6
1 files changed, 4 insertions, 2 deletions
diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish
index 52efc731..71b8faf6 100644
--- a/share/functions/__fish_print_hostnames.fish
+++ b/share/functions/__fish_print_hostnames.fish
@@ -2,8 +2,10 @@
function __fish_print_hostnames -d "Print a list of known hostnames"
# Print all hosts from /etc/hosts
- if test -f /etc/hosts
- sed </etc/hosts -e 's/[0-9.]*\( \|\t\)*\(.*\)/\2/'|sed -e 's/\#.*//'|tr \t \n |sgrep -v '^$'
+ if test -x /usr/bin/getent
+ getent hosts | tr -s ' ' ' ' | cut -d ' ' -f 2- | tr ' ' '\n'
+ elseif test -f /etc/hosts
+ tr -s ' \t' ' ' < /etc/hosts | sed 's/ *#.*//' | cut -s -d ' ' -f 2- | grep -o '[^ ]*'
end
# Print nfs servers from /etc/fstab
if test -f /etc/fstab