using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'fmerge' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'fmerge' 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) { 'fmerge' { [CompletionResult]::new('-e', '-e', [CompletionResultType]::ParameterName, 'enables experimental features') [CompletionResult]::new('--experimental', '--experimental', [CompletionResultType]::ParameterName, 'enables experimental features') [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') [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.') [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.') [CompletionResult]::new('merge', 'merge', [CompletionResultType]::ParameterValue, 'Merge.') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } 'fmerge;man' { [CompletionResult]::new('-o', '-o', [CompletionResultType]::ParameterName, 'o') [CompletionResult]::new('--out', '--out', [CompletionResultType]::ParameterName, 'out') [CompletionResult]::new('-f', '-f', [CompletionResultType]::ParameterName, 'f') [CompletionResult]::new('--format', '--format', [CompletionResultType]::ParameterName, 'format') [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 } 'fmerge;autocomplete' { [CompletionResult]::new('-o', '-o', [CompletionResultType]::ParameterName, 'o') [CompletionResult]::new('--out', '--out', [CompletionResultType]::ParameterName, 'out') [CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 's') [CompletionResult]::new('--shell', '--shell', [CompletionResultType]::ParameterName, 'shell') [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 } 'fmerge;merge' { [CompletionResult]::new('-f', '-f', [CompletionResultType]::ParameterName, 'f') [CompletionResult]::new('--file', '--file', [CompletionResultType]::ParameterName, 'file') [CompletionResult]::new('-r', '-r', [CompletionResultType]::ParameterName, 'r') [CompletionResult]::new('--regex', '--regex', [CompletionResultType]::ParameterName, 'regex') [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 } 'fmerge;help' { [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.') [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.') [CompletionResult]::new('merge', 'merge', [CompletionResultType]::ParameterValue, 'Merge.') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } 'fmerge;help;man' { break } 'fmerge;help;autocomplete' { break } 'fmerge;help;merge' { break } 'fmerge;help;help' { break } }) $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | Sort-Object -Property ListItemText }