From bb7b365d379fbcdc4ee67edbe37e5d5a76ef2f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Donk=C3=B3?= Date: Sat, 20 Mar 2021 00:23:28 +0100 Subject: [PATCH] Add sway, swaymsg and swaynag completions for pwsh --- completions/pwsh/sway.ps1 | 26 ++++++++++++++++ completions/pwsh/swaymsg.ps1 | 43 ++++++++++++++++++++++++++ completions/pwsh/swaynag.ps1 | 60 ++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 completions/pwsh/sway.ps1 create mode 100644 completions/pwsh/swaymsg.ps1 create mode 100644 completions/pwsh/swaynag.ps1 diff --git a/completions/pwsh/sway.ps1 b/completions/pwsh/sway.ps1 new file mode 100644 index 000000000..4631272fe --- /dev/null +++ b/completions/pwsh/sway.ps1 @@ -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', $_) + } +} diff --git a/completions/pwsh/swaymsg.ps1 b/completions/pwsh/swaymsg.ps1 new file mode 100644 index 000000000..0e7e7292c --- /dev/null +++ b/completions/pwsh/swaymsg.ps1 @@ -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', $_) + } +} diff --git a/completions/pwsh/swaynag.ps1 b/completions/pwsh/swaynag.ps1 new file mode 100644 index 000000000..a89d2d785 --- /dev/null +++ b/completions/pwsh/swaynag.ps1 @@ -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', $_) + } +}