mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 00:44:53 +08:00
functions/__fish_print_hostnames: Check getent's status
This previously effectively checked `string split ' '`s return status, which was false if it didn't split anything. And while that should be true if getent fails (because it should produce no output), it's also true if it doesn't print a line with multiple aliases. Which should be fairly typical. Instead we use our new-found $pipestatus to check what getent returns, in the assumption that it'll fail if it doesn't support hosts. Follow up to 8f7a47547e0f8e3055f51dddd59e1cce7bd49618. [ci skip]
This commit is contained in:
parent
9cd29e5166
commit
3bc392a6b3
@ -8,7 +8,8 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||
type -q getent
|
||||
# Ignore zero IPs.
|
||||
and getent hosts 2>/dev/null | string match -r -v '^0.0.0.0' | string replace -r '^\s*\S+\s+' '' | string split ' '
|
||||
or if test -r /etc/hosts
|
||||
# We care about _getent_s status, not `string split`s.
|
||||
if test $pipestatus[1] -ne 0; and test -r /etc/hosts
|
||||
# Ignore commented lines and functionally empty lines.
|
||||
string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' </etc/hosts | string replace -r -a '#.*$' '' | string replace -r '^\s*\S+\s+' '' | string trim | string replace -r -a '\s+' ' ' | string split ' '
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user