Skip to content

Tab completion replaces tilde with full path #20033

Closed

Description

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

Activity

  1. jhoneill commented on Jul 27, 2023

    @jhoneill

    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

  2. mklement0 commented on Jul 27, 2023

    @mklement0
    Contributor

    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
  3. ThomasNieto commented on Jul 27, 2023

    @ThomasNieto
    ContributorAuthor

    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.

  4. MartinGC94 commented on Jul 27, 2023

    @MartinGC94
    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?

  5. ThomasNieto commented on Jul 27, 2023

    @ThomasNieto
    ContributorAuthor

    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

  6. mklement0 commented on Jul 27, 2023

    @mklement0
    Contributor

    MartinGC94, that's great news, but I can confirm Thomas Nieto (@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.

  7. MartinGC94 commented on Jul 27, 2023

    @MartinGC94
    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.

  8. ThomasNieto commented on Jul 28, 2023

    @ThomasNieto
    ContributorAuthor

    Closing as a duplicate of #5350.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions