Skip to content

Instantly share code, notes, and snippets.

@rkeithhill
Last active November 8, 2022 20:27
Show Gist options
  • Save rkeithhill/f62534167ee87579541b60f5be03e20a to your computer and use it in GitHub Desktop.
Save rkeithhill/f62534167ee87579541b60f5be03e20a to your computer and use it in GitHub Desktop.
$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
@rkeithhill
Copy link
Author

Please consider upvoting this winget-cli issue: microsoft/winget-cli#331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment