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', $_)
}
}

View file

@ -0,0 +1,43 @@
# 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 swaymsg -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$completions = @(
'--help',
'--monitor',
'--pretty',
'--quiet',
'--raw',
'--socket',
'--type',
'--version'
)
if ($commandAst.CommandElements.Count -ge 2) {
if ($commandAst.CommandElements[1].ToString() -in @( '-t', '--type' )) {
$completions = @(
'get_workspaces',
'get_inputs',
'get_outputs',
'get_tree',
'get_marks',
'get_bar_config',
'get_version',
'get_binding_modes',
'get_binding_state',
'get_config',
'get_seats',
'send_tick',
'subscribe'
)
} elseif ($commandAst.CommandElements[1].ToString() -in @( '-s', '--socket' )) {
$completions = Get-ChildItem -Path '/run/user/*/sway-ipc*' | Select-Object -ExpandProperty FullName
}
}
$completions | Where-Object { $_.StartsWith($wordToComplete) } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}

View file

@ -0,0 +1,60 @@
# 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 swaynag -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$completions = @(
'--button',
'--button-no-terminal',
'--button-dismiss',
'--button-dismiss-no-terminal',
'--config',
'--debug',
'--edge',
'--font',
'--help',
'--detailed-message',
'--detailed-button',
'--message',
'--output',
'--dismiss-button',
'--type',
'--version',
# Appearance
'--background',
'--border',
'--border-bottom',
'--button-background',
'--text',
'--border-bottom-size',
'--message-padding',
'--details-border-size',
'--button-border-size',
'--button-gap',
'--button-dismiss-gap',
'--button-margin-right',
'--button-padding'
)
if ($commandAst.CommandElements.Count -ge 2) {
if ($commandAst.CommandElements[1].ToString() -in @( '-c', '--config' )) {
$completions = Get-ChildItem | Select-Object -ExpandProperty Name
} elseif ($commandAst.CommandElements[1].ToString() -in @( '-e', '--edge' )) {
$completions = @(
'top',
'bottom'
)
} elseif ($commandAst.CommandElements[1].ToString() -in @( '-t', '--type' )) {
$completions = @(
'error',
'warning'
)
}
}
$completions | Where-Object { $_.StartsWith($wordToComplete) } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}