Cannot recognize `~` in Windows
In powershell, ~ is used to refer to %HOME%.
For example, when running dir ~, it lists all files and folders under %HOME%, which is usually C:\Users\YOUR_USERNAME\.
However, when running for example, rm -rf ~/.cache or ls -a ~, it says:
rm: cannot access '~': No such file or directory
ls: cannot access '~': No such file or directory
Before I used Busybox-w32, which supports the ~ mark. I wish it could recognize it.
Anyway, it can recognize $HOME in powershell, as $HOME is just the absolute path, which can be tested with echo.
On Unix systems, this expansion is done by the shell, not by uutils. I think it should be the same on Windows. I've found this that might help tough: https://github.com/orgs/PowerShell/discussions/15263#discussioncomment-625042.
Edit: that option has been removed in recent powershell versions.
I've checked the documentation. Unfortunately, PSNativePSPathResolution has discontinued since powershell version 7.3.
Anyway, in Git Bash, the ls.exe in this project recognizes the tilde mark ~. It is because the tilde just refers to the home path.
me@DESKTOP MINGW64 ~/tmp
$ where ls
C:\Program Files\Git\usr\bin\ls.exe
C:\Users\me\scoop\shims\ls.exe
me@DESKTOP MINGW64 ~/tmp
$ touch 1 2 3 4 5
me@DESKTOP MINGW64 ~/tmp
$ /c/Users/me/scoop/shims/ls.exe ~/tmp
1 2 3 4 5
me@DESKTOP MINGW64 ~/tmp
$ echo ~
/c/Users/me
me@DESKTOP MINGW64 ~/tmp
$ /c/Users/me/scoop/shims/echo.exe ~
C:/Users/me
On the other hand, in Command Prompt, which certainly do not use tilde to refer to %HOME%, the ls.exe coming with Git Bash, it does recognize ~. I'm not quite sure whether it's a feature of MSYS2 MINGW64 Bash or not.
C:\Users\me\tmp>where ls
C:\Program Files\Git\usr\bin\ls.exe
C:\Users\me\scoop\shims\ls.exe
C:\Users\me\tmp>ls ~/tmp
1 2 3 4 5
C:\Users\me\tmp>C:\Users\me\scoop\shims\ls.exe ~/tmp
ls: cannot access '~/tmp': No such file or directory
Similarly, Busybox-w32 and CoreUtils for Windows have the same feature. I am not using them because of their poor support for Unicode. But this project will work well.
Anyway, it is the case that in Linux shell, ~ is simply /home/USER_NAME, which can be tested using echo, so the issue won't be there.
@szw0407 please don't share screenshots of terminals: they are terrible for accessibility and search. thanks
Similarly, Busybox-w32 and CoreUtils for Windows have the same feature. I am not using them because of their poor support for Unicode. But this project will work well.
In fact the coreutils for win32 was maintained by GNUWin32 but haven't been updated for years. I'm not sure whether it could represent the current version of coreutils or not.
@szw0407 please don't share screenshots of terminals: they are terrible for accessibility and search. thanks
I shall edit it later. Thanks for reminding me of that.
thanks :) the advantage of terminal is that it is easy to copy and paste!
Git bash is a shell, so they can implement more complex expansion, because they also have more information. Consider these two lines in bash:
ls ~
ls '~'
On Linux (and probably Git Bash), the first ~ should expand to the home directory, but the second should just be the file ~. However, the uutils ls binary cannot see that difference. All we see is the string "~", because the " quotes are part of the bash syntax.
Therefore, I think this has to be the responsibility of the shell, not the responsibility of uutils.