-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completers ∀x∈ {cmds, aliases} in powershell_completions.go #1977
base: main
Are you sure you want to change the base?
Conversation
pwsh completers ∀x∈ {cmds, aliases}
Yes, gladly. On a Windows machine, consider an application called Tab completion of the executable is provided by the env However, the registered autocompletion provided by In fact, I proposed this change specifically because I saw that the |
I think this is a proper solution for aliases compared to #1621. If we can just get the list of aliases in powershell then I think it makes sense to register the completion for all aliases by default. |
In my exuberance to include all the other aliases, I accidentally removed the original alias that was previously the only one being registered for autocompletion. I have restored this `'%[1]s'`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this in PowerShell versions 3-7 continuous (3, 4, 5, 6, 7). It works as expected.
How can I advance or reject this PR? |
I'm planning on reviewing this but you'll have to give me a couple of weeks to carve out the time. |
@mavaddat I'm trying to test this and it is not working for me. I have recompiled
Also, I just merged #1960 and now this PR needs rebasing. |
Implement curly bracket technique like spf13#1960
Preliminary assignment before use
I was also seeing this error before I forced
Done as you said. Please let me know if this is not what you meant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marckhouzam Were you able to check this to see if it is working for you too?
This looks to be a similar solution to #2049 I'm not a windows user or powershell expert but I would like to drive consensus on one of these two solutions. There probably should have been an issue created where we could discuss different proposals. @mavaddat - how does your solution compare to #2049? cc @bartoncasey |
Incorporate @bartoncasey insight about typical alias usage in spf13#2049
Typo in previous. Change `$_` PSItem to `$__%[2]sCmd`
Thank you @bartoncasey. You make a good point that the alias may not be the command path. I have updated the PR The core logic is here: Get-Alias | Where-Object { $_ -eq ($__CompleterTargetCmd | Resolve-Path) -or $_ -eq (Get-Command -Name $__CompleterTargetCmd).Definition} This captures all the aliases whose underlying executable is the target for the completer we're builder. |
@mavaddat for some reason I cannot rebase this PR; probably because it contains a merge. |
Done. Please recheck. |
@mavaddat I can't get this to work as I would expect. I recompiled
After that, I can get completion for |
I see the reason: I was using the Also, could you please describe your workflow for checking this? It would be ideal that we update |
I'll give this a try again. Thanks for the quick fix.
I can only do it manually.
More automation would be great. Could you clarify what you have in mind? |
@mavaddat It still does not work. Let's first agree on what needs to be considered as an alias. This is what I'm understanding we are targeting:
Is this correct? Are there other cases I'm missing? From what I can see from testing on Mac, point 3 is automatically handled by Powershell (I'm running v7.3.2).
I'll followup on #2049. |
Yes, this is correct. A legitimate target for command completion should be any name or alias that calls the executable (i.e., the executable that relies on
Correct. The system path resolution is responsible for searching for an appropriate executable. In PowerShell, we can call this API using the
The issue I foresee with #2049 is that it does not check that the system chose the correct executable. My solution was to check that the underlying executable that is called by the alias belonged to the The Executable. However, one may argue that we should not be checking that. After all, it's the system's responsibility to resolve the path. Also, attempting to check the alias's legitimacy adds code-maintenance overhead (as we are seeing in our testing back-and-forth). |
IIUC such a scenario would be of I write a script called But just in case, do you know if there’s a way for the user to unregister an argument completer if our approach causes problems? |
Yes, they would re-register the argument completer for that alias/name with |
Where
name
is substituted for%[1]s
, this provides PowerShell argument completer for all%[1]s
commands and aliases. In case ofpodman
, this is especially useful when user setdocker
as an alias.Also, the PowerShell argument completer will now apply for
%[1]s.exe
if that is an entrypoint to%[1]s
that is set bySystem.Environment
. This is useful for cases (Windows contexts) where the executable has*.exe
extension. (We don't want to deny argument completion when the user is employing a canonical name for the executable, which it does in the status quo.)Does this PR introduce a user-facing change?
Yes.
See also containers/podman#18847