| 1 |
$fn = $($MyInvocation.MyCommand.Name) |
| 2 |
$name = $fn -replace "(.*)\.ps1$", '$1' |
| 3 |
Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { |
| 4 |
param($commandName, $wordToComplete, $cursorPosition) |
| 5 |
$other = "$wordToComplete --generate-shell-completion" |
| 6 |
Invoke-Expression $other | ForEach-Object { |
| 7 |
$parts = $_.Split(':', 2) |
| 8 |
if ($parts.Count -eq 2) { |
| 9 |
$completion = $parts[0].Trim() |
| 10 |
$description = $parts[1].Trim() |
| 11 |
[System.Management.Automation.CompletionResult]::new($completion, $completion, 'ParameterValue', $description) |
| 12 |
} else { |
| 13 |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) |
| 14 |
} |
| 15 |
} |
| 16 |
} |