Skip to content

Commit 5c4a0ca

Browse files
committed
Add script to repair broken vscode-powershell.
See PowerShell/vscode-powershell#5047
1 parent 1926ca1 commit 5c4a0ca

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ Miscellaneous scripts.
1616
- **VirtualBox**\
1717
Batch scripts to automatically take a snapshot before starting a VM and verify snapshot creation inside the VM.
1818

19-
- **VSCode**\
20-
Merge selected VSCode logs and sort by log entry timestamps.
19+
- **VSCode**
20+
21+
- **mergeVscodeLogs.ps1**\
22+
Merge selected VSCode logs and sort by log entry timestamps.
23+
24+
- **repairVscodePowerShell.ps1**\
25+
Repair broken *vscode-powershell* shell integration.

VSCode/repairVscodePowerShell.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)