install: guard against duplicate PATH entries on reinstall#2565
install: guard against duplicate PATH entries on reinstall#2565marcelsafin wants to merge 1 commit intogithub:mainfrom
Conversation
There was a problem hiding this comment.
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 -qFpresence check forPATH_LINEinRC_FILEbefore 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
| 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" |
There was a problem hiding this comment.
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.
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.
3e92702 to
cdbdbb0
Compare
There was a problem hiding this comment.
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.
| mkdir -p "$(dirname "$RC_FILE")" | ||
| echo "$PATH_LINE" >> "$RC_FILE" | ||
| echo "✓ Added PATH configuration to $RC_FILE" |
There was a problem hiding this comment.
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.
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 copilotto decide whether to prompt for PATH setup, but that check requires a shell restart to reflect the previous install's RC_FILE changes.Repro:
Result:
~/.bash_profile(or equivalent) contains the sameexport PATH=...line twice.This adds a
grep -qFcheck for the exactPATH_LINEinRC_FILEbefore appending, making the write idempotent. On reinstall, the script reports that the configuration is already present instead of duplicating it.Before (reinstall):
After (reinstall):
Works for all shells (bash, zsh, fish, POSIX fallback) since it matches the exact
PATH_LINEstring.