diff --git a/hosts b/hosts index b7a87ae..fb594fa 100755 --- a/hosts +++ b/hosts @@ -224,8 +224,8 @@ _contains() { # _download_from [] # # Description: -# Download the file at and print to standard output or , if -# present. Uses `curl` if available, falling back to `wget`. +# Download the file at and print to standard output or . +# Uses `curl` if available, falling back to `wget`. _download_from() { local _downloaded=0 local _target_path="${2:-}" @@ -350,6 +350,9 @@ _print_entries() { # _verify_write_permissions # +# Usage: +# _verify_write_permissions +# # Print a helpful error message when the specified operation can't be # performed due to the lack of write permissions. If `$_AUTO_SUDO` is enabled, # then run the command with sudo and exit with the command's exit value. @@ -1064,6 +1067,11 @@ disable() { else _debug printf "disable() \${_search_string}: %s\\n" "${_search_string}" + # Regular Expression Notes + # + # - Note double periods in regular expression in order to emulate /.+/, + # which apparently doesn't work properly with all versions of sed. + local _regex_ip _regex_ip="^\\(${_search_string}[${_TAB_SPACE_}]..*\\)$" @@ -1073,10 +1081,6 @@ disable() { local _regex_hostname _regex_hostname="^\\([^#]..*[${_TAB_SPACE_}]${_search_string}\\)$" - # Regular Expression Notes - # - # - Note double periods in regular expression in order to emulate /.+/, - # which apparently doesn't work properly with all versions of sed. local _targets _targets=$( sed -n \ @@ -1166,6 +1170,7 @@ enable() { # # - Note double periods in regular expression in order to emulate /.+/, # which apparently doesn't work properly with all versions of sed. + local _regex_ip _regex_ip="^\\#disabled: \\(${_search_string}[${_TAB_SPACE_}]..*\\)$" @@ -1239,7 +1244,6 @@ Description: be printed. HEREDOC list() { - # Get the disabled records up front for the two cases where they are needed. local _disabled_records _disabled_records=$( sed -n "s/^\\#disabled: \\(.*\\)$/\\1/p" "${HOSTS_PATH}" @@ -1257,10 +1261,11 @@ list() { show "${1}" fi else - # NOTE: use separate expressions since using a | for the or results in + # NOTE: use separate expressions since using `|` for the 'or' results in # inconsistent behavior. local _enabled_records _enabled_records="$(grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}")" + _print_entries "${_enabled_records:-}" if [[ -n "${_disabled_records:-}" ]] @@ -1341,7 +1346,7 @@ remove() { # # Note double periods in regular expression in order to emulate /.+/, # which apparently doesn't work properly with all versions of sed. - # + # IP / Hostname pair regular expressions: local _regex_ip_hostname_commented _regex_ip_hostname_commented="^\\(${_search_ip}[${_TAB_SPACE_}]*${_search_hostname}[${_TAB_SPACE_}]..*\\)$"