|
| 1 | +# Copyright (c) 2024 Matthias Wolf, Mawosoft. |
| 2 | + |
| 3 | +<# |
| 4 | +.SYNOPSIS |
| 5 | + Repairs shell integration for vscode-powershell. |
| 6 | +.DESCRIPTION |
| 7 | + Repairs shell integration for vscode-powershell <= v2024.2.2 by creating a folder and a symlink. |
| 8 | + Needs to be run again after any update of VSCode >= 1.94. |
| 9 | + Requires admin rights. Runs on any PowerShell version or supported OS platform. |
| 10 | +.NOTES |
| 11 | + VSCode 1.94++ moved the shell integration scripts to a different folder. |
| 12 | + As a result, the PowerShell Extension doesn't initialize correctly. |
| 13 | + This seems to be fixed in v2024.5.0-preview. |
| 14 | +#> |
| 15 | + |
| 16 | +#Requires -Version 5.1 |
| 17 | + |
| 18 | +[CmdletBinding()] |
| 19 | +param( |
| 20 | + # Path to VS Code if not on Windows or not default. |
| 21 | + [string]$VscodePath |
| 22 | +) |
| 23 | + |
| 24 | +if (-not $VscodePath -and ($PSVersionTable.PSVersion.Major -lt 6 -or $IsWindows)) { |
| 25 | + $VscodePath = Join-Path $env:ProgramFiles 'Microsoft VS Code' |
| 26 | +} |
| 27 | +if (-not (Test-Path -LiteralPath $VscodePath -PathType Container)) { |
| 28 | + throw 'Please specify VS Code install location with -VscodePath' |
| 29 | +} |
| 30 | + |
| 31 | +$terminalPath = Join-Path $VscodePath 'resources/app/out/vs/workbench/contrib/terminal' |
| 32 | +$scriptsPath = Join-Path $terminalPath 'common/scripts' |
| 33 | +if (-not (Test-Path -LiteralPath $scriptsPath -PathType Container)) { |
| 34 | + throw "Directory not found: $scriptsPath" |
| 35 | +} |
| 36 | +$browserPath = Join-Path $terminalPath 'browser' |
| 37 | +if (-not (Test-Path -LiteralPath $browserPath -PathType Container)) { |
| 38 | + New-Item -ItemType Directory -Path $browserPath |
| 39 | +} |
| 40 | +$media = Join-Path '.' 'media' |
| 41 | +if (-not (Test-Path -LiteralPath (Join-Path $browserPath $media) -PathType Container)) { |
| 42 | + # PowerShell has an issue with relative targets. |
| 43 | + Push-Location -LiteralPath $browserPath |
| 44 | + try { |
| 45 | + $target = Resolve-Path -LiteralPath $scriptsPath -Relative |
| 46 | + $target = Join-Path '.' $target |
| 47 | + New-Item -ItemType SymbolicLink -Path $media -Target $target |
| 48 | + } |
| 49 | + finally { |
| 50 | + Pop-Location |
| 51 | + } |
| 52 | +} |
0 commit comments