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