From 312816b18ef34a56a9a8476034b3793534bbfa2b Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 3 Jul 2026 14:48:58 +0200 Subject: [PATCH] feat: Implement strip() function (#1190) Added strip function to remove whitespace and quotes. --- src/utils.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/utils.sh b/src/utils.sh index c747830..5f567df 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -7,13 +7,40 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; } error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; } warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; } +strip() { + local value="${1:-}" + + # Remove surrounding whitespace + value="${value#"${value%%[![:space:]]*}"}" + value="${value%"${value##*[![:space:]]}"}" + + # Remove leading/trailing single/double quotes + value="${value%\"}" + value="${value#\"}" + value="${value%\'}" + value="${value#\'}" + + # Remove surrounding whitespace again + value="${value#"${value%%[![:space:]]*}"}" + value="${value%"${value##*[![:space:]]}"}" + + printf '%s' "$value" +} + enabled() { - case "${1:-}" in + case "$(strip "${1:-}")" in Y|y|YES|Yes|yes|TRUE|True|true|1|ON|On|on) return 0 ;; *) return 1 ;; esac } +disabled() { + case "$(strip "${1:-}")" in + N|n|NO|No|no|FALSE|False|false|0|OFF|Off|off) return 0 ;; + *) return 1 ;; + esac +} + formatBytes() { local result result=$(numfmt --to=iec --suffix=B "$1" | sed -r 's/([A-Z])/ \1/' | sed 's/ B/ bytes/g;')