1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-21 20:35:10 +00:00

Improve spacing and comments in subcommands.

This commit is contained in:
William Melody 2020-06-08 09:41:36 -07:00
parent 5049abe817
commit bd7edba09b

23
hosts
View File

@ -224,8 +224,8 @@ _contains() {
# _download_from <url> [<outfile>]
#
# Description:
# Download the file at <url> and print to standard output or <outfile>, if
# present. Uses `curl` if available, falling back to `wget`.
# Download the file at <url> and print to standard output or <outfile>.
# Uses `curl` if available, falling back to `wget`.
_download_from() {
local _downloaded=0
local _target_path="${2:-}"
@ -348,6 +348,9 @@ _print_entries() {
done <<< "${_input}"
}
# _verify_write_permissions
#
# Usage:
# _verify_write_permissions
#
# Print a helpful error message when the specified operation can't be
@ -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_}]..*\\)$"