mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Ignore zero-ips in print_hostnames
This would be a lot of useless options for those who block via hosts.
This commit is contained in:
parent
61fd8b9861
commit
a5f5e6c1ef
1 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue