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.
This commit is contained in:
1 parent
06b03c9528
commit
0279d4a5d0
1 file changed
+14
-1
+14
-1
@@ -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
|
# 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
|
# loaded twice on mac. The existence guard also stops the array referencing a
|
||||||
# plugin that was never installed.
|
# 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 "<KEY> 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
|
# Guarded. Unguarded, a clean bootstrap produces a broken login shell and
|
||||||
# nothing tells you why.
|
# nothing tells you why.
|
||||||
|
|||||||
Reference in new issue
Block a user