From 5c4a0caa075d067fb9aaed135789be04f41c7da9 Mon Sep 17 00:00:00 2001 From: mawosoft <78562192+mawosoft@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:52:05 +0100 Subject: [PATCH] Add script to repair broken vscode-powershell. See https://github.com/PowerShell/vscode-powershell/pull/5047 --- README.md | 9 ++++-- VSCode/repairVscodePowerShell.ps1 | 52 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 VSCode/repairVscodePowerShell.ps1 diff --git a/README.md b/README.md index aef08c6..5e21e21 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,10 @@ Miscellaneous scripts. - **VirtualBox**\ Batch scripts to automatically take a snapshot before starting a VM and verify snapshot creation inside the VM. -- **VSCode**\ - Merge selected VSCode logs and sort by log entry timestamps. +- **VSCode** + + - **mergeVscodeLogs.ps1**\ + Merge selected VSCode logs and sort by log entry timestamps. + + - **repairVscodePowerShell.ps1**\ + Repair broken *vscode-powershell* shell integration. diff --git a/VSCode/repairVscodePowerShell.ps1 b/VSCode/repairVscodePowerShell.ps1 new file mode 100644 index 0000000..1c681b3 --- /dev/null +++ b/VSCode/repairVscodePowerShell.ps1 @@ -0,0 +1,52 @@ +# Copyright (c) 2024 Matthias Wolf, Mawosoft. + +<# +.SYNOPSIS + Repairs shell integration for vscode-powershell. +.DESCRIPTION + Repairs shell integration for vscode-powershell <= v2024.2.2 by creating a folder and a symlink. + Needs to be run again after any update of VSCode >= 1.94. + Requires admin rights. Runs on any PowerShell version or supported OS platform. +.NOTES + VSCode 1.94++ moved the shell integration scripts to a different folder. + As a result, the PowerShell Extension doesn't initialize correctly. + This seems to be fixed in v2024.5.0-preview. +#> + +#Requires -Version 5.1 + +[CmdletBinding()] +param( + # Path to VS Code if not on Windows or not default. + [string]$VscodePath +) + +if (-not $VscodePath -and ($PSVersionTable.PSVersion.Major -lt 6 -or $IsWindows)) { + $VscodePath = Join-Path $env:ProgramFiles 'Microsoft VS Code' +} +if (-not (Test-Path -LiteralPath $VscodePath -PathType Container)) { + throw 'Please specify VS Code install location with -VscodePath' +} + +$terminalPath = Join-Path $VscodePath 'resources/app/out/vs/workbench/contrib/terminal' +$scriptsPath = Join-Path $terminalPath 'common/scripts' +if (-not (Test-Path -LiteralPath $scriptsPath -PathType Container)) { + throw "Directory not found: $scriptsPath" +} +$browserPath = Join-Path $terminalPath 'browser' +if (-not (Test-Path -LiteralPath $browserPath -PathType Container)) { + New-Item -ItemType Directory -Path $browserPath +} +$media = Join-Path '.' 'media' +if (-not (Test-Path -LiteralPath (Join-Path $browserPath $media) -PathType Container)) { + # PowerShell has an issue with relative targets. + Push-Location -LiteralPath $browserPath + try { + $target = Resolve-Path -LiteralPath $scriptsPath -Relative + $target = Join-Path '.' $target + New-Item -ItemType SymbolicLink -Path $media -Target $target + } + finally { + Pop-Location + } +}