From adc9ad28da1fc5b6e7a4b5916442ccf9aa166817 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 4 Jun 2025 11:25:49 +0900 Subject: [PATCH] [bash,zsh] Correctly exclude the hostname "0.0.0.0" In the current implementation, any hostnames in /etc/hosts containing "0.0.0.0" as a part (such as "110.0.0.0" would be excluded. "0.0.0.0" should be checked by the exact match. --- shell/completion.bash | 5 +++-- shell/completion.zsh | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index 7e46bacf..c489c5a0 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -516,11 +516,12 @@ if ! declare -F __fzf_list_hosts > /dev/null; then # Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of # the form [[:blank:]], and Ubuntu 18.04 LTS still uses this # 16-year-old mawk unfortunately. We need to use [ \t] instead. - /^[ \t]*(#|$)|0\.0\.0\.0/ { next } + /^[ \t]*(#|$)/ { next } { sub(/#.*/, "") for (i = 2; i <= NF; i++) - print $i + if ($i != "0.0.0.0") + print $i } ' /etc/hosts 2> /dev/null ) diff --git a/shell/completion.zsh b/shell/completion.zsh index 3663a610..e0227007 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -294,11 +294,12 @@ if ! declare -f __fzf_list_hosts > /dev/null; then # Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of # the form [[:blank:]], and Ubuntu 18.04 LTS still uses this # 16-year-old mawk unfortunately. We need to use [ \t] instead. - /^[ \t]*(#|$)|0\.0\.0\.0/ { next } + /^[ \t]*(#|$)/ { next } { sub(/#.*/, "") for (i = 2; i <= NF; i++) - print $i + if ($i != "0.0.0.0") + print $i } ' /etc/hosts 2> /dev/null )