From 72263ca71c9f18a261a706c52a7e1352105bcaee Mon Sep 17 00:00:00 2001 From: catwinee Date: Fri, 21 Aug 2026 19:26:38 +0800 Subject: [PATCH] Detect login shell from $SHELL when installing PATH. curl | bash always sets BASH_VERSION, so fish and other non-bash users got a bash export written to the wrong rc file. Write a shell-specific snippet instead and skip duplicates on reinstall. --- README.md | 7 +-- docs/AMD_workshop/README.md | 2 +- install.sh | 91 ++++++++++++++++++++++++++----------- 3 files changed, 70 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c0f6c08..4505f84 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ curl -fsSL https://raw.githubusercontent.com/gpu-mode/popcorn-cli/main/install.s powershell -ExecutionPolicy Bypass -Command "iwr -UseBasicParsing https://raw.githubusercontent.com/gpu-mode/popcorn-cli/main/install.ps1 | iex" ``` -After installation, restart your terminal (or run `source ~/.bashrc` / `source ~/.zshrc`). +After installation, restart your terminal (or run `source ~/.bashrc` / `source ~/.zshrc` / `source ~/.config/fish/config.fish`). The release binary is named `popcorn-cli`; the one-line installers also add a `popcorn` alias, and the examples below use that shorter command. @@ -90,8 +90,9 @@ tag. **Command not found after installation:** - Restart your terminal -- Check if the install directory is in your PATH: - - Linux/macOS: `echo $PATH` +- Check if `~/.local/bin` is in your PATH (`echo $PATH`) + - fish: `fish_add_path ~/.local/bin` (the installer writes this to `~/.config/fish/config.fish`) + - bash/zsh: `export PATH="$HOME/.local/bin:$PATH"` - Windows: `echo $env:PATH` - Check if POPCORN_API_URL is set to https://site--bot--dxfjds728w5v.code.run - Linux/macOS: `echo $POPCORN_API_URL` diff --git a/docs/AMD_workshop/README.md b/docs/AMD_workshop/README.md index 82aaab2..2e7c7f9 100644 --- a/docs/AMD_workshop/README.md +++ b/docs/AMD_workshop/README.md @@ -16,7 +16,7 @@ powershell -ExecutionPolicy Bypass -Command "iwr -UseBasicParsing https://raw.gi ## 📋 Quick Start After Installation -1. **Restart your terminal** (or run `source ~/.bashrc` / `source ~/.zshrc`) +1. **Restart your terminal** (or run `source ~/.bashrc` / `source ~/.zshrc` / `source ~/.config/fish/config.fish`) 2. **Register with GitHub** (one-time setup): ```bash diff --git a/install.sh b/install.sh index 0d61d61..a7f1023 100755 --- a/install.sh +++ b/install.sh @@ -104,36 +104,75 @@ else exit 1 fi -# Add to PATH -SHELL_RC="" -if [[ -n "$ZSH_VERSION" ]]; then - SHELL_RC="$HOME/.zshrc" -elif [[ -n "$BASH_VERSION" ]]; then - SHELL_RC="$HOME/.bashrc" +# Add ~/.local/bin to the user's login-shell PATH. +# +# This installer is almost always invoked as `curl | bash`, so BASH_VERSION is +# set even when the user actually uses fish/zsh/nushell. Detect the login +# shell from $SHELL instead, write the matching rc snippet, and skip if the +# rc file already references INSTALL_DIR (re-running used to duplicate lines). +CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" +login_shell_name="$(basename "${SHELL:-/bin/sh}")" + +case "$login_shell_name" in + zsh) + SHELL_RC="$HOME/.zshrc" + PATH_SNIPPET="export PATH=\"$INSTALL_DIR:\$PATH\"" + RELOAD_HINT="source $SHELL_RC" + ;; + bash) + SHELL_RC="$HOME/.bashrc" + PATH_SNIPPET="export PATH=\"$INSTALL_DIR:\$PATH\"" + RELOAD_HINT="source $SHELL_RC" + ;; + fish) + SHELL_RC="$CONFIG_HOME/fish/config.fish" + PATH_SNIPPET="fish_add_path \"$INSTALL_DIR\"" + RELOAD_HINT="source $SHELL_RC" + ;; + nu|nushell) + SHELL_RC="$CONFIG_HOME/nushell/env.nu" + PATH_SNIPPET="\$env.PATH = (\$env.PATH | prepend \"$INSTALL_DIR\")" + RELOAD_HINT="restart your terminal" + ;; + tcsh) + SHELL_RC="$HOME/.tcshrc" + PATH_SNIPPET="setenv PATH $INSTALL_DIR:\$PATH" + RELOAD_HINT="source $SHELL_RC" + ;; + csh) + SHELL_RC="$HOME/.cshrc" + PATH_SNIPPET="setenv PATH $INSTALL_DIR:\$PATH" + RELOAD_HINT="source $SHELL_RC" + ;; + ksh|mksh|ksh93) + SHELL_RC="$HOME/.kshrc" + PATH_SNIPPET="export PATH=\"$INSTALL_DIR:\$PATH\"" + RELOAD_HINT="source $SHELL_RC" + ;; + *) + SHELL_RC="$HOME/.profile" + PATH_SNIPPET="export PATH=\"$INSTALL_DIR:\$PATH\"" + RELOAD_HINT="source $SHELL_RC" + ;; +esac + +echo "🐚 Login shell: $login_shell_name (from \$SHELL)" + +if [[ -f "$SHELL_RC" ]] && grep -F -q "$INSTALL_DIR" "$SHELL_RC"; then + echo "✅ $INSTALL_DIR already configured in $SHELL_RC" else - # Try to detect shell - case "$SHELL" in - */zsh) - SHELL_RC="$HOME/.zshrc" - ;; - */bash) - SHELL_RC="$HOME/.bashrc" - ;; - *) - SHELL_RC="$HOME/.profile" - ;; - esac + echo "🔧 Adding $INSTALL_DIR to PATH in $SHELL_RC" + mkdir -p "$(dirname "$SHELL_RC")" + { + echo "" + echo "# Added by Popcorn CLI installer" + echo "$PATH_SNIPPET" + } >> "$SHELL_RC" fi -# Check if PATH already contains the directory +# Available inside this installer process; the parent shell still needs a reload. if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then - echo "🔧 Adding $INSTALL_DIR to PATH in $SHELL_RC" - echo "" >> "$SHELL_RC" - echo "# Added by Popcorn CLI installer" >> "$SHELL_RC" - echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$SHELL_RC" export PATH="$INSTALL_DIR:$PATH" -else - echo "✅ $INSTALL_DIR already in PATH" fi # Cleanup @@ -143,7 +182,7 @@ echo "" echo "🎉 Popcorn CLI installed and ready for hackathon!" echo "" echo "📋 Quick Start:" -echo " 1. Restart your terminal or run: source $SHELL_RC" +echo " 1. Restart your terminal or run: $RELOAD_HINT" echo " 2. Register with GitHub: popcorn-cli register github" echo " 3. Submit your solution: popcorn-cli submit --gpu MI300 --leaderboard amd-fp8-mm --mode test " echo ""