Add sway, swaymsg and swaynag completions for pwsh

This commit is contained in:
István Donkó 2021-03-20 00:23:28 +01:00
parent 6059c744f8
commit bb7b365d37
3 changed files with 129 additions and 0 deletions

26
completions/pwsh/sway.ps1 Normal file
View file

@ -0,0 +1,26 @@
# Based on the following documentation and tons of trial and error:
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/register-argumentcompleter?view=powershell-7.1
Register-ArgumentCompleter -Native -CommandName sway -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$completions = @(
'--help',
'--config',
'--validate',
'--debug',
'--version',
'--verbose',
'--get-socketpath'
)
if ($commandAst.CommandElements.Count -ge 2) {
if ($commandAst.CommandElements[1].ToString() -in @( '-c', '--config' )) {
$completions = Get-ChildItem | Select-Object -ExpandProperty Name
}
}
$completions | Where-Object { $_.StartsWith($wordToComplete) } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}