-
Notifications
You must be signed in to change notification settings - Fork 0
improve path #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve path #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" >> "$rc" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "# OpenCode" >> "$rc" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> "$rc" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 | |
| # 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
AI
Feb 12, 2026
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.