mirror of
https://github.com/octoleo/hosts.git
synced 2025-01-03 22:27:23 +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>]
|
$_me list [enabled | disabled | <search string>]
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
List the existing IP / hostname pairs. When provided with a seach string, all
|
List the existing IP / hostname pairs, optionally limited to a specified
|
||||||
matching lines will be printed.
|
state. When provided with a seach string, all matching enabled records will
|
||||||
|
be printed.
|
||||||
EOM
|
EOM
|
||||||
list() {
|
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 [[ -n "$1" ]]; then
|
||||||
if [[ "$1" == disabled ]]; then
|
if [[ "$1" == disabled ]]; then
|
||||||
sed -n "s/^\#disabled: \(.*\)$/\1/p" /etc/hosts
|
printf "%s\n" "${disabled_records}"
|
||||||
elif [[ "$1" == enabled ]]; then
|
elif [[ "$1" == enabled ]]; then
|
||||||
grep -v -e '^$' -e '^\s*\#' /etc/hosts
|
grep -v -e '^$' -e '^\s*\#' /etc/hosts
|
||||||
else
|
else
|
||||||
@ -762,6 +766,9 @@ list() {
|
|||||||
# NOTE: use separate expressions since using a | for the or results in
|
# NOTE: use separate expressions since using a | for the or results in
|
||||||
# inconsistent behavior.
|
# inconsistent behavior.
|
||||||
grep -v -e '^$' -e '^\s*\#' /etc/hosts
|
grep -v -e '^$' -e '^\s*\#' /etc/hosts
|
||||||
|
if [[ -n "${disabled_records}" ]]; then
|
||||||
|
printf "\nDisabled:\n%s\n" "${disabled_records}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user