Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Created January 6, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcnabb/5e4765779fa17c97ed79eefde8f3755d to your computer and use it in GitHub Desktop.
Save mattmcnabb/5e4765779fa17c97ed79eefde8f3755d to your computer and use it in GitHub Desktop.
Tab completion with argument completers
# set up a test command
function Test-MyCompleter {
param
(
[string[]]
$Param1
)
}
# register the completer
$ScriptBlock = {
$List = 'aaaaaa','bbbbbb','cccccc'
foreach ($Item in $List)
{
New-CompletionResult -CompletionText $Item -ToolTip $Item -ListItemText $Item -CompletionResultType ParameterValue
}
}
TabExpansionPlusPlus\Register-ArgumentCompleter -CommandName Test-MyCompleter -ParameterName Param1 -ScriptBlock $ScriptBlock
# when I type this and press tab, completion should only offer 'bbbbbb'
Test-MyCompleter -Param1 b <TAB>
# however, it tab-completes through the list at the first index and I get
Test-MyCompleter -Param1 aaaaaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment