From 0279d4a5d002eb748abb657e1b45481af5734d53 Mon Sep 17 00:00:00 2001 From: bcherb2 Date: Wed, 18 Nov 2026 03:02:50 -0500 Subject: [PATCH] fix: zsh-ai loads only when its provider has a key A public-only machine has no secrets.zsh, so every interactive shell printed zsh-ai's two-line "GEMINI_API_KEY not set" warning. The plugin is added only when the key its provider needs is set (ollama needs none). With secrets present it loads exactly as before. --- private_dot_zshrc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/private_dot_zshrc b/private_dot_zshrc index 48a4321..7aed51a 100644 --- a/private_dot_zshrc +++ b/private_dot_zshrc @@ -120,7 +120,20 @@ plugins=(git zsh-autosuggestions sudo web-search dirhistory history) # every platform AND separately sourced from /opt/homebrew on macOS, so it # loaded twice on mac. The existence guard also stops the array referencing a # plugin that was never installed. -[[ -z $ZSH_AI_DISABLE && -d $ZSH_CUSTOM/plugins/zsh-ai ]] && plugins+=(zsh-ai) +# +# It also loads only when its provider has a key. The key comes from +# secrets.zsh, which a public-only machine does not have, and without it the +# plugin prints a " not set" warning on every interactive shell and does +# nothing else. ollama is local and needs no key. +case ${ZSH_AI_PROVIDER:-anthropic} in + gemini) _zai_key=GEMINI_API_KEY ;; + openai) _zai_key=OPENAI_API_KEY ;; + ollama) _zai_key= ;; + *) _zai_key=ANTHROPIC_API_KEY ;; +esac +[[ -z $ZSH_AI_DISABLE && -d $ZSH_CUSTOM/plugins/zsh-ai ]] && \ + [[ -z $_zai_key || -n ${(P)_zai_key} ]] && plugins+=(zsh-ai) +unset _zai_key # Guarded. Unguarded, a clean bootstrap produces a broken login shell and # nothing tells you why.