msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.28k stars 484 forks source link

Wrong PATH convertion when running msys2 from an existing msys2 instance #1848

Open Celeborn2BeAlive opened 4 years ago

Celeborn2BeAlive commented 4 years ago

Hi, I'm using msys2 with MSYS2_PATH_TYPE=inherit, so my msys2 path contains my windows path. When I run msys2 normally everything is fine with $PATH and windows paths inside are converted to msys2 path, for example:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Users/laure/scoop/apps/cmder/current/vendor/conemu-maximus5/ConEmu/Scripts:/c/Users/laure/scoop/apps/cmder/current/vendor/conemu-maximus5:/c/Users/laure/scoop/apps/cmder/current/vendor/conemu-maximus5/ConEmu:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/Git/cmd:/c/Users/laure/.home_sync/bin:/c/Users/laure/.pyenv/pyenv-win/bin:/c/Users/laure/.pyenv/pyenv-win/shims:/c/Users/laure/scoop/apps/nvm/current/nodejs/nodejs:/c/Users/laure/scoop/shims:/c/Users/laure/AppData/Local/Microsoft/WindowsApps

However, if a run a new msys2 instance from my current msys2 terminal, the path of the new instance is not correctly converted:

/usr/local/bin:/usr/bin:/bin:/opt/bin:C:\Users\laure\scoop\apps\cmder\current\vendor\conemu-maximus5\ConEmu\Scripts;C:\Users\laure\scoop\apps\cmder\current\vendor\conemu-maximus5;C:\Users\laure\scoop\apps\cmder\current\vendor\conemu-maximus5\ConEmu;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;C:\Users\laure\.home_sync\bin;C:\Users\laure\.pyenv\pyenv-win\bin;C:\Users\laure\.pyenv\pyenv-win\shims;C:\Users\laure\scoop\apps\nvm\current\nodejs\nodejs;C:\Users\laure\scoop\shims;C:\Users\laure\AppData\Local\Microsoft\WindowsApps

As a result, msys2 fails to find my binaries.

If you're wondering why I'm doing that, it's because I want to launch visual studio code directly from msys2, but then its integrated terminal that I configured to also run msys2 has the path issue I'm mentioning.

Do you have any idea where this come from ? Is it a known issue ? And do you have a workaround ?

Thanks for the answer and for your work on msys2 !

Biswa96 commented 4 years ago

If VSCode is the only reason then you can use aliases in shell rc file. As example, alias vscode=/c/path/to/vscode.exe.

Celeborn2BeAlive commented 4 years ago

If VSCode is the only reason then you can use aliases in shell rc file. As example, alias vscode=/c/path/to/vscode.exe.

I may have been unclear, my issue is not that VS code cannot be found in my PATH, it can (I just run "code" and vs code starts).

The issue is in the integrated terminal of VS code, which is itself running msys2.

What I run is actually cmder -> msys2 -> "code ." (to open VS code in my current working dir) -> msys2 (inside VS code integrated terminal).

In the first msys2, if I type echo $PATH, I can see my windows PATH which have been correctly converted (all "\" are now "/", and C: or D: is replaced with /c/ or /d/), so everything is fine. I can run git, cmake, code, etc, perfect.

But in the second msys2, the one that run inside VS code, if I type echo $PATH I get my windows PATH (so it means MSYS2_PATH_TYPE=inherit is also working in this instance of msys2), but not converted, all paths are back to their windows version with "\" separator and C:, D:, etc. So in this msys2 I cannot run git, cmake, etc (and no I don't want to write an alias for all my binaries :p).

Its like the conversion step of PATH is missing in the second msys2.

However, I just did a few more tests and noticed the issue only occurs when I'm running msys2 from cmder. If I directly run a msys2.exe console, then vs code -> msys2, everything is fine with the path. But if I do the same from a msys2 terminal in cmder, the path is unconverted in the second msys2 instance.

I will investigate what is going on with cmder and close the issue if it's only related to it.

tanzislam commented 4 years ago

I had applied "delayed expansion" inside msys2_shell.cmd in #1836 to keep the Bash command line more intact. If Cmder was already working around the previous early-expansion behavior (by itself escaping the Bash command line) then it would break now.

MaximusSeniorem commented 3 years ago

Same issue for me. Here's what I found

Seems like the variable ORIGNAL_PATH is not 'cygpath-ed' when launching msys2 as a VSCode integrated terminal. I can't understand why though... (I litterally can't, since I couldn't find when this variable is supposed to be set)

extract of my vscode setting.json
    "terminal.integrated.profiles.windows": {
        "MSYS64" : {
            "path" : "C:\\msys64\\msys2_shell.cmd",
            "args" : ["-defterm","-mingw64","-no-start","-full-path"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "MSYS64"

I got windows format

$ echo $ORIGINAL_PATH
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;...

whereas launching msys2_shell.cmd with windows terminal with the exact same args outputs:

$ echo $ORIGINAL_PATH
/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:...
Konfekt commented 1 year ago

Hello, is it intended that echo $0 inside a shell script on C: shows a path starting with C:/ instead of /c/ ?