Skip to content

Commit 3cd8f2e

Browse files
committed
[pwsh keymap] Add expandVSCodeDefaultKeyBindingsInfo.ps1
1 parent 2cc98b1 commit 3cd8f2e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
<#
4+
.SYNOPSIS
5+
Expands the VSCode default keybindings with infos about keybindings not sent to the shell.
6+
#>
7+
8+
using namespace System
9+
using namespace System.Collections.Generic
10+
11+
[CmdletBinding()]
12+
param(
13+
# Path to VSCode default keybindings JSON file.
14+
[Parameter(Mandatory)]
15+
[ValidateNotNullOrEmpty()]
16+
[string]$DefaultKeyBindingPath,
17+
18+
# Path to VSCode default settings JSON file.
19+
[Parameter(Mandatory)]
20+
[ValidateNotNullOrEmpty()]
21+
[string]$DefaultSettingsPath,
22+
23+
# Path to destination JSON file.
24+
[Parameter(Mandatory)]
25+
[ValidateNotNullOrEmpty()]
26+
[string]$Destination,
27+
[switch]$Force
28+
)
29+
30+
$keybindings = Get-Content $DefaultKeyBindingPath -Raw | ConvertFrom-Json
31+
[Queue[string]]$settings = Get-Content $DefaultSettingsPath
32+
[HashSet[string]]$defaultSkippedCommands = @{}
33+
34+
while ($settings.Count -gt 0 -and
35+
-not $settings.Dequeue().Contains(
36+
'Default Skipped Commands:',
37+
[StringComparison]::OrdinalIgnoreCase)) {
38+
<# do nothing #>
39+
}
40+
41+
while ($settings.Count -gt 0) {
42+
[string]$line = $settings.Dequeue().Trim()
43+
if ($line.Length -eq 0) { continue }
44+
if (-not $line.StartsWith('//')) { break }
45+
$line = $line.Trim("/- `t")
46+
if ($line.Length -gt 0) {
47+
$null = $defaultSkippedCommands.Add($line)
48+
}
49+
}
50+
51+
foreach ($binding in $keybindings) {
52+
if ($defaultSkippedCommands.Contains($binding.command)) {
53+
$binding.psobject.Properties.Add([psnoteproperty]::new('skipShell', $true))
54+
}
55+
}
56+
57+
$keyBindings | ConvertTo-Json | New-Item -Path $Destination -Force:$Force

0 commit comments

Comments
 (0)