using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'ln' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'ln' 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) { 'ln' { [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'remove existing destination files') [CompletionResult]::new('--force', 'force', [CompletionResultType]::ParameterName, 'remove existing destination files') [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'make symbolic links instead of hard links') [CompletionResult]::new('--symbolic', 'symbolic', [CompletionResultType]::ParameterName, 'make symbolic links instead of hard links') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'print name of each linked file') [CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'print name of each linked file') [CompletionResult]::new('-L', 'L', [CompletionResultType]::ParameterName, 'For each source_file operand that names a file of type symbolic link, create a (hard) link to the file referenced by the symbolic link.') [CompletionResult]::new('-P', 'P', [CompletionResultType]::ParameterName, 'For each source_file operand that names a file of type symbolic link, create a (hard) link to the symbolic link itself.') [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 }