|
| 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