Skip to content

Commit eb094e6

Browse files
committed
ZSH: Add zsh-ai-cmd plugin with macOS Keychain API key management
Add zsh-ai-cmd plugin for AI shell suggestions (Ctrl+Z for ghost text). Uses Anthropic provider with claude-haiku-4-5-20251001. API key is stored in macOS Keychain via a run_onchange_after script that reads from 1Password and writes to Keychain as 'zsh-ai-cmd-anthropic'. The script re-runs when the 1Password item's modification time changes. The plugin's ZSH_AI_CMD_KEYCHAIN_NAME uses ${provider} interpolation so switching providers only requires changing ZSH_AI_CMD_PROVIDER. macOS only — the keychain script skips on Linux.
1 parent 99204c8 commit eb094e6

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

home/.chezmoidata/zsh_plugins.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
zsh_plugins:
1717
- repo: zsh-users/zsh-autosuggestions
1818
description: "Fish-like autosuggestions for zsh"
19+
- repo: kylesnowschwartz/zsh-ai-cmd
20+
description: "AI shell suggestions with ghost text via Ctrl+Z"
1921
- repo: ohmyzsh/ohmyzsh
2022
description: "Community-driven zsh framework, used as a plugin source"
2123
plugins:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
# trigger: {{ (onepassword "Anthropic API" "dotfiles").updated_at }}
4+
5+
# {{ template "dotfiles_bashlib.sh" . }}
6+
7+
# Help shellcheck identify the above include
8+
true || source ../.chezmoitemplates/dotfiles_bashlib.sh
9+
10+
{{ if ne .chezmoi.os "darwin" -}}
11+
dot::chezmoi_script_skipped "macOS only"
12+
{{ else -}}
13+
14+
dot::chezmoi_script_start "store Anthropic API key in macOS Keychain"
15+
16+
KEYCHAIN_SERVICE="zsh-ai-cmd-anthropic"
17+
18+
dot::step::start "read key from 1Password"
19+
key=$(op read "op://dotfiles/Anthropic API/credential") || dot::step::fatal
20+
dot::step::done
21+
22+
dot::step::start "store in macOS Keychain"
23+
# Delete existing entry if present (security add fails on duplicates)
24+
security delete-generic-password -s "$KEYCHAIN_SERVICE" -a "$USER" 2>/dev/null
25+
security add-generic-password -s "$KEYCHAIN_SERVICE" -a "$USER" -w "$key" || dot::step::fatal
26+
dot::step::done
27+
28+
dot::success "Anthropic API key stored in Keychain as '$KEYCHAIN_SERVICE'"
29+
30+
{{ end -}}

home/dot_config/zsh/exact_private_zsh.d/private_007_plugin_config.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
if plug::is_loaded zsh-autosuggestions; then
55
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
66
fi
7+
8+
if plug::is_loaded zsh-ai-cmd; then
9+
ZSH_AI_CMD_PROVIDER=anthropic
10+
ZSH_AI_CMD_ANTHROPIC_MODEL=claude-haiku-4-5-20251001
11+
ZSH_AI_CMD_KEYCHAIN_NAME='zsh-ai-cmd-${provider}'
12+
fi

0 commit comments

Comments
 (0)