Skip to content
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

Tab completion replaces tilde with full path #20033

Closed
5 tasks done
ThomasNieto opened this issue Jul 27, 2023 · 8 comments
Closed
5 tasks done

Tab completion replaces tilde with full path #20033

ThomasNieto opened this issue Jul 27, 2023 · 8 comments
Labels
Resolution-Duplicate The issue is a duplicate.

Comments

@ThomasNieto
Copy link
Contributor

Prerequisites

Steps to reproduce

If you type ~\ then Tab the home directory symbol will be converted into the full provider path instead of retaining the ~.

Expected behavior

# ~ is retained

Actual behavior

# Provider path is used

Error details

N/A

Environment data

7.4-preview4

Visuals

No response

@ThomasNieto ThomasNieto added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jul 27, 2023
@jhoneill
Copy link

This seems to be a damned if they do and damned if they don't thing. There is another recent issue complaining that external windows exes don't understand ~ in a path. Tab expanding ~ helps to ensure a working path gets sent to things but it annoyed me until I grew used to it. There's probably a wider issue about making ~ work everywhere so that it can happily stay unexpanded by tab

@mklement0
Copy link
Contributor

mklement0 commented Jul 27, 2023

As noted, with ~ on Windows, when calling external programs, the behavior happens to be somewhat of a blessing currently, as ~ isn't automatically expanded on invocation.

In general, however, I agree that the behavior is unhelpful:

  • It is visually somewhat jarring.
  • It interferes with the ability to retain a path in its abstract form, which is important if you want to copy the path to, say, sample code in a tutorial.
  • It can significantly lengthen your command (see below).

Note that the problem is more general, in that it also affects (environment) variable-based paths; e.g., on Windows:

# Pressing TAB at the end of this line expands to a literal, user-specific path; e.g.
#  'C:\Users\jdoe\AppData\Roaming\Microsoft\'
Get-ChildItem $env:APPDATA\Mi

@ThomasNieto
Copy link
Contributor Author

ThomasNieto commented Jul 27, 2023

For the external programs issue, I would expect PowerShell should expand ~ from a PSPath (Temp: / ~) to a provider path (C:\temp) when calling external programs since they don't know what a PSPath is or may not have a concept of ~.

This issue is specifically just for tab completion and command history so that what the user typed in is preserved. In my use case it creates a long command with the full path when I'm looking back and just need the relative path from ~.

What prompted me originally to log this was when my custom PSDrive GitHub got changed to the provider path but found it was TabExpansionPlusPlus custom TabExpansion2 function that was messing with PSDrives and with no profile worked as expected but ~ still was changed.

@MartinGC94
Copy link
Contributor

Strange, you say this is happening in preview 4 but this was actually fixed in the preview 4 release by this PR: #19489
It works as expected on my PC:
image

Have you tried loading PS without a custom profile?

@ThomasNieto
Copy link
Contributor Author

ThomasNieto commented Jul 27, 2023

@MartinGC94 you're right, I must have accidently ran pwsh stable when the test with no profile. I can't reproduce on 7.4-preview 4. I can still reproduce the example using environment variables though. Did you fix that as well in your PR?

image

@mklement0
Copy link
Contributor

@MartinGC94, that's great news, but I can confirm @ThomasNieto's finding that environment variables are still converted to literal paths.

Looking at your PR, I see that the issue at hand has a duplicate dating back to 2017:

Once the environment-variable issue is also handled, both this and the aforementioned issue should be closed.

@MartinGC94
Copy link
Contributor

Great, I was afraid there was some weird edge case I had missed. As for the variable replacement, I have some WIP code locally to fix that, I've just been too lazy to finish it. Expect to see a PR for that in the near future.

@ThomasNieto
Copy link
Contributor Author

Closing as a duplicate of #5350.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Jul 28, 2023
@kilasuit kilasuit added the Resolution-Duplicate The issue is a duplicate. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate The issue is a duplicate.
Projects
None yet
Development

No branches or pull requests

5 participants