Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Choco tab completion does not work if .exe is present #2255

Open
Luk164 opened this issue May 2, 2021 · 6 comments
Open

Choco tab completion does not work if .exe is present #2255

Luk164 opened this issue May 2, 2021 · 6 comments

Comments

@Luk164
Copy link

Luk164 commented May 2, 2021

What You Are Seeing?

When using choco in PWSH, I almost always use tab completion. For choco, this ends in choco.exe, but I noticed that tab completion for commands (i.e. choco install) does not work with the choco.exe.

What is Expected?

Tab completion should work with both choco and choco.exe commands

How Did You Get This To Happen? (Steps to Reproduce)

  1. Type choco ins
  2. Press TAB
  3. works fine
  4. type choco.exe ins
  5. Press TAB
  6. Does not work

This is what my profile file looks like:

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Chocolatey profile
#$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
#if (Test-Path($ChocolateyProfile)) {
#  Import-Module "$ChocolateyProfile"
#}
Import-Module DockerCompletion
Import-Module “$env:ChocolateyInstall\helpers\chocolateyProfile.psm1” -Force
Set-Alias -Name npm -Value pnpm

P.S.: Deactivated chocolatey profile because it was causing trouble for me. If this is problematic for some reason feel free to point it out.

@gep13 gep13 changed the title Choco tabl completion does not work if .exe is present Choco tab completion does not work if .exe is present May 12, 2021
@corbob
Copy link
Member

corbob commented May 13, 2021

@Luk164 would you mind editing your issue and wrapping the profile code in a codefence? This will cause GitHub to format it as code and not markdown. A sample codefence:

```powershell
Get-ChildItem ~
```

The powershell is entirely optional, but will enable syntax highlighting.

Based on what I can make out from the formatting, you say you've deactivated the chocolatey profile, but it looks like it's loaded on the second-last line. I can confirm that I'm able to reproduce this issue with choco.exe not tab completing while choco does. I tried to edit the tab completions to make it work with .exe and the only thing I could do was break tab completion for both 😂

I have found this article (https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#powershell) on adding dotnet completions, and if I change it to dotnet.exe I can autocomplete on that, so it seems .exe is doable, it just might need to be done differently than it is currently (currently I think we're using a module called PowerTab that adds tab completion to versions of PowerShell prior to the introduction of Register-ArgumentCompleter).

@mattcargile
Copy link

mattcargile commented Jan 23, 2022

This was a workaround that helped me. You could add it to your $PROFILE

New-Alias -Name 'choco.exe' -Value 'choco' -Force

This allows the internal function Get-AliasPattern to return an additional command.

I have found this article (https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#powershell) on adding dotnet completions, and if I change it to dotnet.exe I can autocomplete on that, so it seems .exe is doable, it just might need to be done differently than it is currently (currently I think we're using a module called PowerTab that adds tab completion to versions of PowerShell prior to the introduction of Register-ArgumentCompleter).

On PowerShell 7, I don't need to add the exe for the dotnet completion to work. It just works. For Chocolatey, I've been attempting to understand how Function:\TabExpansion and Function:\TabExpansion2 is working across powershell and pwsh. Chocolatey is using the older 2.0 version Powershell way but somehow it is still working in PowerShell Core. PowerTab is only working if user has it installed, otherwise I assume the engine is picking up on override of Function:\TabExpansion.

@vexx32
Copy link
Member

vexx32 commented Jan 24, 2022

Yeah, the method we use is pretty ancient. I don't know if we're able to change how we're doing it until we drop support for PowerShell v2 though. At that point we can use newer methods of tab completion which shouldn't have this issue. That alias setting is a nice workaround though, and it might be worth adding to our tab completion / profile script to enable it by default.

@yan12125
Copy link

FWIW, Chocolatey tab completion is gone with PowerShell Core 7.4, which dropped support for Function:\TabExpansion [1].

I don't know if we're able to change how we're doing it until we drop support for PowerShell v2 though.

Maybe you can define both Function:\TabExpansion and Function:\TabExpansion2, and call the former from the latter like the approach removed in [1]?

[1] PowerShell/PowerShell#18337

@corbob
Copy link
Member

corbob commented Nov 27, 2023

FWIW, Chocolatey tab completion is gone with PowerShell Core 7.4, which dropped support for Function:\TabExpansion [1].

I don't know if we're able to change how we're doing it until we drop support for PowerShell v2 though.

Maybe you can define both Function:\TabExpansion and Function:\TabExpansion2, and call the former from the latter like the approach removed in [1]?

[1] PowerShell/PowerShell#18337

@yan12125 Thank you for the heads up here. Would you mind opening a new issue for this?

@yan12125
Copy link

@yan12125 Thank you for the heads up here. Would you mind opening a new issue for this?

Sure, I created #3364. Didn't do so as I thought #3364 and this issue are actually the same issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants