shitbox/pkg/usr/share/pwsh/completions/_b2sum.ps1

39 lines
2.0 KiB
PowerShell

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'b2sum' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'b2sum'
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('-') -or
$element.Value -eq $wordToComplete) {
break
}
$element.Value
}) -join ';'
$completions = @(switch ($command) {
'b2sum' {
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'digest length in bits; must not exceed the max for the blake2 algorithm and must be a multiple of 8')
[CompletionResult]::new('--length', 'length', [CompletionResultType]::ParameterName, 'digest length in bits; must not exceed the max for the blake2 algorithm and must be a multiple of 8')
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'read checksums from the FILEs and check them')
[CompletionResult]::new('--check', 'check', [CompletionResultType]::ParameterName, 'read checksums from the FILEs and check them')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}