Skip to content

install: guard against duplicate PATH entries on reinstall#2565

Open
marcelsafin wants to merge 1 commit intogithub:mainfrom
marcelsafin:fix/install-duplicate-path-guard
Open

install: guard against duplicate PATH entries on reinstall#2565
marcelsafin wants to merge 1 commit intogithub:mainfrom
marcelsafin:fix/install-duplicate-path-guard

Conversation

@marcelsafin
Copy link
Copy Markdown
Contributor

Running the installer twice without restarting the shell causes the PATH configuration line to be appended to the shell profile a second time. This happens because the script checks command -v copilot to decide whether to prompt for PATH setup, but that check requires a shell restart to reflect the previous install's RC_FILE changes.

Repro:

curl -fsSL https://gh.io/copilot-install | bash   # say y to PATH prompt
curl -fsSL https://gh.io/copilot-install | bash   # say y again → duplicate line

Result: ~/.bash_profile (or equivalent) contains the same export PATH=... line twice.

This adds a grep -qF check for the exact PATH_LINE in RC_FILE before appending, making the write idempotent. On reinstall, the script reports that the configuration is already present instead of duplicating it.

Before (reinstall):

✓ Added PATH configuration to /home/user/.bash_profile   ← duplicate appended

After (reinstall):

✓ PATH configuration already in /home/user/.bash_profile

Works for all shells (bash, zsh, fish, POSIX fallback) since it matches the exact PATH_LINE string.

Copy link
Copy Markdown
Contributor

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

This PR makes the installer’s PATH configuration step idempotent by checking whether the intended PATH export line is already present in the selected shell profile before appending it, preventing duplicate entries when re-running the installer in the same shell session.

Changes:

  • Add a grep -qF presence check for PATH_LINE in RC_FILE before appending.
  • Print a distinct message when PATH configuration is already present instead of writing again.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

install.sh Outdated
Comment on lines +178 to +183
if grep -qF "$PATH_LINE" "$RC_FILE" 2>/dev/null; then
echo "✓ PATH configuration already in $RC_FILE"
else
mkdir -p "$(dirname "$RC_FILE")"
echo "$PATH_LINE" >> "$RC_FILE"
echo "✓ Added PATH configuration to $RC_FILE"
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

grep -qF matches the PATH_LINE as a substring anywhere in the file. That can produce a false positive (e.g., if the line exists but is commented out or appears inside another longer line), causing the installer to claim PATH is configured when it isn’t. If the intent is to match the exact line that the script appends, use a full-line fixed-string match (e.g., grep -qxF) and consider adding -- before the pattern for safety.

Copilot uses AI. Check for mistakes.
Running the installer twice without restarting the shell causes the
PATH configuration line to be appended to the shell profile a second
time, since the script only checks whether copilot is in PATH (which
requires a shell restart to take effect) before prompting.

Check whether the exact PATH_LINE already exists in RC_FILE before
appending. This makes the write idempotent—reinstalls and upgrades
skip the duplicate and report that the configuration is already
present.
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +181 to +183
mkdir -p "$(dirname "$RC_FILE")"
echo "$PATH_LINE" >> "$RC_FILE"
echo "✓ Added PATH configuration to $RC_FILE"
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

If mkdir -p or the append to $RC_FILE fails (permissions, read-only FS), the script will still print a success message. Consider checking the return status and emitting an error / non-zero exit so users aren’t told PATH was configured when it wasn’t.

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