using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'mktemp' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'mktemp' 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) { 'mktemp' { [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'specify the directory to create temporary files in') [CompletionResult]::new('--tmpdir', 'tmpdir', [CompletionResultType]::ParameterName, 'specify the directory to create temporary files in') [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'specify a prefix to append to the created files') [CompletionResult]::new('--template', 'template', [CompletionResultType]::ParameterName, 'specify a prefix to append to the created files') [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'create a directory instead of a file') [CompletionResult]::new('--directory', 'directory', [CompletionResultType]::ParameterName, 'create a directory instead of a file') [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'immediately remove created files and directories') [CompletionResult]::new('--dryrun', 'dryrun', [CompletionResultType]::ParameterName, 'immediately remove created files and directories') [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 }