5

[EDITED to add:] It turns out that the actual problem here was a brainless typo I had made. The answer to my actual question is "yes, you just do the obvious thing and it works, if you aren't a moron". I'm accepting the answer that basically says that, but maybe in fact the question should be deleted.

My employer's standard setup for software development on Windows involves using MSYS. (Either traditional MSYS or MSYS2.) Is there a way to run the shell for either of these inside the new Windows Terminal?

Traditional MSYS has a Windows batch script that arranges to execute sh.exe inside whatever terminal it's being run from. You might therefore think that making a new profile in WT's profiles.json, with "commandline": "path\to\sh.exe", would do the trick. Alas, no: if I do this and ask WT for a terminal of that type, I get a plain old cmd prompt instead. (Starting in C:\WINDOWS\System32.) [EDITED to add:] Duh, not-alas, yes: if I do this then it basically does work, but this gets wrong a couple of details that the accepted answer gets right.

The thing you run to get an MSYS2 prompt is a Windows executable instead of a batch script as in traditional MSYS, but it too launches its own sh.exe. Same thing happens with that.

I guess what's going on here is that the MSYS sh.exe is just expecting to interact via stdin and stdout, whereas an executable suitable for running directly from WT needs to understand the rather complicated Microsoft console APIs, or something like that.

I've also tried, with little optimism and no success (they all produce the same result as above), the following things:

"commandline": "cmd path/to/sh.exe"
"commandline": "cmd /c path/to/sh.exe"
"commandline": "cmd path/to/msys2_shell.cmd"
"commandline": "cmd /c path/to/msys2_shell.cmd"

Is there any convenient way to get an MSYS shell running inside a Windows Terminal?

2 Answers2

5

MSYS2 has their own guide to add MSYS2 to Windows Terminal. It uses msys2_shell.cmd instead of run the shell manually.

Usage:
    msys2_shell.cmd [options] [login shell parameters]

Options: -mingw32 | -mingw64 | -ucrt64 | -clang64 | -msys[2] Set shell type -defterm | -mintty | -conemu Set terminal type -here Use current directory as working directory -where DIRECTORY Use specified DIRECTORY as working directory -[use-]full-path Use full current PATH variable instead of trimming to minimal -no-start Do not use "start" command and return login shell resulting errorcode as this batch file resulting errorcode -shell SHELL Set login shell -help | --help | -? | /? Display this help and exit

Any parameter that cannot be treated as valid option and all following parameters are passed as login shell command parameters.

I think the manual itself is pretty self-explanatory. The important flags here are -no-start and -defterm. But here, I wants to add more flags. The one that I added is -here that recommended by the guide, and -shell, because I want to choose another shell. You can customize it as you want.

C:\\msys64\\msys2_shell.cmd -defterm -here -no-start -mingw64 -shell zsh

So, the JSON profile would be

{
    "guid": "{05351409-756a-416f-81c1-a97a1a2cdfe2}",
    "name": "MINGW64",
    "commandline": "C:\\msys64\\msys2_shell.cmd -defterm -here -no-start -mingw64 -shell zsh",
    "hidden": false
},

For the GUID field, you can generate your own with [guid]::NewGuid().Guid in PowerShell, or use an online service like this one. It just identifier that this profile is different with others that might have same name.

For the latest version of Windows Terminal, you don't need edit the JSON file manually, and it also generate the GUID for you. Simply click "Add a new profile" and specify the "Command line" field.

terminal

nouvist
  • 181
4

Assuming MSYS2 is installed in C:\msys2 folder, the commandline entry for Windows Terminal will be C:\msys2\usr\bin\bash.exe -i -l. Hence the entry in profile.json will be:

{
    // Make changes here to the MSYS2 profile
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "name": "msys2",
    "commandline": "C:\\msys2\\usr\\bin\\bash.exe -i -l",
    "hidden": false
},

The command launches bash.exe from MSYS2 environment with --interactive and --login options. Those options are necessary to set up environment specific to MSYS2 only. For more information about how to add entry in Windows Terminal profile.json file, see this documentation from Microsoft Temrminal GitHub repository.

Biswapriyo
  • 11,584