Skip to content

Commit cdbdbb0

Browse files
committed
install: guard against duplicate PATH entries on reinstall
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.
1 parent 13653ea commit cdbdbb0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

install.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,13 @@ if ! command -v copilot >/dev/null 2>&1; then
175175
printf "Would you like to add it to %s? [y/N] " "$RC_FILE"
176176
if read -r REPLY </dev/tty 2>/dev/null; then
177177
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
178-
mkdir -p "$(dirname "$RC_FILE")"
179-
echo "$PATH_LINE" >> "$RC_FILE"
180-
echo "✓ Added PATH configuration to $RC_FILE"
178+
if grep -qxF -- "$PATH_LINE" "$RC_FILE" 2>/dev/null; then
179+
echo "✓ PATH configuration already in $RC_FILE"
180+
else
181+
mkdir -p "$(dirname "$RC_FILE")"
182+
echo "$PATH_LINE" >> "$RC_FILE"
183+
echo "✓ Added PATH configuration to $RC_FILE"
184+
fi
181185
echo " Restart your shell or run: source $RC_FILE"
182186
fi
183187
fi

0 commit comments

Comments
 (0)