Skip to main content
WinGet offers a complete command that provides context-sensitive tab completion for your shell. It enables completion of command names, argument names, and argument values based on the current command line state.
This feature was released in v0.1.42241 Preview. Update to this version or later to use completion.

How Tab Completion Works

Tab completion cycles through possible values as you press the Tab key repeatedly. Here’s what you can complete:
  • Command names - Complete main commands like install, search, show
  • Argument names - Complete flags and options like --version, --source
  • Argument values - Complete package names, versions, and other contextual values

Completion Examples

These examples assume tab completion works similar to PowerShell, where repeated Tab presses cycle through possible values.
InputResultReason
winget ⇥winget installinstall is the first command below the root
winget sh⇥winget showshow is the first command that starts with sh
winget source l⇥winget source listlist is the first sub-command of source that starts with l
winget -⇥winget --version--version is the first argument defined for the root
winget install power⇥winget install "Power Toys""Power Toys" is the first package whose Id, Name, or Moniker starts with power
winget install "Power Toys" --version ⇥winget install "Power Toys" --version 0.19.20.19.2 is the highest version of Power Toys

PowerShell Setup

1

Open Your PowerShell Profile

Check if your profile exists:
Test-Path $PROFILE
If it returns False, create it:
New-Item -Path $PROFILE -Type File -Force
Open the profile for editing:
notepad $PROFILE
2

Add the Argument Completer

Add this code to your $PROFILE:
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', $_)
        }
}
3

Save and Reload

  1. Save the file
  2. Reload your profile:
. $PROFILE
Or restart PowerShell for changes to take effect.
4

Test Tab Completion

Try typing a partial command and press Tab:
winget inst⇥
It should complete to:
winget install

Command Reference

The winget complete command powers the tab completion feature.

Syntax

winget complete --word=<word> --commandline=<commandline> --position=<position>

Required Arguments

ArgumentDescription
--wordThe current word being completed - the token where the cursor is located. Can be empty to indicate no current value at the cursor. If provided, it must appear as a substring in the command line.
--commandlineThe entire current command line, including winget. Everything except the tab character should be provided to this argument.
--positionThe current position of the cursor in the command line. Can be greater than the length of the command line string to indicate the cursor is at the end.

Completion Modes

When a word value is provided:
winget complete --word="pow" --commandline="winget install pow" --position=16
Suggests completions that:
  • Fit correctly at this location
  • Start with the given word value
Example output:
"Power Toys"
PowerShell

Completion Types

Based on the cursor position and context, completions can be:

Sub-command

Cursor is after a command with available sub-commandsExample: winget source ⇥

Argument Specifier

Cursor is not after an argument expecting a value, and arguments are availableExample: winget install ⇥

Argument Value

Cursor is after an argument specifier that expects a value, or a positional argument is expectedExample: winget install --source ⇥

Output Format

Completions are output one per line:
install
search
show
source
If a completion string contains a space, it’s wrapped in quotations:
"Power Toys"
"Visual Studio Code"

Bash and Zsh Support

While the winget complete command is shell-agnostic, the PowerShell example above is specific to PowerShell. You’ll need to adapt the completion script for other shells.

Bash Example

For Bash, you would need to create a completion script using the complete builtin:
_winget_complete() {
    local word="${COMP_WORDS[COMP_CWORD]}"
    local commandline="${COMP_LINE}"
    local position="${COMP_POINT}"
    
    COMPREPLY=($(winget complete --word="$word" --commandline="$commandline" --position="$position" 2>/dev/null))
}

complete -F _winget_complete winget
Add this to your ~/.bashrc or ~/.bash_completion.

Zsh Example

For Zsh, you would create a completion function:
_winget() {
    local word="${words[CURRENT]}"
    local commandline="${words}"
    local position=$CURSOR
    
    completions=("${(@f)$(winget complete --word="$word" --commandline="$commandline" --position="$position" 2>/dev/null)}")
    _describe 'winget' completions
}

compdef _winget winget
Add this to your ~/.zshrc.
These Bash and Zsh examples are basic implementations. You may need to adjust them based on your specific shell configuration and requirements.

Troubleshooting

Check WinGet version:
winget --version
Ensure you have v0.1.42241 or later.Verify profile loaded:
Get-Command Register-ArgumentCompleter
Test complete command manually:
winget complete --word="" --commandline="winget" --position=6
The completion command queries WinGet in real-time, so outdated completions usually mean your source needs updating:
winget source update
If you get an error about execution policy when loading your profile:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
See about execution policies for more information.

Next Steps

Commands

Learn about all available WinGet commands

Settings

Customize WinGet behavior and preferences

Build docs developers (and LLMs) love