choco
choco copied to clipboard
Choco tab completion does not work if .exe is present
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)
- Type choco ins
- Press TAB
- works fine
- type choco.exe ins
- Press TAB
- 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.
@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 :joy:
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
).
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 todotnet.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 ofRegister-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
.
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.
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] https://github.com/PowerShell/PowerShell/pull/18337
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
andFunction:\TabExpansion2
, and call the former from the latter like the approach removed in [1]?
@yan12125 Thank you for the heads up here. Would you mind opening a new issue for this?
@yan12125 Thank you for the heads up here. Would you mind opening a new issue for this?
Sure, I created https://github.com/chocolatey/choco/issues/3364. Didn't do so as I thought #3364 and this issue are actually the same issue.