Powershell: Emulation of ~ (tilde) expansion for native utilities is incomplete

Created on 17 Dec 2019  路  4Comments  路  Source: PowerShell/PowerShell

Note:

  • ~ expansion for native utilities currently fundamentally only works on _Unix_ platforms - but Windows would benefit from it too: see #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 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
Issue-Enhancement WG-Engine-Providers

Most helpful comment

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.

All 4 comments

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.

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.

~username expansion should be a separate issue

:tada:This issue was addressed in #12386, which has now been successfully released as v7.1.0-preview.3.:tada:

Handy links:

Was this page helpful?
0 / 5 - 0 ratings