Skip to content

Commit 29e83d8

Browse files
committed
feat(install): write user PATH on Windows; symmetric removal in bcode uninstall
install.sh: when installing on Windows (Git Bash/MSYS/Cygwin), write ~/.bcode/bin to HKCU\Environment\Path via PowerShell. Without this the binary was unreachable from PowerShell/cmd unless users added it manually. uninstall.ts: when method=curl on win32, remove the same entry from user PATH before printing the manual binary-removal hint. Avoids a dangling PATH pointing at a deleted binary.
1 parent ea0767f commit 29e83d8

2 files changed

Lines changed: 56 additions & 30 deletions

File tree

‎install.sh‎

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -414,32 +414,51 @@ case $current_shell in
414414
;;
415415
esac
416416

417+
add_to_user_path_windows() {
418+
# User PATH lives in HKCU\Environment. Read it via PowerShell, append our
419+
# dir if missing, write it back. Idempotent. Survives across PowerShell,
420+
# cmd, and new Git Bash sessions (each shell reads PATH on start).
421+
local win_dir
422+
win_dir=$(cygpath -w "$INSTALL_DIR" 2>/dev/null || echo "$INSTALL_DIR")
423+
powershell.exe -NoProfile -Command "
424+
\$d = '$win_dir'
425+
\$p = [Environment]::GetEnvironmentVariable('Path','User')
426+
if (\$p -split ';' -notcontains \$d) {
427+
[Environment]::SetEnvironmentVariable('Path', (\$p.TrimEnd(';') + ';' + \$d), 'User')
428+
}" >/dev/null
429+
print_message info "${MUTED}Added ${NC}$INSTALL_DIR${MUTED} to user PATH (open a new shell to use)${NC}"
430+
}
431+
417432
if [[ "$no_modify_path" != "true" ]]; then
418-
config_file=""
419-
for file in $config_files; do
420-
if [[ -f $file ]]; then
421-
config_file=$file
422-
break
433+
if [[ "${os:-}" == "windows" ]]; then
434+
add_to_user_path_windows
435+
else
436+
config_file=""
437+
for file in $config_files; do
438+
if [[ -f $file ]]; then
439+
config_file=$file
440+
break
441+
fi
442+
done
443+
444+
if [[ -z $config_file ]]; then
445+
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
446+
print_message info " export PATH=$INSTALL_DIR:\$PATH"
447+
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
448+
case $current_shell in
449+
fish)
450+
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
451+
;;
452+
zsh|bash|ash|sh)
453+
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
454+
;;
455+
*)
456+
export PATH=$INSTALL_DIR:$PATH
457+
print_message warning "Manually add the directory to $config_file (or similar):"
458+
print_message info " export PATH=$INSTALL_DIR:\$PATH"
459+
;;
460+
esac
423461
fi
424-
done
425-
426-
if [[ -z $config_file ]]; then
427-
print_message warning "No config file found for $current_shell. You may need to manually add to PATH:"
428-
print_message info " export PATH=$INSTALL_DIR:\$PATH"
429-
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
430-
case $current_shell in
431-
fish)
432-
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
433-
;;
434-
zsh|bash|ash|sh)
435-
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
436-
;;
437-
*)
438-
export PATH=$INSTALL_DIR:$PATH
439-
print_message warning "Manually add the directory to $config_file (or similar):"
440-
print_message info " export PATH=$INSTALL_DIR:\$PATH"
441-
;;
442-
esac
443462
fi
444463
fi
445464

@@ -459,10 +478,10 @@ if ! command -v uv >/dev/null 2>&1; then
459478
fi
460479

461480
echo -e ""
462-
echo -e "${MUTED}▄⠀ ▄ ${NC}"
463-
echo -e "${MUTED}█▀▀█ █▀▀▄ █▀▀█ █ █ █▀▀▀ █▀▀█ █▀▀▄ █▀▀▀ █▀▀█ █▀▀█ █▀▀█${NC}"
464-
echo -e "${MUTED}█ █ █ █ █ █▐▌█ ▀▀▀█ █▀▀▀ █ █ █ █ █ █ █▀▀▀${NC}"
465-
echo -e "${MUTED}▀▀▀▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀${NC}"
481+
echo -e "${MUTED}▄⠀ ${NC} ▄ "
482+
echo -e "${MUTED}█▀▀█ █▀▀▄ █▀▀█ █ █ █▀▀▀ █▀▀█ █▀▀▄ ${NC}█▀▀▀ █▀▀█ █▀▀█ █▀▀█"
483+
echo -e "${MUTED}█░░█ █░░░ █░░█ █▐▌█ ▀▀▀█ █▀▀▀ █░░░ ${NC}█░░░ █░░█ █░░█ █▀▀▀"
484+
echo -e "${MUTED}▀▀▀▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ${NC}▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀"
466485
echo -e ""
467486
echo -e "${MUTED}BrowserCode ${NC}$specific_version${MUTED} installed to ${NC}$INSTALL_DIR/bcode"
468487
echo -e ""

‎packages/opencode/src/cli/cmd/uninstall.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,18 @@ async function executeUninstall(method: Installation.Method, targets: RemovalTar
211211
}
212212

213213
if (method === "curl" && targets.binary) {
214+
const binDir = path.dirname(targets.binary)
215+
216+
if (process.platform === "win32" && binDir.includes(".bcode")) {
217+
// bcode/install.sh adds binDir to user PATH on Windows; remove it here.
218+
const ps = `$d='${binDir.replace(/'/g, "''")}'; $p=[Environment]::GetEnvironmentVariable('Path','User'); $n=($p -split ';' | Where-Object { $_ -ne $d }) -join ';'; if ($n -ne $p) { [Environment]::SetEnvironmentVariable('Path', $n, 'User') }`
219+
await Process.run(["powershell.exe", "-NoProfile", "-Command", ps], { nothrow: true })
220+
prompts.log.step("Removed from user PATH")
221+
}
222+
214223
UI.empty()
215224
prompts.log.message("To finish removing the binary, run:")
216225
prompts.log.info(` rm "${targets.binary}"`)
217-
218-
const binDir = path.dirname(targets.binary)
219226
if (binDir.includes(".bcode")) {
220227
prompts.log.info(` rmdir "${binDir}" 2>/dev/null`)
221228
}

0 commit comments

Comments
 (0)