From 7d8a94d4caab619ae5311b8dd7bafe3fe3a459f9 Mon Sep 17 00:00:00 2001 From: William Melody Date: Wed, 18 Mar 2015 17:04:39 -0700 Subject: [PATCH] Add 'enabled' and 'disabled' options to `list` These return records that have the status specified in the option. --- Readme.md | 2 +- hosts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index b76898f..4d6bbf3 100644 --- a/Readme.md +++ b/Readme.md @@ -7,7 +7,7 @@ A command line program with shortcuts for managing hosts file entries. Usage: hosts add hosts remove - hosts list [] + hosts list [enabled | disabled | ] hosts show ( | | ) hosts disable ( | | ) hosts enable ( | | ) diff --git a/hosts b/hosts index 7db328f..6540506 100755 --- a/hosts +++ b/hosts @@ -743,7 +743,7 @@ file() { desc list <] + $_me list [enabled | disabled | ] 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.