diff --git a/Readme.md b/Readme.md index 5dca020..b76898f 100644 --- a/Readme.md +++ b/Readme.md @@ -9,6 +9,8 @@ A command line program with shortcuts for managing hosts file entries. hosts remove hosts list [] hosts show ( | | ) + hosts disable ( | | ) + hosts enable ( | | ) hosts edit hosts file diff --git a/hosts b/hosts index 04f4617..7db328f 100755 --- a/hosts +++ b/hosts @@ -660,6 +660,30 @@ add() { fi } +# --------------------------------------------------------------------- disable + +desc disable <||) + +Description: + Disable one or more records based on a given ip address, hostname, or + search term. +EOM +disable() { + local search_term=$1 + if [[ -z "${search_term}" ]]; then + $_me help disable + exit 1 + else + + targets=$(sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" /etc/hosts) + printf "Disabling:\n%s\n" "${targets}" + + sed -i "s/^\([^#]*${search_term}.*\)$/\#disabled: \1/g" /etc/hosts + fi +} + # ------------------------------------------------------------------------ edit desc edit <||) + +Description: + Enable one or more disabled records based on a given ip address, hostname, + or search term. +EOM +enable() { + local search_term=$1 + if [[ -z "${search_term}" ]]; then + $_me help enable + exit 1 + else + target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/" + + targets=$(sed -n "${target_regex}p" /etc/hosts) + printf "Enabling:\n%s\n" "${targets}" + + sed -i "${target_regex}g" /etc/hosts + fi +} + # ------------------------------------------------------------------------ file desc file <