Skip to content

Commit

Permalink
Add script to repair broken vscode-powershell.
Browse files Browse the repository at this point in the history
  • Loading branch information
mawosoft committed Nov 4, 2024
1 parent 1926ca1 commit 5c4a0ca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
52 changes: 52 additions & 0 deletions VSCode/repairVscodePowerShell.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 5c4a0ca

Please sign in to comment.