Skip to content

Commit 39d4524

Browse files
committed
Auto-select current editor during install by passing URI scheme to install scripts
- `apps/editor/src/views/prompt/backend/message-handlers/handle-update-extension.ts` should pass uri scheme as argument to command, if the install script is run with this argument, editor selection should be skipped and installation proceeded-to without any input from the user. ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── backend │ ├── message-handlers │ │ └── handle-update-extension.ts │ └── prompt-view-provider.ts ├── install.ps1 └── install.sh
1 parent 5c4c371 commit 39d4524

3 files changed

Lines changed: 57 additions & 18 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-update-extension.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ export const handle_update_extension = () => {
55
const terminal = vscode.window.createTerminal('CodeWebChat Update')
66
terminal.show()
77

8+
const uriScheme = vscode.env.uriScheme
9+
810
if (os.platform() === 'win32') {
911
terminal.sendText(
10-
'powershell -c "irm https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.ps1 | iex"',
12+
`powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.ps1))) '${uriScheme}'"`,
1113
false
1214
)
1315
} else {
1416
terminal.sendText(
15-
'curl -fsSL https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.sh | bash',
17+
`curl -fsSL https://raw.githubusercontent.com/robertpiosik/CodeWebChat/main/install.sh | bash -s -- "${uriScheme}"`,
1618
false
1719
)
1820
}

‎install.ps1‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$ErrorActionPreference = "Stop"
2+
$targetScheme = if ($args.Count -gt 0) { $args[0] } else { $null }
23

34
# Validate Node.js version and attempt to switch if necessary
45
$nodeIsGood = $false
@@ -41,19 +42,21 @@ if (!$nodeIsGood) {
4142
# Detect available editors in the system
4243
$availableEditors = @()
4344
$editorCmds = @()
45+
$editorSchemes = @()
4446

45-
function Check-Editor($Name, $Cmd) {
47+
function Check-Editor($Name, $Cmd, $Scheme) {
4648
if (Get-Command $Cmd -ErrorAction SilentlyContinue) {
4749
$script:availableEditors += $Name
4850
$script:editorCmds += $Cmd
51+
$script:editorSchemes += $Scheme
4952
}
5053
}
5154

52-
Check-Editor "VS Code" "code"
53-
Check-Editor "VS Code Insiders" "code-insiders"
54-
Check-Editor "VSCodium" "codium"
55-
Check-Editor "Cursor" "cursor"
56-
Check-Editor "Antigravity" "agy-ide"
55+
Check-Editor "VS Code" "code" "vscode"
56+
Check-Editor "VS Code Insiders" "code-insiders" "vscode-insiders"
57+
Check-Editor "VSCodium" "codium" "vscodium"
58+
Check-Editor "Cursor" "cursor" "cursor"
59+
Check-Editor "Antigravity" "agy-ide" "agy"
5760

5861
Write-Host "`nHint: If your editor is installed but not listed, you might need to add its command to your PATH." -ForegroundColor Yellow
5962
Write-Host "Open your editor, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), and find a command like: `"Shell Command: Install 'cursor' command in PATH`" (or 'agy-ide', etc.)." -ForegroundColor Yellow
@@ -73,7 +76,22 @@ if ($availableEditors.Count -gt 1) {
7376
}
7477
Write-Host "q) Quit`n"
7578

76-
$choice = Read-Host "Select where to install CWC to"
79+
$autoChoice = $null
80+
if ($targetScheme) {
81+
for ($i = 0; $i -lt $editorSchemes.Count; $i++) {
82+
if ($editorSchemes[$i] -eq $targetScheme) {
83+
$autoChoice = $i + 1
84+
break
85+
}
86+
}
87+
}
88+
89+
if ($autoChoice) {
90+
$choice = $autoChoice.ToString()
91+
Write-Host "Automatically selected $($availableEditors[$autoChoice - 1]) based on current editor ($targetScheme)." -ForegroundColor Green
92+
} else {
93+
$choice = Read-Host "Select where to install CWC to"
94+
}
7795

7896
if ($choice -eq 'q' -or $choice -eq 'Q') {
7997
Write-Host "Installation cancelled."

‎install.sh‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ fi
5454
# Detect available editors in the system
5555
declare -a AVAILABLE_EDITORS
5656
declare -a EDITOR_CMDS
57+
declare -a EDITOR_SCHEMES
5758

5859
check_editor() {
5960
if command -v "$2" >/dev/null 2>&1; then
6061
AVAILABLE_EDITORS+=("$1")
6162
EDITOR_CMDS+=("$2")
63+
EDITOR_SCHEMES+=("$3")
6264
fi
6365
}
6466

65-
check_editor "VS Code" "code"
66-
check_editor "VS Code Insiders" "code-insiders"
67-
check_editor "VSCodium" "codium"
68-
check_editor "Cursor" "cursor"
69-
check_editor "Antigravity" "agy-ide"
67+
check_editor "VS Code" "code" "vscode"
68+
check_editor "VS Code Insiders" "code-insiders" "vscode-insiders"
69+
check_editor "VSCodium" "codium" "vscodium"
70+
check_editor "Cursor" "cursor" "cursor"
71+
check_editor "Antigravity" "agy-ide" "agy"
7072

7173
echo ""
7274
echo "Hint: If your editor is installed but not listed, you might need to add its command to your PATH."
@@ -87,11 +89,28 @@ fi
8789
echo "q) Quit"
8890
echo ""
8991

90-
# Handle interactive prompt even if script is piped via curl | bash
91-
if [ -c /dev/tty ]; then
92-
read -p "Select where to install CWC to: " choice < /dev/tty
92+
TARGET_SCHEME="$1"
93+
AUTO_CHOICE=""
94+
95+
if [ -n "$TARGET_SCHEME" ]; then
96+
for i in "${!EDITOR_SCHEMES[@]}"; do
97+
if [ "${EDITOR_SCHEMES[$i]}" = "$TARGET_SCHEME" ]; then
98+
AUTO_CHOICE=$((i + 1))
99+
break
100+
fi
101+
done
102+
fi
103+
104+
if [ -n "$AUTO_CHOICE" ]; then
105+
choice="$AUTO_CHOICE"
106+
echo "Automatically selected ${AVAILABLE_EDITORS[$((choice-1))]} based on current editor ($TARGET_SCHEME)."
93107
else
94-
read -p "Select where to install CWC to: " choice
108+
# Handle interactive prompt even if script is piped via curl | bash
109+
if [ -c /dev/tty ]; then
110+
read -p "Select where to install CWC to: " choice < /dev/tty
111+
else
112+
read -p "Select where to install CWC to: " choice
113+
fi
95114
fi
96115

97116
if [[ "$choice" == "q" || "$choice" == "Q" ]]; then

0 commit comments

Comments
 (0)