fix(hooks): use printf -v for bash 3.2 compat (declare -g is 4.2+)

macOS ships /bin/bash 3.2 and the script uses #!/bin/bash with
set -euo pipefail, so declare -g would abort the SessionStart hook
with "invalid option" on every Mac. printf -v writes via assignment
semantics (global from inside a function on 3.2+) — same scope
outcome, broader compatibility.
This commit is contained in:
Trevin Chow
2026-05-16 23:49:44 -07:00
parent 7506cbd542
commit 46cf2328aa
+3 -1
View File
@@ -37,7 +37,9 @@ load_env_vars() {
# command substitution in backtick-containing comments # command substitution in backtick-containing comments
value="${value%%[[:space:]]#*}" value="${value%%[[:space:]]#*}"
if [[ -n "$key" && -n "$value" ]]; then if [[ -n "$key" && -n "$value" ]]; then
declare -g "ENV_${key}=${value}" # printf -v writes via assignment semantics (global from inside a
# function), works on macOS's /bin/bash 3.2 — `declare -g` is 4.2+.
printf -v "ENV_${key}" '%s' "$value"
fi fi
done < "$file" done < "$file"
fi fi