mirror of
https://github.com/octoleo/hosts.git
synced 2025-01-01 05:31:49 +00:00
Display disabled records in list
when present
When disabled records are present, include them in a new section in the default output of `list`. If no disabled records are present, don't include the section.
This commit is contained in:
parent
7d8a94d4ca
commit
e9dec32c90
13
hosts
13
hosts
@ -746,13 +746,17 @@ Usage:
|
||||
$_me list [enabled | disabled | <search string>]
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user