using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'rev' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'rev' 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) { 'rev' { [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c') [CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'color') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Each file is preceded by a header consisting of the string "==> XXX <==" where "XXX" is the name of the file.') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Each file is preceded by a header consisting of the string "==> XXX <==" where "XXX" is the name of the file.') [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 }