microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.28k stars 1.45k forks source link

auto complete does not automatically enable after install `winget` with Microsoft Store #1430

Open soroshsabz opened 3 years ago

soroshsabz commented 3 years ago

Brief description of your issue

Don't auto complete automatically enable after install winget with Microsoft Store

Steps to reproduce

  1. Install winget from Microsoft Store
  2. Open Windows terminal (PowerShell)
  3. Write winget and then click repeated presses of tab (β‡₯)
  4. PowerShell does not show any command or meaningful suggestion, instead of showing file and folder

Expected behavior

I expect after install winget from Microsoft Store, and open Windows Terminal (PowerShell) I can use auto-complete without need any further steps.

Actual behavior

auto-complete does not work automatically.

Environment

Windows Package Manager v1.0.11692
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.19043.1202
Package: Microsoft.DesktopAppInstaller v1.12.11692.0

Workaround

I have to add below command manually to my profile from WinGet Command Line Tab Completion

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', $_)
        }
}

After close all PowerShell and reopen that, this work correctly

soroshsabz commented 3 years ago

related to #146

denelon commented 2 years ago

We're looking at options to register the completer for PowerShell, but it will still likely require a user to add one or more lines to their $Profile.