Print disabled matches in `show`

This commit is contained in:
William Melody 2015-03-18 17:41:04 -07:00
parent 522d189f2e
commit bc36182773
1 changed files with 6 additions and 1 deletions

7
hosts
View File

@ -812,7 +812,12 @@ Description:
EOM
show() {
if [[ -n "$1" ]]; then
grep "^[^#]*$1" /etc/hosts
# Run `sed` before `grep` to avoid conflict that supress `sed` output.
disabled_records=$(sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" /etc/hosts)
enabled_records=$(grep "^[^#]*$1" /etc/hosts)
# Output disabled records secondly for better organization.
[[ -n "$enabled_records" ]] && printf "%s\n" "$enabled_records"
[[ -n "$disabled_records" ]] && printf "%s\n" "$disabled_records"
else
$_me help show
exit 1