Installer: add ~/.local/bin to PATH instead of only warning

Appends an export to the profile for the user's shell (zsh: .zshrc,
bash: .bash_profile on macOS / .bashrc on Linux, fish: config.fish),
once, and tells the user to open a new terminal at the end of setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
This commit is contained in:
neil 2026-11-02 05:44:35 -08:00
parent 7ad0642d2e
commit b07af69afa
2 changed files with 28 additions and 4 deletions

View file

@ -86,10 +86,32 @@ PYTHONPATH="$SRC" exec "$PY" -P -m llmhost "\$@"
EOF EOF
chmod +x "$BIN/llmhost" chmod +x "$BIN/llmhost"
case ":$PATH:" in # Put ~/.local/bin on PATH for future shells (like uv's and opencode's installers do).
*":$BIN:"*) ;; add_to_path() {
*) warn "$BIN isn't on your PATH. Add this to your shell profile: export PATH=\"$BIN:\$PATH\"" ;; case ":$PATH:" in *":$BIN:"*) return 0 ;; esac
local rc line
case "$(basename "${SHELL:-}")" in
zsh) rc="${ZDOTDIR:-$HOME}/.zshrc"; line='export PATH="$HOME/.local/bin:$PATH"' ;;
bash) if [ "$OS" = "Darwin" ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi
line='export PATH="$HOME/.local/bin:$PATH"' ;;
fish) rc="$HOME/.config/fish/config.fish"; line='fish_add_path $HOME/.local/bin' ;;
*) warn "$BIN isn't on your PATH. Add it in your shell's startup file: export PATH=\"$BIN:\$PATH\""; return 0 ;;
esac esac
if grep -qsF '$HOME/.local/bin' "$rc" || grep -qsF "$BIN" "$rc"; then
PATH_NOTE="$rc" # already configured; only this shell is missing it
return 0
fi
mkdir -p "$(dirname "$rc")"
printf '\n# Added by llm-host\n%s\n' "$line" >> "$rc"
say "Added $BIN to your PATH in $rc"
PATH_NOTE="$rc"
}
PATH_NOTE=""
add_to_path
if [ -n "$PATH_NOTE" ]; then
# Shown before setup's long output so it isn't missed; setup repeats it at the end.
export LLMHOST_PATH_NOTE="Open a new terminal (or run: source $PATH_NOTE) to use the llmhost command."
fi
say "Running setup" say "Running setup"
exec "$BIN/llmhost" setup "$@" exec "$BIN/llmhost" setup "$@"

View file

@ -148,6 +148,8 @@ Done.
if not a.no_opencode: if not a.no_opencode:
setup_opencode(cfg, ask=sys.stdin.isatty() and not a.yes, install_ok=a.opencode) setup_opencode(cfg, ask=sys.stdin.isatty() and not a.yes, install_ok=a.opencode)
say(f"\nOther machines: run `llmhost opencode-config` here for their opencode setup.") say(f"\nOther machines: run `llmhost opencode-config` here for their opencode setup.")
if os.environ.get("LLMHOST_PATH_NOTE"):
say("\n" + os.environ["LLMHOST_PATH_NOTE"])
def setup_opencode(cfg, ask, install_ok=False, later="llmhost opencode-setup"): def setup_opencode(cfg, ask, install_ok=False, later="llmhost opencode-setup"):