diff --git a/mcp-config/install.sh b/mcp-config/install.sh index fe3c633..8bbcb2e 100755 --- a/mcp-config/install.sh +++ b/mcp-config/install.sh @@ -120,11 +120,23 @@ say "Key stored at $KEYFILE (0600)." # bootstrap run — and then models and skills silently vanish, because sync.sh # never runs and OPENCODE_CONFIG is never exported. ~/.zshrc.local is the # unmanaged file the managed zshrc sources last, so the hook persists. -case "${SHELL:-}" in - *zsh) RC="$HOME/.zshrc.local" ;; - *bash) RC="$HOME/.bashrc" ;; - *) [ -f "$HOME/.zshrc" ] && RC="$HOME/.zshrc.local" || RC="$HOME/.bashrc" ;; -esac +# +# Do NOT pick the file from $SHELL alone. On a fresh box bootstrap runs this +# from the user's ORIGINAL shell: zsh/ has just switched the login shell to zsh, +# but $SHELL in this process still says bash. The hook then went into ~/.bashrc, +# below zsh/'s auto-exec hook, so every new terminal exec'd into zsh before +# reaching it, zsh never sourced sync.sh, and opencode came up unconfigured. +# The dotfiles-managed ~/.zshrc (or zsh as the account's login shell) wins. +_login_shell="$(getent passwd "$(id -un)" 2>/dev/null | cut -d: -f7)" +if grep -qs 'Managed by dotfiles/zsh/install.sh' "$HOME/.zshrc"; then + RC="$HOME/.zshrc.local" +else + case "${_login_shell:-${SHELL:-}}" in + *zsh) RC="$HOME/.zshrc.local" ;; + *bash) RC="$HOME/.bashrc" ;; + *) [ -f "$HOME/.zshrc" ] && RC="$HOME/.zshrc.local" || RC="$HOME/.bashrc" ;; + esac +fi touch "$RC" # It sits alongside the user's secrets; keep it non-readable by others. [ "$RC" = "$HOME/.zshrc.local" ] && chmod 0600 "$RC" 2>/dev/null || true