Last active
November 8, 2022 20:27
-
-
Save rkeithhill/f62534167ee87579541b60f5be03e20a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wingetCompleter = { | |
param($wordToComplete, $commandAst, $cursorPosition) | |
$tokens = $commandAst.Extent.Text.Trim() -split '\s+' | |
$completions = switch ($tokens[1]) { | |
'install' { "-q","-m","-v","-s","-e","-i","-h","-o","-l", | |
"--query","--manifest","--id","--name","--moniker","--version","--source","--exact","--interactive", | |
"--silent","--log","--override","--location","--help"; break } | |
'search' { "-q","-s","-n","-e","-?", | |
"--query","--id","--name","--moniker","--tag","--command","--source","--count","--exact","--help" | |
break } | |
'show' { "-q","-m","-v","-s","-e","-?", | |
"--query","--manifest","--id","--name","--moniker","--version","--source","--exact","--versions","--help" | |
break } | |
'source' { $srcCommands = "add","list","update","remove","reset" | |
if (($tokens.Count -ge 3) -and ($srcCommands -contains $tokens[2])) { | |
switch -regex ($tokens[2]) { | |
'add' { "-n","-a","-t","-?","--name","--arg","--type","--help"; break } | |
'list|update|remove' { "-n",,"-?","--name","--force","--help"; break } | |
'reset' { "-n",,"-?","--name","--help"; break } | |
} | |
} | |
else { | |
$srcCommands + @("-?","--help") | |
} | |
break | |
} | |
'hash' { "-f","-m","-?","--file","--msix","--help"; break } | |
'validate' { "-?","--manifest","--help"; break } | |
default { "install","show","source","search","hash","validate","-v","--help","--info","--version" } | |
} | |
$completions | Where-Object {$_ -like "${wordToComplete}*"} | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
Register-ArgumentCompleter -CommandName winget -Native -ScriptBlock $wingetCompleter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please consider upvoting this
winget-cli
issue: microsoft/winget-cli#331