From b624114a432d637b6d68427ed1839600d2cec0dc Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 13 Mar 2026 05:08:53 -0700 Subject: [PATCH] Fix readonly variable crash in non-tty environments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setup_Terminal_Capabilities checked Term_Reset with -z (emptiness), but in non-tty contexts tput fails and Term_Reset gets set to empty string as readonly at line 302. The -z check sees "empty", tries to re-set it, and crashes with "read-only variable". Fix: check variable existence (typeset -p) instead of emptiness (-z). A readonly empty variable is still declared — it just has no value. Reproduces via: ssh host 'source _Z_Utils.zsh' or any non-tty context. Signed-off-by: Christopher Allen --- src/lib/_Z_Utils.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/_Z_Utils.zsh b/src/lib/_Z_Utils.zsh index d4c9d53..ee76b05 100755 --- a/src/lib/_Z_Utils.zsh +++ b/src/lib/_Z_Utils.zsh @@ -1446,8 +1446,12 @@ function z_Setup_Environment() { # Set up terminal capabilities if not already set function setup_Terminal_Capabilities() { - # Only initialize if they aren't already defined - if [[ -z "$Term_Reset" ]]; then + # Only initialize if they aren't already declared. + # Check variable existence, not emptiness: in non-tty environments, + # Term_Reset is set to empty string at line ~302 but is still readonly. + # Using -z would see "empty" and try to re-set it, crashing with + # "read-only variable". + if ! typeset -p Term_Reset >/dev/null 2>&1; then # Initialize terminal capabilities typeset -g Term_Reset="$(tput sgr0 2>/dev/null || echo '')" typeset -g Term_Bold="$(tput bold 2>/dev/null || echo '')"