diff --git a/install-pi.sh b/install-pi.sh index a2b0d88..4af7374 100755 --- a/install-pi.sh +++ b/install-pi.sh @@ -140,7 +140,8 @@ if [ -z "$PI_BIN" ] && command -v npm &>/dev/null; then fi fi -# Add pi's directory to PATH for this session so pi install subprocess works +# Add pi's directory to PATH for this session so pi install subprocess works, +# and permanently add it to the shell profile if not already there. if [ -n "$PI_BIN" ]; then PI_DIR="$(dirname "$PI_BIN")" case ":$PATH:" in @@ -148,6 +149,29 @@ if [ -n "$PI_BIN" ]; then *) export PATH="$PI_DIR:$PATH" info "Added $PI_DIR to PATH for this session" + + # Permanently add to shell profile + SHELL_RC="" + if [ -n "${ZSH_VERSION:-}" ] && [ -f "$HOME/.zshrc" ]; then + SHELL_RC="$HOME/.zshrc" + elif [ -f "$HOME/.bashrc" ]; then + SHELL_RC="$HOME/.bashrc" + fi + + if [ -n "$SHELL_RC" ]; then + PATH_LINE="export PATH=\"$PI_DIR:\$PATH\"" + if ! grep -qF "$PI_DIR" "$SHELL_RC" 2>/dev/null; then + echo "" >>"$SHELL_RC" + echo "# Added by install-pi.sh" >>"$SHELL_RC" + echo "$PATH_LINE" >>"$SHELL_RC" + success "Added $PI_DIR to $SHELL_RC (takes effect on next login)" + else + info "$PI_DIR already in $SHELL_RC" + fi + else + warn "Could not detect shell config. Add this line to your profile manually:" + warn " export PATH=\"$PI_DIR:\$PATH\"" + fi ;; esac success "Pi is available: $PI_BIN" @@ -205,21 +229,6 @@ info "════════════════════════ info "" info "Pi binary: $PI_BIN" info "" -if [ -n "$PI_DIR" ]; then - case ":$PATH:" in - *":$PI_DIR:"*) ;; - *) - SHELL_RC="" - if [ -f "$HOME/.bashrc" ]; then SHELL_RC="$HOME/.bashrc"; elif [ -f "$HOME/.zshrc" ]; then SHELL_RC="$HOME/.zshrc"; fi - if [ -n "$SHELL_RC" ]; then - info "NOTE: Add $PI_DIR to your PATH permanently by running:" - info " echo 'export PATH=\"$PI_DIR:\$PATH\"' >> $SHELL_RC" - info " source $SHELL_RC" - fi - ;; - esac -fi -info "" info "Getting started:" info " 1. Navigate to your project: cd /path/to/project" info " 2. Start Pi: pi"