From 860ebdf5b35e1048c5215d06003d3f21c6302802 Mon Sep 17 00:00:00 2001 From: geobelsky Date: Tue, 24 Mar 2026 12:18:51 +0000 Subject: [PATCH] fix: auto-add install dir to PATH in install script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The installer now detects the user's shell (zsh/bash/fish) and appends the PATH export to the appropriate rc file instead of just printing a generic hint. Idempotent — skips if already present. Co-Authored-By: Claude Opus 4.6 (1M context) --- install.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 2258058..6a3b081 100755 --- a/install.sh +++ b/install.sh @@ -132,13 +132,53 @@ fi log "Installed ${BIN_NAME} ${VERSION} to ${INSTALL_DIR}/${BIN_NAME}" -case ":$PATH:" in - *":${INSTALL_DIR}:"*) ;; - *) - log "" - log "Add ${INSTALL_DIR} to your PATH if it is not already present." - ;; -esac +ensure_path() { + # Already in PATH — nothing to do + case ":$PATH:" in + *":${INSTALL_DIR}:"*) return 0 ;; + esac + + SHELL_NAME="$(basename "${SHELL:-/bin/sh}")" + LINE="export PATH=\"${INSTALL_DIR}:\$PATH\"" + + case "$SHELL_NAME" in + zsh) RC_FILE="$HOME/.zshrc" ;; + bash) + # macOS defaults to .bash_profile for login shells + if [ -f "$HOME/.bash_profile" ]; then + RC_FILE="$HOME/.bash_profile" + else + RC_FILE="$HOME/.bashrc" + fi + ;; + fish) + RC_FILE="$HOME/.config/fish/config.fish" + LINE="fish_add_path ${INSTALL_DIR}" + ;; + *) RC_FILE="$HOME/.profile" ;; + esac + + # Don't duplicate if the line is already in the rc file + if [ -f "$RC_FILE" ] && grep -qF "$INSTALL_DIR" "$RC_FILE" 2>/dev/null; then + return 0 + fi + + log "" + log "Adding ${INSTALL_DIR} to PATH in ${RC_FILE}..." + + if [ "$SHELL_NAME" = "fish" ]; then + mkdir -p "$(dirname "$RC_FILE")" + fi + + printf '\n# Added by axme installer\n%s\n' "$LINE" >> "$RC_FILE" + + # Make available in the current session + export PATH="${INSTALL_DIR}:$PATH" + + log "Done. PATH updated for current and future sessions." +} + +ensure_path log "" log "Next steps:"