using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'base32' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'base32' 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) { 'base32' { [CompletionResult]::new('-w', 'w', [CompletionResultType]::ParameterName, 'Wrap encoded lines after n characters') [CompletionResult]::new('--wrap', 'wrap', [CompletionResultType]::ParameterName, 'Wrap encoded lines after n characters') [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c') [CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'color') [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Decode rather than encode') [CompletionResult]::new('--decode', 'decode', [CompletionResultType]::ParameterName, 'Decode rather than encode') [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Ignore whitespace when decoding') [CompletionResult]::new('--ignore-space', 'ignore-space', [CompletionResultType]::ParameterName, 'Ignore whitespace when decoding') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'output a diagnostic for every file processed') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'output a diagnostic for every file processed') [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Do not display header, even with multiple files') [CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Do not display header, even with multiple files') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') break } }) $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | Sort-Object -Property ListItemText }