1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-25 06:07:40 +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>] # _download_from <url> [<outfile>]
# #
# Description: # Description:
# Download the file at <url> and print to standard output or <outfile>, if # Download the file at <url> and print to standard output or <outfile>.
# present. Uses `curl` if available, falling back to `wget`. # Uses `curl` if available, falling back to `wget`.
_download_from() { _download_from() {
local _downloaded=0 local _downloaded=0
local _target_path="${2:-}" local _target_path="${2:-}"
@ -350,6 +350,9 @@ _print_entries() {
# _verify_write_permissions # _verify_write_permissions
# #
# Usage:
# _verify_write_permissions
#
# Print a helpful error message when the specified operation can't be # 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, # 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. # then run the command with sudo and exit with the command's exit value.
@ -1064,6 +1067,11 @@ disable() {
else else
_debug printf "disable() \${_search_string}: %s\\n" "${_search_string}" _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 local _regex_ip
_regex_ip="^\\(${_search_string}[${_TAB_SPACE_}]..*\\)$" _regex_ip="^\\(${_search_string}[${_TAB_SPACE_}]..*\\)$"
@ -1073,10 +1081,6 @@ disable() {
local _regex_hostname local _regex_hostname
_regex_hostname="^\\([^#]..*[${_TAB_SPACE_}]${_search_string}\\)$" _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 local _targets
_targets=$( _targets=$(
sed -n \ sed -n \
@ -1166,6 +1170,7 @@ enable() {
# #
# - Note double periods in regular expression in order to emulate /.+/, # - Note double periods in regular expression in order to emulate /.+/,
# which apparently doesn't work properly with all versions of sed. # which apparently doesn't work properly with all versions of sed.
local _regex_ip local _regex_ip
_regex_ip="^\\#disabled: \\(${_search_string}[${_TAB_SPACE_}]..*\\)$" _regex_ip="^\\#disabled: \\(${_search_string}[${_TAB_SPACE_}]..*\\)$"
@ -1239,7 +1244,6 @@ Description:
be printed. be printed.
HEREDOC HEREDOC
list() { list() {
# Get the disabled records up front for the two cases where they are needed.
local _disabled_records local _disabled_records
_disabled_records=$( _disabled_records=$(
sed -n "s/^\\#disabled: \\(.*\\)$/\\1/p" "${HOSTS_PATH}" sed -n "s/^\\#disabled: \\(.*\\)$/\\1/p" "${HOSTS_PATH}"
@ -1257,10 +1261,11 @@ list() {
show "${1}" show "${1}"
fi fi
else 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. # inconsistent behavior.
local _enabled_records local _enabled_records
_enabled_records="$(grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}")" _enabled_records="$(grep -v -e '^$' -e '^\s*\#' "${HOSTS_PATH}")"
_print_entries "${_enabled_records:-}" _print_entries "${_enabled_records:-}"
if [[ -n "${_disabled_records:-}" ]] if [[ -n "${_disabled_records:-}" ]]
@ -1341,7 +1346,7 @@ remove() {
# #
# Note double periods in regular expression in order to emulate /.+/, # Note double periods in regular expression in order to emulate /.+/,
# which apparently doesn't work properly with all versions of sed. # which apparently doesn't work properly with all versions of sed.
#
# IP / Hostname pair regular expressions: # IP / Hostname pair regular expressions:
local _regex_ip_hostname_commented local _regex_ip_hostname_commented
_regex_ip_hostname_commented="^\\(${_search_ip}[${_TAB_SPACE_}]*${_search_hostname}[${_TAB_SPACE_}]..*\\)$" _regex_ip_hostname_commented="^\\(${_search_ip}[${_TAB_SPACE_}]*${_search_hostname}[${_TAB_SPACE_}]..*\\)$"