From bc3618277307669a8872574e8fe461c07420fc13 Mon Sep 17 00:00:00 2001 From: William Melody Date: Wed, 18 Mar 2015 17:41:04 -0700 Subject: [PATCH] Print disabled matches in `show` --- hosts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hosts b/hosts index a95633a..147edb3 100755 --- a/hosts +++ b/hosts @@ -812,7 +812,12 @@ Description: EOM show() { if [[ -n "$1" ]]; then - grep "^[^#]*$1" /etc/hosts + # Run `sed` before `grep` to avoid conflict that supress `sed` output. + disabled_records=$(sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" /etc/hosts) + enabled_records=$(grep "^[^#]*$1" /etc/hosts) + # Output disabled records secondly for better organization. + [[ -n "$enabled_records" ]] && printf "%s\n" "$enabled_records" + [[ -n "$disabled_records" ]] && printf "%s\n" "$disabled_records" else $_me help show exit 1