From 5e2effd05bbb6a7957aa7a02b66198582c1174c3 Mon Sep 17 00:00:00 2001 From: dtzp555-max Date: Sat, 9 May 2026 00:50:07 +1000 Subject: [PATCH] fix(ocp-connect): write ~/.zshrc on macOS (default shell since Catalina) (#77) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS default shell has been zsh since Catalina (2019). The previous rc-file selection logic treated macOS the same as Linux, so on a fresh Mac where ~/.zshrc did not already exist AND the script was invoked via `bash -s --` (e.g. `curl | bash`), the $SHELL guard was `/bin/bash` and neither condition for zshrc was true — resulting in only ~/.bashrc being written. Since ~/.bashrc is not sourced by interactive zsh sessions, the OPENAI_BASE_URL / OPENAI_API_KEY exports were invisible to interactive shells. Fix: - Add an explicit `elif $is_mac` branch that unconditionally includes ~/.zshrc: create the file (empty) if it does not yet exist, since zsh tolerates an empty ~/.zshrc. - On macOS, ~/.bashrc is only written if it already exists — consistent with the task spec ("don't create ~/.bashrc if it didn't exist"). - Linux path is preserved unchanged. - Fix the "Reload your shell" hint at script end: previously it printed only the last loop variable `$rc_file` (stale reference outside the loop). Now it iterates `${rc_files[@]}` so both files are shown on macOS (reproducing the Round A bug: hint said only `source ~/.bashrc` even when zshrc should also be reloaded). Smoke-tested with HOME=/tmp/fakehome redirect for three scenarios: 1. Fresh MacBook (no .bashrc, no .zshrc) → only .zshrc created+written 2. macOS with existing .bashrc → both .bashrc and .zshrc written 3. Linux with bash, no .bashrc → .bashrc written (unchanged) Identified during Round A testing on MacBook 2026-05-08. Co-authored-by: dtzp555 Co-authored-by: Claude Sonnet 4.6 --- ocp-connect | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ocp-connect b/ocp-connect index 3b0cac2..bedd5d7 100755 --- a/ocp-connect +++ b/ocp-connect @@ -582,11 +582,19 @@ print(k if k else '') if [[ "${SHELL:-}" == */fish ]]; then echo " Note: fish shell detected. Writing to ~/.bashrc — add to fish config manually." rc_files+=("$HOME/.bashrc") + elif $is_mac; then + # macOS: default shell since Catalina (2019) is zsh. + # Always write ~/.zshrc (create if absent — zsh tolerates an empty file). + # Only write ~/.bashrc if it already exists (don't surprise users with new files). + [[ -f "$HOME/.bashrc" ]] && rc_files+=("$HOME/.bashrc") + # zshrc: always include on macOS; create the file if it doesn't exist yet + [[ -f "$HOME/.zshrc" ]] || touch "$HOME/.zshrc" + rc_files+=("$HOME/.zshrc") else - # Always write both on macOS (default shell is zsh but some tools source bashrc) + # Linux / other: write to whichever rc files already exist or match current shell [[ -f "$HOME/.bashrc" || "${SHELL:-}" == */bash ]] && rc_files+=("$HOME/.bashrc") [[ -f "$HOME/.zshrc" || "${SHELL:-}" == */zsh ]] && rc_files+=("$HOME/.zshrc") - # If neither exists, create for current shell + # If neither exists, fall back to creating one for the current shell [[ ${#rc_files[@]} -eq 0 ]] && rc_files+=("$HOME/.${SHELL##*/}rc") fi @@ -705,7 +713,9 @@ PYEOF echo "" echo " Done. Reload your shell to apply:" - echo " source $rc_file" + for rc_file in "${rc_files[@]}"; do + echo " source $rc_file" + done } main "$@"