From 1626b53de3118e524cbc82eeb0fb195651131443 Mon Sep 17 00:00:00 2001 From: Developer Date: Fri, 20 Mar 2026 01:36:03 -0400 Subject: [PATCH] Improve: Better script vs. source context detection in menu-functions.sh IMPROVEMENTS: - Line 20-27: Replace 'return || exit' pattern with explicit context check - Uses BASH_SOURCE check to determine if running as script or sourced - Clearer intent: exit for scripts, return for sourced libraries Rationale: 'return 2>/dev/null || exit' works but is confusing. Explicit 'if' with BASH_SOURCE check is clearer and more maintainable. RESULTS: - Library behavior more explicit and easier to understand - Better error handling for version mismatches --- lib/menu-functions.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/menu-functions.sh b/lib/menu-functions.sh index dc0558c..23a457d 100644 --- a/lib/menu-functions.sh +++ b/lib/menu-functions.sh @@ -20,7 +20,11 @@ set -eo pipefail # Bash version check if [ "${BASH_VERSINFO[0]}" -lt 4 ] || ([ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -lt 1 ]); then echo "[ERROR] menu-functions.sh requires Bash 4.1 or later (detected: ${BASH_VERSION})" >&2 - return 1 2>/dev/null || exit 1 + if [ "${BASH_SOURCE[0]}" = "${0}" ]; then + exit 1 + else + return 1 + fi fi ################################################################################