Fd: Option `--path-separator` failing on MSys (Git Bash)

Created on 20 Feb 2020  Â·  11Comments  Â·  Source: sharkdp/fd

I have fd 7.4.0 installed on a Windows machine (Rust 1.41.0, stable-x86_64-pc-windows-msvc) and run it from a bash that is provided by Git for Windows, which itself is based on Msys2 (according to https://github.com/git-for-windows/git/wiki/Technical-overview):

$ uname -a
MINGW64_NT-10.0-18363 SOMEHOST 3.0.7-338.x86_64 2019-07-03 15:16 UTC x86_64 Msys

$ fd
bar
bar\baz
bar\baz\bla
bar\baz\bla\some.txt
bar\yetanother.txt
other.txt

fd is using backslashes as it is supposed to do in Windows. #429 added the --path-separator option, which could be useful for using the results as paths within Git Bash. However, in my environment, the option fails, and every backslash is substituted with the absolute path to the Git for Windows installation directory:

$ fd --path-separator="/"
bar
barC:/Program Files/Git/baz
barC:/Program Files/Git/bazC:/Program Files/Git/bla
barC:/Program Files/Git/bazC:/Program Files/Git/blaC:/Program Files/Git/some.txt
barC:/Program Files/Git/yetanother.txt
other.txt

$ ls "C:/Program Files/Git/"
bin/  cmd/  dev/  etc/  git-bash.exe*  git-cmd.exe*  LICENSE.txt  mingw64/  ReleaseNotes.html  tmp/  unins000.dat  unins000.exe*  unins000.msg  usr/

Using single-quotes around the slash character make no difference. Nor does leaving out the quotes all together.

feature-request good first issue

Most helpful comment

Thank you, that was a great hint, @sharkdp! I am very grateful to you for taking the time to dig into this.

For the record, one needs to set the environment variable MSYS_NO_PATHCONV=1:

$ fd --path-separator='/'
bar
barC:/Program Files/Git/baz
barC:/Program Files/Git/bazC:/Program Files/Git/bla
barC:/Program Files/Git/bazC:/Program Files/Git/blaC:/Program Files/Git/some.txt
barC:/Program Files/Git/yetanother.txt
other.txt

$ MSYS_NO_PATHCONV=1 fd --path-separator='/'
bar
bar/baz
bar/baz/bla
bar/baz/bla/some.txt
bar/yetanother.txt
other.txt

All 11 comments

It looks to me like this is a problem of Msys2 or Git Bash. Could you please try these suggestions: https://stackoverflow.com/a/54924640/704831 ?

Thank you, that was a great hint, @sharkdp! I am very grateful to you for taking the time to dig into this.

For the record, one needs to set the environment variable MSYS_NO_PATHCONV=1:

$ fd --path-separator='/'
bar
barC:/Program Files/Git/baz
barC:/Program Files/Git/bazC:/Program Files/Git/bla
barC:/Program Files/Git/bazC:/Program Files/Git/blaC:/Program Files/Git/some.txt
barC:/Program Files/Git/yetanother.txt
other.txt

$ MSYS_NO_PATHCONV=1 fd --path-separator='/'
bar
bar/baz
bar/baz/bla
bar/baz/bla/some.txt
bar/yetanother.txt
other.txt

This MSYS_NO_PATHCONV=1 fix only works on Git Bash.
When comes to msys2, we should use MSYS2_ARG_CONV_EXCL=--path-separator=
Ref: https://www.msys2.org/wiki/Porting/#filesystem-namespaces

Given that we introduced the --path-separator=… option for situations like Cygwin/MSYS2/Git Bash on Windows, it seems really unfortunate users have to go through this experience described in this ticket.

Maybe we should introduce a --path-separator-slash or --unix-path-separator option as an alias for --path-separator="/", which would not require any environment variables to be set?

What do you think?

Good idea!

Okay, let's turn this into a feature request.

I ran into this today trying to use fd on msys2, and just learned about MSYS2_ARG_CONV_EXCL so maybe I can fix my shell alias.

Could fd go a step further and try to auto-detect the path separator at runtime?

  • MSYS2 sets the MSYSTEM environment variable, which could be checked cheaply
  • Cygwin doesn't seem to set any unique environment variables

    • a hack could be to check for an entry starting with /cygdrive/ in PATH (usually PATH contains /cygdrive/c/Windows/System32, among other native windows path entries) Edit: apparently PATH gets mangled to a Windows-style string C:\foo\bar;C:\baz\quux at runtime, so that won't work.

    • I assume that forking off to a uname process would be too expensive

  • I'm not sure about git bash, except that it's msys/mingw based. Does it also set MSYSTEM?

@aswild Great idea. Maybe this could help for cygwin: https://stackoverflow.com/a/3104453 ?

Ooh, OSTYPE looks so promising but apparently it's only set as a shell variable and isn't exported to the environment, foiled again.

It would be great if someone could summarize the current status and what should/could be done here to improve the situation.

I haven't used msys2 for a while. Instead, I'm using WSL now and no longer need this option.

I think it's OK to leave it unchanged since I already give the workaround in msys2 at https://github.com/sharkdp/fd/issues/537#issuecomment-636422669

Was this page helpful?
0 / 5 - 0 ratings