setup-vscode-windows.ps1
· 7.5 KiB · PowerShell
Eredeti
# ===================================================================
# PROFESSIONAL VS CODE + PYTHON + GIT + DOCKER SETUP FOR WINDOWS 11
# Run as Administrator | UTF-8 without BOM
# ===================================================================
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "ERROR: Run as Administrator!" -ForegroundColor Red
pause
exit 1
}
Write-Host "`nStarting professional dev environment setup..." -ForegroundColor Green
# --- 1. Ensure winget is available (Robust) ---
function Install-Winget {
if (Get-Command winget -ErrorAction SilentlyContinue) { return $true }
Write-Host "winget not found. Installing App Installer..." -ForegroundColor Cyan
try {
# Try Microsoft Store (modern)
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
if (Get-Command winget -ErrorAction SilentlyContinue) { return $true }
} catch {}
# Fallback: Download .msixbundle from GitHub
Write-Host "Downloading App Installer from GitHub..." -ForegroundColor Yellow
$url = "https://aka.ms/getwinget"
$out = "$env:TEMP\winget.msixbundle"
Invoke-WebRequest -Uri $url -OutFile $out -UseBasicParsing
Add-AppxPackage -Path $out -ErrorAction SilentlyContinue
Remove-Item $out -Force
Start-Sleep -Seconds 5
return (Get-Command winget -ErrorAction SilentlyContinue)
}
if (-not (Install-Winget)) {
Write-Host "FAILED to install winget. Install manually: https://aka.ms/getwinget" -ForegroundColor Red
pause
exit 1
}
# --- 2. Install VS Code ---
Write-Host "`nInstalling VS Code..." -ForegroundColor Cyan
if (-not (Get-Command code -ErrorAction SilentlyContinue)) {
winget install -e --id Microsoft.VisualStudioCode --source winget --silent --accept-package-agreements --accept-source-agreements
Start-Sleep -Seconds 10 # Wait for PATH update
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User")
}
if (Get-Command code -ErrorAction SilentlyContinue) {
Write-Host "VS Code ready." -ForegroundColor Green
} else {
Write-Host "VS Code install failed." -ForegroundColor Red
pause
exit 1
}
# --- 3. Install Python + pip upgrade ---
Write-Host "`nInstalling Python 3.12..." -ForegroundColor Cyan
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
winget install -e --id Python.Python.3.12 --source winget --silent
Start-Sleep -Seconds 10
}
if (Get-Command python -ErrorAction SilentlyContinue) {
Write-Host "Upgrading pip..." -ForegroundColor Cyan
python -m pip install --upgrade pip --quiet
Write-Host "Python ready." -ForegroundColor Green
}
# --- 4. Install Git ---
Write-Host "`nInstalling Git..." -ForegroundColor Cyan
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
winget install -e --id Git.Git --source winget --silent
}
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Host "Git ready." -ForegroundColor Green
}
# --- 5. Install Docker Desktop ---
Write-Host "`nInstalling Docker Desktop..." -ForegroundColor Cyan
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
winget install -e --id Docker.DockerDesktop --source winget --silent --accept-package-agreements
Write-Host "Docker installed. Restart may be required." -ForegroundColor Yellow
}
# --- 6. Safe settings.json merge ---
$settingsPath = "$env:APPDATA\Code\User\settings.json"
$settingsDir = Split-Path $settingsPath -Parent
if (-not (Test-Path $settingsDir)) { New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null }
$defaultSettings = @{
"editor.fontSize" = 14
"editor.tabSize" = 4
"editor.insertSpaces" = $true
"files.autoSave" = "afterDelay"
"files.autoSaveDelay" = 1000
"workbench.colorTheme" = "Default Dark+"
"terminal.integrated.defaultProfile.windows" = "PowerShell"
"python.defaultInterpreterPath" = "python"
"python.terminal.activateEnvironment" = $true
"git.autofetch" = $true
"git.confirmSync" = $false
"extensions.autoUpdate" = $true
"telemetry.telemetryLevel" = "off"
"workbench preferred language" = "bg" # Bulgarian
}
# Load existing or create new
if (Test-Path $settingsPath) {
try {
$current = Get-Content $settingsPath -Raw | ConvertFrom-Json -ErrorAction Stop
if ($current -isnot [PSCustomObject]) { $current = [PSCustomObject]@{} }
} catch {
Write-Host "Invalid settings.json - backing up and replacing..." -ForegroundColor Yellow
Copy-Item $settingsPath "$settingsPath.bak" -Force
$current = [PSCustomObject]@{}
}
} else {
$current = [PSCustomObject]@{}
}
# Merge settings
foreach ($key in $defaultSettings.Keys) {
if (-not ($current.PSObject.Properties.Name -contains $key)) {
Add-Member -InputObject $current -NotePropertyName $key -NotePropertyValue $defaultSettings[$key]
} else {
$current.$key = $defaultSettings[$key]
}
}
$json = $current | ConvertTo-Json -Depth 10
[System.IO.File]::WriteAllText($settingsPath, $json, [System.Text.Encoding]::UTF8)
Write-Host "settings.json updated safely!" -ForegroundColor Green
# --- 7. Install Extensions ---
Write-Host "`nInstalling VS Code extensions..." -ForegroundColor Cyan
$extensions = @(
"ms-python.python"
"ms-python.vscode-pylance"
"ms-toolsai.jupyter"
"eamodio.gitlens"
"GitHub.copilot"
"ms-vscode.bulgarian-language-pack"
"streetsidesoftware.code-spell-checker"
"esbenp.prettier-vscode"
"ms-vscode-remote.remote-wsl"
"ms-azuretools.vscode-docker"
)
foreach ($ext in $extensions) {
if (-not (code --list-extensions | Where-Object { $_ -eq $ext })) {
Write-Host " Installing: $ext"
code --install-extension $ext --force | Out-Null
} else {
Write-Host " Already: $ext" -ForegroundColor DarkGray
}
}
# --- 8. Activate Bulgarian Language ---
Write-Host "`nActivating Bulgarian interface..." -ForegroundColor Cyan
$localePath = "$env:APPDATA\Code\User\locale.json"
$localeDir = Split-Path $localePath -Parent
if (-not (Test-Path $localeDir)) { New-Item -ItemType Directory -Path $localeDir -Force | Out-Null }
'{"locale":"bg"}' | Out-File -FilePath $localePath -Encoding UTF8 -Force
Write-Host "Bulgarian language activated! Restart VS Code." -ForegroundColor Green
# --- 9. WSL2 Check ---
Write-Host "`nChecking WSL2..." -ForegroundColor Cyan
if (Get-Command wsl -ErrorAction SilentlyContinue) {
$distros = wsl --list --quiet | Where-Object { $_ -and $_.Trim() }
if ($distros) {
Write-Host "WSL2 active: $distros" -ForegroundColor Green
} else {
$ans = Read-Host "Install Ubuntu in WSL2? (y/n)"
if ($ans -match "^[Yy]") {
wsl --install -d Ubuntu
Write-Host "Restart required after install!" -ForegroundColor Yellow
}
}
} else {
$ans = Read-Host "Enable WSL2? (y/n)"
if ($ans -match "^[Yy]") {
wsl --install
Write-Host "Restart required!" -ForegroundColor Yellow
}
}
# --- Final ---
Write-Host "`nSETUP COMPLETE!" -ForegroundColor Green
Write-Host " VS Code: code ." -ForegroundColor Cyan
Write-Host " Python: python --version" -ForegroundColor Cyan
Write-Host " Docker: docker --version" -ForegroundColor Cyan
Write-Host " Restart VS Code to see Bulgarian UI!" -ForegroundColor Magenta
Write-Host "`nTip: Restart PC if Docker/WSL/Python was installed.`n"
pause
| 1 | # =================================================================== |
| 2 | # PROFESSIONAL VS CODE + PYTHON + GIT + DOCKER SETUP FOR WINDOWS 11 |
| 3 | # Run as Administrator | UTF-8 without BOM |
| 4 | # =================================================================== |
| 5 | |
| 6 | $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 7 | if (-not $isAdmin) { |
| 8 | Write-Host "ERROR: Run as Administrator!" -ForegroundColor Red |
| 9 | pause |
| 10 | exit 1 |
| 11 | } |
| 12 | |
| 13 | Write-Host "`nStarting professional dev environment setup..." -ForegroundColor Green |
| 14 | |
| 15 | # --- 1. Ensure winget is available (Robust) --- |
| 16 | function Install-Winget { |
| 17 | if (Get-Command winget -ErrorAction SilentlyContinue) { return $true } |
| 18 | |
| 19 | Write-Host "winget not found. Installing App Installer..." -ForegroundColor Cyan |
| 20 | try { |
| 21 | # Try Microsoft Store (modern) |
| 22 | Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe -ErrorAction SilentlyContinue |
| 23 | Start-Sleep -Seconds 3 |
| 24 | if (Get-Command winget -ErrorAction SilentlyContinue) { return $true } |
| 25 | } catch {} |
| 26 | |
| 27 | # Fallback: Download .msixbundle from GitHub |
| 28 | Write-Host "Downloading App Installer from GitHub..." -ForegroundColor Yellow |
| 29 | $url = "https://aka.ms/getwinget" |
| 30 | $out = "$env:TEMP\winget.msixbundle" |
| 31 | Invoke-WebRequest -Uri $url -OutFile $out -UseBasicParsing |
| 32 | Add-AppxPackage -Path $out -ErrorAction SilentlyContinue |
| 33 | Remove-Item $out -Force |
| 34 | Start-Sleep -Seconds 5 |
| 35 | return (Get-Command winget -ErrorAction SilentlyContinue) |
| 36 | } |
| 37 | |
| 38 | if (-not (Install-Winget)) { |
| 39 | Write-Host "FAILED to install winget. Install manually: https://aka.ms/getwinget" -ForegroundColor Red |
| 40 | pause |
| 41 | exit 1 |
| 42 | } |
| 43 | |
| 44 | # --- 2. Install VS Code --- |
| 45 | Write-Host "`nInstalling VS Code..." -ForegroundColor Cyan |
| 46 | if (-not (Get-Command code -ErrorAction SilentlyContinue)) { |
| 47 | winget install -e --id Microsoft.VisualStudioCode --source winget --silent --accept-package-agreements --accept-source-agreements |
| 48 | Start-Sleep -Seconds 10 # Wait for PATH update |
| 49 | $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User") |
| 50 | } |
| 51 | if (Get-Command code -ErrorAction SilentlyContinue) { |
| 52 | Write-Host "VS Code ready." -ForegroundColor Green |
| 53 | } else { |
| 54 | Write-Host "VS Code install failed." -ForegroundColor Red |
| 55 | pause |
| 56 | exit 1 |
| 57 | } |
| 58 | |
| 59 | # --- 3. Install Python + pip upgrade --- |
| 60 | Write-Host "`nInstalling Python 3.12..." -ForegroundColor Cyan |
| 61 | if (-not (Get-Command python -ErrorAction SilentlyContinue)) { |
| 62 | winget install -e --id Python.Python.3.12 --source winget --silent |
| 63 | Start-Sleep -Seconds 10 |
| 64 | } |
| 65 | if (Get-Command python -ErrorAction SilentlyContinue) { |
| 66 | Write-Host "Upgrading pip..." -ForegroundColor Cyan |
| 67 | python -m pip install --upgrade pip --quiet |
| 68 | Write-Host "Python ready." -ForegroundColor Green |
| 69 | } |
| 70 | |
| 71 | # --- 4. Install Git --- |
| 72 | Write-Host "`nInstalling Git..." -ForegroundColor Cyan |
| 73 | if (-not (Get-Command git -ErrorAction SilentlyContinue)) { |
| 74 | winget install -e --id Git.Git --source winget --silent |
| 75 | } |
| 76 | if (Get-Command git -ErrorAction SilentlyContinue) { |
| 77 | Write-Host "Git ready." -ForegroundColor Green |
| 78 | } |
| 79 | |
| 80 | # --- 5. Install Docker Desktop --- |
| 81 | Write-Host "`nInstalling Docker Desktop..." -ForegroundColor Cyan |
| 82 | if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { |
| 83 | winget install -e --id Docker.DockerDesktop --source winget --silent --accept-package-agreements |
| 84 | Write-Host "Docker installed. Restart may be required." -ForegroundColor Yellow |
| 85 | } |
| 86 | |
| 87 | # --- 6. Safe settings.json merge --- |
| 88 | $settingsPath = "$env:APPDATA\Code\User\settings.json" |
| 89 | $settingsDir = Split-Path $settingsPath -Parent |
| 90 | if (-not (Test-Path $settingsDir)) { New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null } |
| 91 | |
| 92 | $defaultSettings = @{ |
| 93 | "editor.fontSize" = 14 |
| 94 | "editor.tabSize" = 4 |
| 95 | "editor.insertSpaces" = $true |
| 96 | "files.autoSave" = "afterDelay" |
| 97 | "files.autoSaveDelay" = 1000 |
| 98 | "workbench.colorTheme" = "Default Dark+" |
| 99 | "terminal.integrated.defaultProfile.windows" = "PowerShell" |
| 100 | "python.defaultInterpreterPath" = "python" |
| 101 | "python.terminal.activateEnvironment" = $true |
| 102 | "git.autofetch" = $true |
| 103 | "git.confirmSync" = $false |
| 104 | "extensions.autoUpdate" = $true |
| 105 | "telemetry.telemetryLevel" = "off" |
| 106 | "workbench preferred language" = "bg" # Bulgarian |
| 107 | } |
| 108 | |
| 109 | # Load existing or create new |
| 110 | if (Test-Path $settingsPath) { |
| 111 | try { |
| 112 | $current = Get-Content $settingsPath -Raw | ConvertFrom-Json -ErrorAction Stop |
| 113 | if ($current -isnot [PSCustomObject]) { $current = [PSCustomObject]@{} } |
| 114 | } catch { |
| 115 | Write-Host "Invalid settings.json - backing up and replacing..." -ForegroundColor Yellow |
| 116 | Copy-Item $settingsPath "$settingsPath.bak" -Force |
| 117 | $current = [PSCustomObject]@{} |
| 118 | } |
| 119 | } else { |
| 120 | $current = [PSCustomObject]@{} |
| 121 | } |
| 122 | |
| 123 | # Merge settings |
| 124 | foreach ($key in $defaultSettings.Keys) { |
| 125 | if (-not ($current.PSObject.Properties.Name -contains $key)) { |
| 126 | Add-Member -InputObject $current -NotePropertyName $key -NotePropertyValue $defaultSettings[$key] |
| 127 | } else { |
| 128 | $current.$key = $defaultSettings[$key] |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | $json = $current | ConvertTo-Json -Depth 10 |
| 133 | [System.IO.File]::WriteAllText($settingsPath, $json, [System.Text.Encoding]::UTF8) |
| 134 | Write-Host "settings.json updated safely!" -ForegroundColor Green |
| 135 | |
| 136 | # --- 7. Install Extensions --- |
| 137 | Write-Host "`nInstalling VS Code extensions..." -ForegroundColor Cyan |
| 138 | $extensions = @( |
| 139 | "ms-python.python" |
| 140 | "ms-python.vscode-pylance" |
| 141 | "ms-toolsai.jupyter" |
| 142 | "eamodio.gitlens" |
| 143 | "GitHub.copilot" |
| 144 | "ms-vscode.bulgarian-language-pack" |
| 145 | "streetsidesoftware.code-spell-checker" |
| 146 | "esbenp.prettier-vscode" |
| 147 | "ms-vscode-remote.remote-wsl" |
| 148 | "ms-azuretools.vscode-docker" |
| 149 | ) |
| 150 | |
| 151 | foreach ($ext in $extensions) { |
| 152 | if (-not (code --list-extensions | Where-Object { $_ -eq $ext })) { |
| 153 | Write-Host " Installing: $ext" |
| 154 | code --install-extension $ext --force | Out-Null |
| 155 | } else { |
| 156 | Write-Host " Already: $ext" -ForegroundColor DarkGray |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | # --- 8. Activate Bulgarian Language --- |
| 161 | Write-Host "`nActivating Bulgarian interface..." -ForegroundColor Cyan |
| 162 | $localePath = "$env:APPDATA\Code\User\locale.json" |
| 163 | $localeDir = Split-Path $localePath -Parent |
| 164 | if (-not (Test-Path $localeDir)) { New-Item -ItemType Directory -Path $localeDir -Force | Out-Null } |
| 165 | '{"locale":"bg"}' | Out-File -FilePath $localePath -Encoding UTF8 -Force |
| 166 | Write-Host "Bulgarian language activated! Restart VS Code." -ForegroundColor Green |
| 167 | |
| 168 | # --- 9. WSL2 Check --- |
| 169 | Write-Host "`nChecking WSL2..." -ForegroundColor Cyan |
| 170 | if (Get-Command wsl -ErrorAction SilentlyContinue) { |
| 171 | $distros = wsl --list --quiet | Where-Object { $_ -and $_.Trim() } |
| 172 | if ($distros) { |
| 173 | Write-Host "WSL2 active: $distros" -ForegroundColor Green |
| 174 | } else { |
| 175 | $ans = Read-Host "Install Ubuntu in WSL2? (y/n)" |
| 176 | if ($ans -match "^[Yy]") { |
| 177 | wsl --install -d Ubuntu |
| 178 | Write-Host "Restart required after install!" -ForegroundColor Yellow |
| 179 | } |
| 180 | } |
| 181 | } else { |
| 182 | $ans = Read-Host "Enable WSL2? (y/n)" |
| 183 | if ($ans -match "^[Yy]") { |
| 184 | wsl --install |
| 185 | Write-Host "Restart required!" -ForegroundColor Yellow |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | # --- Final --- |
| 190 | Write-Host "`nSETUP COMPLETE!" -ForegroundColor Green |
| 191 | Write-Host " VS Code: code ." -ForegroundColor Cyan |
| 192 | Write-Host " Python: python --version" -ForegroundColor Cyan |
| 193 | Write-Host " Docker: docker --version" -ForegroundColor Cyan |
| 194 | Write-Host " Restart VS Code to see Bulgarian UI!" -ForegroundColor Magenta |
| 195 | Write-Host "`nTip: Restart PC if Docker/WSL/Python was installed.`n" |
| 196 | |
| 197 | pause |