-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_ide_example.ps1
More file actions
236 lines (210 loc) · 7.23 KB
/
start_ide_example.ps1
File metadata and controls
236 lines (210 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# IDE Starter Script für Windows PowerShell
param(
[string]$IDE,
[string]$Slot
)
# IDE Konfigurationen
$IDES = @{
"cursor" = ".\Cursor.exe"
"vscode" = "code"
}
# Port Ranges für verschiedene IDEs
$PORT_RANGES = @{
"cursor" = @(9222..9232)
"vscode" = @(9233..9242)
}
# Hilfsfunktion: prüft ob Port frei ist
function Test-PortInUse {
param([int]$Port)
try {
$connection = Test-NetConnection -ComputerName "localhost" -Port $Port -InformationLevel Quiet -WarningAction SilentlyContinue
return $connection.TcpTestSucceeded
}
catch {
return $false
}
}
# Hilfsfunktion: findet freien Port in Range
function Find-FreePort {
param([int[]]$PortRange)
foreach ($port in $PortRange) {
if (-not (Test-PortInUse -Port $port)) {
return $port
}
}
return $null
}
# Hilfsfunktion: zeigt verfügbare IDEs
function Show-IDEs {
Write-Host "📋 Verfügbare IDEs:" -ForegroundColor Cyan
foreach ($ide in $IDES.Keys) {
$range = $PORT_RANGES[$ide]
Write-Host " $ide (Ports $($range[0])-$($range[-1]))" -ForegroundColor Yellow
}
}
# Hilfsfunktion: zeigt Hilfe
function Show-Help {
Write-Host "🚀 IDE Starter Script" -ForegroundColor Green
Write-Host ""
Write-Host "Verwendung:" -ForegroundColor White
Write-Host " .\start_ide_example.ps1 [ide] [slot]" -ForegroundColor Gray
Write-Host " .\start_ide_example.ps1 [ide] auto" -ForegroundColor Gray
Write-Host " .\start_ide_example.ps1 menu" -ForegroundColor Gray
Write-Host ""
Write-Host "Argumente:" -ForegroundColor White
Write-Host " ide - cursor, vscode" -ForegroundColor Gray
Write-Host " slot - spezifischer Slot (Zahl)" -ForegroundColor Gray
Write-Host " auto - automatisch freien Slot finden" -ForegroundColor Gray
Write-Host " menu - interaktives Menü" -ForegroundColor Gray
Write-Host ""
Show-IDEs
Write-Host ""
Write-Host "Beispiele:" -ForegroundColor White
Write-Host " .\start_ide_example.ps1 cursor # Cursor mit freiem Port starten" -ForegroundColor Gray
Write-Host " .\start_ide_example.ps1 vscode 3 # VSCode auf Slot 3 starten" -ForegroundColor Gray
Write-Host " .\start_ide_example.ps1 cursor auto # Cursor mit automatischem Slot" -ForegroundColor Gray
}
# Interaktives Menü
function Show-Menu {
Write-Host "🎯 IDE Starter - Wähle deine IDE:" -ForegroundColor Green
Write-Host ""
$i = 1
foreach ($ide in $IDES.Keys) {
$range = $PORT_RANGES[$ide]
Write-Host " $i) $ide (Ports $($range[0])-$($range[-1]))" -ForegroundColor Yellow
$i++
}
Write-Host " $i) Hilfe" -ForegroundColor Cyan
Write-Host " 0) Beenden" -ForegroundColor Red
Write-Host ""
$choice = Read-Host "Wähle eine Option (0-$i)"
switch ($choice) {
"0" { exit }
"$i" { Show-Help; exit }
default {
$idesArray = @($IDES.Keys)
if ([int]$choice -ge 1 -and [int]$choice -le $idesArray.Count) {
$selectedIDE = $idesArray[[int]$choice - 1]
Write-Host ""
$slot = Read-Host "Slot für $selectedIDE (Zahl oder 'auto')"
Start-IDE -IDE $selectedIDE -Slot $slot
}
else {
Write-Host "❌ Ungültige Auswahl" -ForegroundColor Red
exit 1
}
}
}
}
# IDE starten
function Start-IDE {
param(
[string]$IDE,
[string]$Slot
)
# Prüfe ob IDE existiert
if (-not $IDES.ContainsKey($IDE)) {
Write-Host "❌ Unbekannte IDE: $IDE" -ForegroundColor Red
Show-IDEs
exit 1
}
$idePath = $IDES[$IDE]
$portRange = $PORT_RANGES[$IDE]
# Prüfe ob IDE verfügbar ist
if ($IDE -eq "cursor") {
if (-not (Test-Path $idePath)) {
Write-Host "❌ Cursor nicht gefunden: $idePath" -ForegroundColor Red
Write-Host " Stelle sicher, dass Cursor.exe im aktuellen Verzeichnis liegt" -ForegroundColor Yellow
exit 1
}
}
else {
try {
Get-Command $idePath -ErrorAction Stop | Out-Null
}
catch {
Write-Host "❌ $IDE ist nicht installiert oder nicht im PATH" -ForegroundColor Red
exit 1
}
}
$port = $null
$dir = $null
# Port und Verzeichnis bestimmen
if ([string]::IsNullOrEmpty($Slot)) {
# Automatisch freien Port finden
$port = Find-FreePort -PortRange $portRange
if ($null -eq $port) {
Write-Host "❌ Kein freier Port in Range $($portRange[0])-$($portRange[-1]) verfügbar" -ForegroundColor Red
exit 1
}
$dir = "$env:USERPROFILE\.pidea\.${IDE}_$port"
}
elseif ($Slot -eq "auto") {
# Automatisch freien Port finden
$port = Find-FreePort -PortRange $portRange
if ($null -eq $port) {
Write-Host "❌ Kein freier Port in Range $($portRange[0])-$($portRange[-1]) verfügbar" -ForegroundColor Red
exit 1
}
$dir = "$env:USERPROFILE\.pidea\.${IDE}_$port"
}
elseif ($Slot -match '^\d+$') {
# Spezifischer Slot
$slotNumber = [int]$Slot
$port = $portRange[0] + $slotNumber - 1
if ($port -gt $portRange[-1]) {
Write-Host "❌ Slot $Slot ist außerhalb der verfügbaren Range ($($portRange[0])-$($portRange[-1]))" -ForegroundColor Red
exit 1
}
if (Test-PortInUse -Port $port) {
Write-Host "❌ Port $port (Slot $Slot) ist bereits belegt" -ForegroundColor Red
exit 1
}
$dir = "$env:USERPROFILE\.pidea\.${IDE}_$port"
}
else {
Write-Host "❌ Ungültiger Slot: $Slot" -ForegroundColor Red
exit 1
}
# Verzeichnis erstellen falls nicht vorhanden
$pideaDir = "$env:USERPROFILE\.pidea"
if (-not (Test-Path $pideaDir)) {
New-Item -ItemType Directory -Path $pideaDir -Force | Out-Null
}
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
}
# IDE starten
Write-Host "🚀 Starte $IDE auf Port $port..." -ForegroundColor Green
try {
if ($IDE -eq "cursor") {
Start-Process -FilePath $idePath -ArgumentList "--user-data-dir=`"$dir`"", "--remote-debugging-port=$port" -WindowStyle Normal
}
else {
Start-Process -FilePath $idePath -ArgumentList "--user-data-dir=`"$dir`"", "--remote-debugging-port=$port" -WindowStyle Normal
}
Write-Host "✅ $IDE gestartet auf Port $port" -ForegroundColor Green
Write-Host " Verzeichnis: $dir" -ForegroundColor Gray
Write-Host " Debug URL: http://localhost:$port" -ForegroundColor Gray
}
catch {
Write-Host "❌ Fehler beim Starten von $IDE: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
}
# Hauptlogik
if ($IDE -eq "menu") {
Show-Menu
}
elseif ($IDE -in @("help", "-h", "--help")) {
Show-Help
}
elseif ([string]::IsNullOrEmpty($IDE)) {
Write-Host "❌ Keine IDE angegeben" -ForegroundColor Red
Write-Host ""
Show-Help
exit 1
}
else {
Start-IDE -IDE $IDE -Slot $Slot
}