Skip to content

Emulation of ~ (tilde) expansion for native utilities is incomplete #11386

Closed

Description

Note:

  • ~ expansion for native utilities currently fundamentally only works on Unix platforms - but Windows would benefit from it too: see Resolve file paths before passing to native commands #10675

  • Fully emulating the logic of ~ expansion in PowerShell requires recognizing partial quoting of sub-tokens in arguments (e.g., ~/'foo bar'), which may turn out to be a challenge based on how argument parsing currently works.

Steps to reproduce

On a Unix-like platform:

# Quoting the argument as a whole always suppresses ~ expansion.
/bin/echo '~/foo' | Should -Be '~/foo'

# Both commands should expand ~ to the value of $HOME, 
# because the ~/ prefix is unquoted.
/bin/echo ~/foo | Should -Not -BeLike '~/*'
/bin/echo ~/'foo bar' | Should -Not -BeLike '~/*'

Expected behavior

All tests should succeed.

Actual behavior

The 3rd test fails, because the partially quoted argument prevented ~ expansion - even though ~/ is unquoted.

Expected like wildcard '~*' to not match '~/foo bar', but it did match.

Note that in POSIX-like shells - whose behavior here is being emulated - /bin/echo ~/'foo bar' indeed expands ~, as expected.

Environment data

PowerShell Core 7.0.0-rc.1

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Dec 17, 2019
  2. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Dec 18, 2019
  3. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    on Dec 18, 2019
  4. Zenexer commented on Dec 19, 2019

    @Zenexer

    It's also missing support ~username syntax; for example, if I have a user foo with a home directory of /home/foo, even if I'm currently running as user bar, ~foo/test should expand to /home/foo/test. I don't think it's too important to prioritize that feature, since it's not widely known, but I figured I'd mention it.

  5. rkitover commented on Mar 14, 2020

    @rkitover
    Contributor

    No, I believe the ~user expansion is widely known, at least among linux developers and power users and is VERY useful.

    E.g., I'm setting up an account for a friend on my windows server, I may want to do something like:

    cpi -rec vimfiles, src, .vimrc, .gitconfig ~other_user

    It should tab complete the expansion too.

  6. SteveL-MSFT commented on Apr 18, 2020

    @SteveL-MSFT
    Member

    ~username expansion should be a separate issue

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

Metadata

Metadata

Labels

Issue-Enhancementthe issue is more of a feature request than a bugWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions