Skip to content

improve path#7

Merged
PabloZaiden merged 1 commit intomainfrom
improve-path
Feb 12, 2026
Merged

improve path#7
PabloZaiden merged 1 commit intomainfrom
improve-path

Conversation

@PabloZaiden
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 12, 2026 17:23
@PabloZaiden PabloZaiden merged commit a717a44 into main Feb 12, 2026
4 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 opencode install, appends export 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.

Comment on lines +22 to +29
# 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
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.

# 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
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if [ -f "$rc" ] && ! grep -q '.opencode/bin' "$rc"; then
if [ -f "$rc" ] && ! grep -qxF 'export PATH="$HOME/.opencode/bin:$PATH"' "$rc"; then

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +29
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
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants