Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions opencode-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ if ! command -v opencode &> /dev/null; then
exit 1
fi
echo "opencode installed successfully."

# 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.
echo "" >> "$rc"
echo "# OpenCode" >> "$rc"
echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc"
fi
done
Comment on lines +22 to +29
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.
Comment on lines +23 to +29
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.
fi

# Handle --skip-auth flag (for automated testing)
Expand Down