use getent for hosts if available, otherwise use more resilient processing of /etc/hosts

This commit is contained in:
David Adam (zanchey) 2012-11-27 11:47:35 +08:00
parent 8253df7c3d
commit 165ba535f0

View file

@ -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