Created
August 11, 2025 15:24
-
-
Save CypherpunkSamurai/d9cfc1e9410c249f0567c8bbd399692b to your computer and use it in GitHub Desktop.
VSCode Potable Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 5.1 | |
param( | |
[switch]$Cleanup, | |
[string]$DataPath = ".\data", | |
[string]$LogLevel = "info", | |
[switch]$DisableLog | |
) | |
$DataDir = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot $DataPath)) | |
$CodeExe = Join-Path $PSScriptRoot "Code.exe" | |
function Write-Log($Message, $Level = "INFO") { | |
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
Write-Host "[$timestamp] [$Level] $Message" | |
} | |
function New-Dir($Path) { | |
if (-not (Test-Path $Path)) { | |
New-Item -ItemType Directory -Path $Path -Force | Out-Null | |
} | |
} | |
if (-not (Test-Path $CodeExe)) { | |
Write-Log "Code.exe not found" "ERROR" | |
exit 1 | |
} | |
New-Dir $DataDir | |
New-Dir (Join-Path $DataDir "user-data") | |
New-Dir (Join-Path $DataDir "extensions") | |
$env:VSCODE_PORTABLE = $DataDir | |
$Arguments = @( | |
"--user-data-dir" | |
"`"$(Join-Path $DataDir "user-data")`"" | |
"--extensions-dir" | |
"`"$(Join-Path $DataDir "extensions")`"" | |
) | |
if (-not $DisableLog) { | |
New-Dir (Join-Path $DataDir "logs") | |
$Arguments += "--log", $LogLevel | |
} | |
if ($args) { | |
$Arguments += $args | |
} | |
Write-Log "Starting VSCode Portable" | |
try { | |
$Process = Start-Process -FilePath "`"$CodeExe`"" -ArgumentList ($Arguments -join " ") -Wait -PassThru | |
Write-Log "VSCode exited with code: $($Process.ExitCode)" | |
} | |
catch { | |
Write-Log "Error: $($_.Exception.Message)" "ERROR" | |
exit 1 | |
} | |
if ($Cleanup) { | |
Remove-Item (Join-Path $env:TEMP "vscode-*") -Recurse -Force -ErrorAction SilentlyContinue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment