diff --git a/hosts b/hosts index 6540506..a61c559 100755 --- a/hosts +++ b/hosts @@ -746,13 +746,17 @@ Usage: $_me list [enabled | disabled | ] Description: - List the existing IP / hostname pairs. When provided with a seach string, all - matching lines will be printed. + List the existing IP / hostname pairs, optionally limited to a specified + state. When provided with a seach string, all matching enabled records will + be printed. EOM list() { + # Get the disabled records up front for the two cases where they are needed. + disabled_records=$(sed -n "s/^\#disabled: \(.*\)$/\1/p" /etc/hosts) + if [[ -n "$1" ]]; then if [[ "$1" == disabled ]]; then - sed -n "s/^\#disabled: \(.*\)$/\1/p" /etc/hosts + printf "%s\n" "${disabled_records}" elif [[ "$1" == enabled ]]; then grep -v -e '^$' -e '^\s*\#' /etc/hosts else @@ -762,6 +766,9 @@ list() { # NOTE: use separate expressions since using a | for the or results in # inconsistent behavior. grep -v -e '^$' -e '^\s*\#' /etc/hosts + if [[ -n "${disabled_records}" ]]; then + printf "\nDisabled:\n%s\n" "${disabled_records}" + fi fi }