Conversation
There was a problem hiding this comment.
Pull request overview
Adds persistence of the ~/.opencode/bin PATH update after installing opencode, so subsequent shells can find the CLI without manual configuration.
Changes:
- After a successful
opencodeinstall, appendsexport PATH="$HOME/.opencode/bin:$PATH"to existing shell startup files (.bashrc,.zshrc,.profile) if not already present.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Persist PATH for future shells if not already configured | ||
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | ||
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | ||
| echo "" >> "$rc" | ||
| echo "# OpenCode" >> "$rc" | ||
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | ||
| fi | ||
| done |
There was a problem hiding this comment.
This script silently appends to users' shell startup files (~/.bashrc, ~/.zshrc, ~/.profile). That’s a persistent side effect that can surprise users and can also pollute CI/devcontainer environments. Consider making this opt-in (flag/env var), and/or printing explicit instructions instead of modifying dotfiles automatically.
| # Persist PATH for future shells if not already configured | |
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | |
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | |
| echo "" >> "$rc" | |
| echo "# OpenCode" >> "$rc" | |
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | |
| fi | |
| done | |
| # Persist PATH for future shells if not already configured. | |
| # Only do this in interactive contexts, and allow disabling via | |
| # OPENCODE_DISABLE_SHELL_INTEGRATION=1 (useful for CI/devcontainers). | |
| if [ -t 1 ] && [ "${OPENCODE_DISABLE_SHELL_INTEGRATION:-}" != "1" ]; then | |
| echo "Configuring your shell to include ~/.opencode/bin in PATH..." | |
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | |
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | |
| echo "" >> "$rc" | |
| echo "# OpenCode" >> "$rc" | |
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | |
| echo " Updated: $rc" | |
| fi | |
| done | |
| else | |
| echo "Skipping automatic shell configuration (non-interactive shell or OPENCODE_DISABLE_SHELL_INTEGRATION=1)." | |
| echo "To use opencode in future shells, add the following line to your shell startup file (e.g., ~/.bashrc or ~/.zshrc):" | |
| echo ' export PATH="$HOME/.opencode/bin:$PATH"' | |
| fi |
|
|
||
| # Persist PATH for future shells if not already configured | ||
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | ||
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then |
There was a problem hiding this comment.
The check grep -q '.opencode/bin' "$rc" uses a regex pattern, so . matches any character and the match is also very broad (e.g., a commented mention would prevent adding the PATH export). Use a fixed-string, more specific match (e.g., grep -qF for the exact export line) to avoid false positives/negatives and accidental duplicates.
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | |
| if [ -f "$rc" ] && ! grep -qxF 'export PATH="$HOME/.opencode/bin:$PATH"' "$rc"; then |
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | ||
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | ||
| echo "" >> "$rc" | ||
| echo "# OpenCode" >> "$rc" | ||
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | ||
| fi | ||
| done |
There was a problem hiding this comment.
The loop only updates RC files if they already exist ([ -f "$rc" ]). On systems where none of these files exist (or where bash uses ~/.bash_profile and zsh uses ~/.zprofile), the PATH still won’t be persisted despite the comment. Consider including the commonly-used login files and/or creating a dedicated snippet file (or printing instructions) when no target file is present.
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do | |
| if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then | |
| echo "" >> "$rc" | |
| echo "# OpenCode" >> "$rc" | |
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | |
| fi | |
| done | |
| UPDATED_RC=false | |
| for rc in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.zshrc" "$HOME/.zprofile" "$HOME/.profile"; do | |
| if [ -f "$rc" ]; then | |
| if grep -q '.opencode/bin' "$rc"; then | |
| UPDATED_RC=true | |
| else | |
| echo "" >> "$rc" | |
| echo "# OpenCode" >> "$rc" | |
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | |
| UPDATED_RC=true | |
| fi | |
| fi | |
| done | |
| # If no existing RC or profile file was updated or already contained the path, | |
| # create/update a default bash RC file to persist the PATH. | |
| if [ "$UPDATED_RC" = "false" ]; then | |
| DEFAULT_RC="$HOME/.bashrc" | |
| if ! grep -q '.opencode/bin' "$DEFAULT_RC" 2>/dev/null; then | |
| echo "" >> "$DEFAULT_RC" | |
| echo "# OpenCode" >> "$DEFAULT_RC" | |
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$DEFAULT_RC" | |
| fi | |
| fi |
No description provided.