Add powershell completions

This commit is contained in:
Dheepak Krishnamurthy 2021-05-11 11:37:59 -06:00
parent c1d9583b59
commit 17f7d5f58e
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,37 @@
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'taskwarrior-tui' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'taskwarrior-tui'
for ($i = 1; $i -lt $commandElements.Count; $i++) {
$element = $commandElements[$i]
if ($element -isnot [StringConstantExpressionAst] -or
$element.StringConstantType -ne [StringConstantType]::BareWord -or
$element.Value.StartsWith('-')) {
break
}
$element.Value
}) -join ';'
$completions = @(switch ($command) {
'taskwarrior-tui' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Sets a custom config file')
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Sets a custom config file')
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Sets default report')
[CompletionResult]::new('--report', 'report', [CompletionResultType]::ParameterName, 'Sets default report')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
break
}
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}