Add 'enabled' and 'disabled' options to `list`

These return records that have the status specified in the option.
This commit is contained in:
William Melody 2015-03-18 17:04:39 -07:00
parent 9de0edda07
commit 7d8a94d4ca
2 changed files with 9 additions and 3 deletions

View File

@ -7,7 +7,7 @@ A command line program with shortcuts for managing hosts file entries.
Usage:
hosts add <ip> <hostname>
hosts remove <hostname>
hosts list [<search string>]
hosts list [enabled | disabled | <search string>]
hosts show ( <ip> | <hostname> | <search string> )
hosts disable ( <ip> | <hostname> | <search term> )
hosts enable ( <ip> | <hostname> | <search term> )

10
hosts
View File

@ -743,7 +743,7 @@ file() {
desc list <<EOM
Usage:
$_me list [<search string>]
$_me list [enabled | disabled | <search string>]
Description:
List the existing IP / hostname pairs. When provided with a seach string, all
@ -751,7 +751,13 @@ Description:
EOM
list() {
if [[ -n "$1" ]]; then
$_me show "$1"
if [[ "$1" == disabled ]]; then
sed -n "s/^\#disabled: \(.*\)$/\1/p" /etc/hosts
elif [[ "$1" == enabled ]]; then
grep -v -e '^$' -e '^\s*\#' /etc/hosts
else
$_me show "$1"
fi
else
# NOTE: use separate expressions since using a | for the or results in
# inconsistent behavior.