Skip to content

Commit

Permalink
bash: clearer names and docs for the various helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Aug 18, 2023
1 parent 1a05fd5 commit 5dd8b08
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 74 deletions.
2 changes: 1 addition & 1 deletion commands/choose-option
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function choose_option() (
label="${labels[i]}"
visual="${visuals[i]}"
# compare their lowercase forms
if [[ "$(lc "$label")" == *"$(lc "$option_filter")"* ]] || [[ "$(lc "$value")" == *"$(lc "$option_filter")"* ]]; then
if [[ "$(lowercase_string "$label")" == *"$(lowercase_string "$option_filter")"* ]] || [[ "$(lowercase_string "$value")" == *"$(lowercase_string "$option_filter")"* ]]; then
# there was a partial match, add it
filtered_values+=("$value")
filtered_labels+=("$label")
Expand Down
6 changes: 3 additions & 3 deletions commands/echo-style
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ function echo_style() (
esac

# if it don't exist, it may be a foreground shorthand
if ! testv "$style" && testv "foreground_$style"; then
if ! is_var_set "$style" && is_var_set "foreground_$style"; then
style="foreground_$style"
fi

# return the color value
if testv "$style"; then
if is_var_set "$style"; then
echo -n "${!style}"

# determine the disable style
Expand All @@ -160,7 +160,7 @@ function echo_style() (
else
# custom disable, check if it exits
disable_style="disable_$style"
if testv "$disable_style"; then
if is_var_set "$disable_style"; then
# if it does, use it
DISABLE+="${!disable_style}"
else
Expand Down
4 changes: 2 additions & 2 deletions commands/is-inside
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ function is_inside() (

# convert to lower case
local haystack needle
haystack="$(lc "$1")"
haystack="$(lowercase_string "$1")"
for needle in "${@:2}"; do
# convert to lowercase
needle="$(lc "$needle")"
needle="$(lowercase_string "$needle")"

# check if it is present
if [[ $haystack == *"$needle"* ]]; then
Expand Down
14 changes: 7 additions & 7 deletions commands/setup-dns
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ function setup_dns() (
# determine servers and action
local servers action action_title
action="$1"
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"
if test "$action" = 'enable'; then
servers=(
"${ipv4_servers[@]}"
Expand Down Expand Up @@ -1020,7 +1020,7 @@ function setup_dns() (
if aghome_exists; then
action='upgrade'
fi
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"

# check
if test -z "$aghome_installer"; then
Expand Down Expand Up @@ -1092,7 +1092,7 @@ function setup_dns() (
function aghome_configure {
local action action_title upstream_servers server pattern replace
action="$1" # enable/disable
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"

# check
if ! aghome_exists; then
Expand Down Expand Up @@ -1184,7 +1184,7 @@ function setup_dns() (
if dnscrypt_exists; then
action='upgrade'
fi
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"

# check
if test -z "$dnscrypt_installer"; then
Expand Down Expand Up @@ -1275,7 +1275,7 @@ function setup_dns() (
function dnscrypt_configure {
local action action_title temp_conf_file dnscrypt_options
action="$1" # enable/disable
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"

# check
if ! dnscrypt_exists; then
Expand Down Expand Up @@ -1373,7 +1373,7 @@ function setup_dns() (
if cloudflared_exists; then
action='upgrade'
fi
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"

# check
if test -z "$cloudflared_installer"; then
Expand Down Expand Up @@ -1447,7 +1447,7 @@ function setup_dns() (
function cloudflared_configure {
local action action_title upstream_servers upstream_section upstream_args server
action="$1" # enable/disable
action_title="$(ucf "$action")"
action_title="$(uppercase_first_letter "$action")"
upstream_section=''
upstream_args=''

Expand Down
2 changes: 1 addition & 1 deletion commands/setup-linux
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function setup_linux() (

# generate log title
local title
title="$(ucf "$action") Linux"
title="$(uppercase_first_letter "$action") Linux"

# =====================================
# Configuration
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-mac
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function setup_mac() (

# generate log title
local title
title="$(ucf "$action") macOS"
title="$(uppercase_first_letter "$action") macOS"

# =====================================
# Action
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-mac-brew
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function setup_mac_brew() (

# generate log title
local title
title="Setup/$(ucf "$action") Homebrew"
title="Setup/$(uppercase_first_letter "$action") Homebrew"

# =====================================
# Action Helpers
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-system
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function setup_system() (

# generate log title
local title
title="$(ucf "$action") System"
title="$(uppercase_first_letter "$action") System"

# =====================================
# Action
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-util
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ function setup_util() (
while read -r id name; do
# trim version from the name, it doesn't work in the `read` arguments, as spaces inside name will be considered the version
name="${name%% *}"
if test "$(lc "$name")" = "$(lc "$arg")"; then
if test "$(lowercase_string "$name")" = "$(lowercase_string "$arg")"; then
exact+=("$id" "$name")
else
options+=("$id" "$name")
Expand Down
2 changes: 1 addition & 1 deletion commands/what-is-my-dns
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function what_is_my_dns() (
"get_dns_${__types[0]}"
else
for __type in "${__types[@]}"; do
printf '%s: ' "$(ucf "$__type")"
printf '%s: ' "$(uppercase_first_letter "$__type")"
"get_dns_$__type"
done
fi
Expand Down
2 changes: 1 addition & 1 deletion commands/what-is-my-ip
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function what_is_my_ip() (
"get_ip_${__types[0]}"
else
for __type in "${__types[@]}"; do
printf '%s: ' "$(ucf "$__type")"
printf '%s: ' "$(uppercase_first_letter "$__type")"
"get_ip_$__type"
done
fi
Expand Down
Loading

0 comments on commit 5dd8b08

Please sign in to comment.