Skip to content

Instantly share code, notes, and snippets.

@rwilkes
Created February 12, 2022 02:09
Show Gist options
  • Save rwilkes/c5fd617dccb90f3dce673bf405acbb87 to your computer and use it in GitHub Desktop.
Save rwilkes/c5fd617dccb90f3dce673bf405acbb87 to your computer and use it in GitHub Desktop.
Register-ArgumentCompleter
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
@rwilkes
Copy link
Author

rwilkes commented Feb 12, 2022

Register-ArgumentCompleter

PowerShell function to for winget tab completion. Source and Examples taken from the official repository doc.

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