Skip to content

Instantly share code, notes, and snippets.

@patriksvensson
Created October 10, 2018 22:57
Show Gist options
  • Save patriksvensson/e47cf103ccc9542939fc05a739211a38 to your computer and use it in GitHub Desktop.
Save patriksvensson/e47cf103ccc9542939fc05a739211a38 to your computer and use it in GitHub Desktop.
Argument completer for Spectre.Cli
Register-ArgumentCompleter -Native -CommandName myapp -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$split = $wordToComplete.ToString().Split()
$command = [system.String]::Join("_", $split[1..$split.Length])
$position = ($cursorPosition-$split[0].Length - 1);
myapp complete --position $position "$command" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment