Using Windows Terminal for MSYS2 #2320

Closed
opened 2026-01-30 22:52:21 +00:00 by claunia · 11 comments
Owner

Originally created by @angelog0 on GitHub (Jun 27, 2019).

Just out of curiosity, has someone tried to create a profile for using the new terminal with MSYS2?

Thanks...

Originally created by @angelog0 on GitHub (Jun 27, 2019). Just out of curiosity, has someone tried to create a profile for using the new terminal with [MSYS2](https://sourceforge.net/projects/msys2)? Thanks...
claunia added the Issue-QuestionResolution-AnsweredProduct-TerminalArea-Interop labels 2026-01-30 22:52:21 +00:00
Author
Owner

@MoeRT09 commented on GitHub (Jun 28, 2019):

Yes, works fine, unless you have TERM set to xterm-256color (eg. home and end key not working).
Here is my Profile:

{
    "acrylicOpacity": 0.75,
    "closeOnExit": false,
    "colorScheme": "Argonaut",
    "commandline": "msys2.cmd",
    "cursorColor": "#FFFFFF",
    "cursorShape": "bar",
    "fontFace": "Source Code Pro for Powerline",
    "fontSize": 10,
    "guid": "{09dc5eef-6840-4050-ae69-21e55e6a2e63}",
    "historySize": 9001,
    "icon": "ms-appdata:///roaming/msys2.ico",
    "name": "MSYS2",
    "padding": "0, 0, 0, 0",
    "snapOnInput": true,
    "useAcrylic": true
}

With msys2.cmd containing the code below, as there is currently no way to set environment variables for profiles (has to be availabe from PATH).

@echo off
setlocal

set PATH=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Docker\Docker\resources\bin
set MSYS2_PATH_TYPE=inherit
REM set TERM=xterm-256color
set MSYSROOT=C:\tools\msys64
if "%MSYSTEM%"=="" (
	set MSYSTEM=MSYS
)

set CHERE_INVOKING=1
%MSYSROOT%\usr\bin\zsh.exe --login
@MoeRT09 commented on GitHub (Jun 28, 2019): Yes, works fine, unless you have TERM set to xterm-256color (eg. home and end key not working). Here is my Profile: ```json { "acrylicOpacity": 0.75, "closeOnExit": false, "colorScheme": "Argonaut", "commandline": "msys2.cmd", "cursorColor": "#FFFFFF", "cursorShape": "bar", "fontFace": "Source Code Pro for Powerline", "fontSize": 10, "guid": "{09dc5eef-6840-4050-ae69-21e55e6a2e63}", "historySize": 9001, "icon": "ms-appdata:///roaming/msys2.ico", "name": "MSYS2", "padding": "0, 0, 0, 0", "snapOnInput": true, "useAcrylic": true } ``` With `msys2.cmd` containing the code below, as there is currently no way to set environment variables for profiles (has to be availabe from PATH). ```batch @echo off setlocal set PATH=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Docker\Docker\resources\bin set MSYS2_PATH_TYPE=inherit REM set TERM=xterm-256color set MSYSROOT=C:\tools\msys64 if "%MSYSTEM%"=="" ( set MSYSTEM=MSYS ) set CHERE_INVOKING=1 %MSYSROOT%\usr\bin\zsh.exe --login ```
Author
Owner

@angelog0 commented on GitHub (Jun 28, 2019):

@MoeRT09, yes, at the moment, the only solution to start MSYS2 and friends is to create an ad hoc .cmd file to set the needed environment variables...

Just this works,

"commandline": "c:/msys64/usr/bin/bash.exe --login -i",

but without setting the environment.

Maybe, soon, the Windows Terminal developers will add this possibility to the profiles settings.

Thanks.

@angelog0 commented on GitHub (Jun 28, 2019): @MoeRT09, yes, at the moment, the only solution to start MSYS2 and friends is to create an _ad hoc_ `.cmd` file to set the needed environment variables... Just this works, `"commandline": "c:/msys64/usr/bin/bash.exe --login -i",` but without setting the environment. Maybe, soon, the **Windows Terminal developers will add this possibility to the profiles settings.** Thanks.
Author
Owner

@Witchilich commented on GitHub (Nov 7, 2019):

If you installed them with scoop - scoop install msys2, you can just use this

        {
            "acrylicOpacity" : 0.75,
            "closeOnExit" : true,
            "colorScheme" : "flat-ui-v1",
            "commandline" : "cmd /c msys2",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "historySize" : 9001,
            "icon" : "%SCOOP%\\apps\\msys2\\current\\msys2.ico",
            "name" : "MSYS2",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : ".",
            "useAcrylic" : true
        },
        {
            "acrylicOpacity" : 0.75,
            "closeOnExit" : true,
            "colorScheme" : "flat-ui-v1",
            "commandline" : "cmd /c mingw64",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "historySize" : 9001,
            "icon" : "%SCOOP%\\apps\\msys2\\current\\mingw64.ico",
            "name" : "MinGW64",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : ".",
            "useAcrylic" : true
        },
@Witchilich commented on GitHub (Nov 7, 2019): If you installed them with scoop - `scoop install msys2`, you can just use this ``` { "acrylicOpacity" : 0.75, "closeOnExit" : true, "colorScheme" : "flat-ui-v1", "commandline" : "cmd /c msys2", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 10, "historySize" : 9001, "icon" : "%SCOOP%\\apps\\msys2\\current\\msys2.ico", "name" : "MSYS2", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : ".", "useAcrylic" : true }, { "acrylicOpacity" : 0.75, "closeOnExit" : true, "colorScheme" : "flat-ui-v1", "commandline" : "cmd /c mingw64", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "fontFace" : "Consolas", "fontSize" : 10, "historySize" : 9001, "icon" : "%SCOOP%\\apps\\msys2\\current\\mingw64.ico", "name" : "MinGW64", "padding" : "0, 0, 0, 0", "snapOnInput" : true, "startingDirectory" : ".", "useAcrylic" : true }, ```
Author
Owner

@viruscamp commented on GitHub (Dec 5, 2019):

Use these:

"commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw64"
"commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw32"
@viruscamp commented on GitHub (Dec 5, 2019): Use these: ``` "commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw64" "commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw32" ```
Author
Owner

@rkitover commented on GitHub (May 11, 2020):

Hi, for a solution with full terminal capability, check out:

https://github.com/rkitover/windows-alt-sshd-msys2

@rkitover commented on GitHub (May 11, 2020): Hi, for a solution with full terminal capability, check out: https://github.com/rkitover/windows-alt-sshd-msys2
Author
Owner

@mwstr commented on GitHub (Oct 27, 2020):

https://www.msys2.org/docs/terminals/

@mwstr commented on GitHub (Oct 27, 2020): https://www.msys2.org/docs/terminals/
Author
Owner

@angelog0 commented on GitHub (Nov 1, 2020):

@MeowningMaster, yes I know but I am using this:

{
                "guid": "{9c173dff-f524-43df-b40e-29953998c744}",
                "name": "MSYS2 Terminal",
                // From: https://github.com/msys2/MSYS2-packages/issues/1684#issuecomment-634694362
                "commandline": "C:/msys64/usr/bin/env.exe MSYS=winsymlinks:nativestrict MSYSTEM=MSYS /bin/bash --login",
                "startingDirectory": "C:/msys64/home/utente",
                "colorScheme": "MSYS2-Theme",
                "icon": "C:/msys64/msys2.ico"
            }
@angelog0 commented on GitHub (Nov 1, 2020): @MeowningMaster, yes I know but I am using this: ``` { "guid": "{9c173dff-f524-43df-b40e-29953998c744}", "name": "MSYS2 Terminal", // From: https://github.com/msys2/MSYS2-packages/issues/1684#issuecomment-634694362 "commandline": "C:/msys64/usr/bin/env.exe MSYS=winsymlinks:nativestrict MSYSTEM=MSYS /bin/bash --login", "startingDirectory": "C:/msys64/home/utente", "colorScheme": "MSYS2-Theme", "icon": "C:/msys64/msys2.ico" } ```
Author
Owner

@TBBle commented on GitHub (May 2, 2021):

Here's what I'm current using, that covers all five of the current MSYS2 MSYSTEMs, and does not end up with a needless cmd process in the tree:

      {
        "guid": "{c1372a71-8d9f-49d7-99db-8cb284c50b98}",
        //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -msys2",
        "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MSYS /bin/bash --login",
        "icon": "C:/msys64/msys2.ico",
        "name": "MSYS2 MSYS",
        "startingDirectory": "%USERPROFILE%"
      },
      {
        "guid": "{2367860f-e6b6-4e91-821a-287e0cceee71}",
        //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -mingw64",
        "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MINGW64 /bin/bash --login",
        "icon": "C:/msys64/mingw64.ico",
        "name": "MSYS2 MinGW 64-bit",
        "startingDirectory": "%USERPROFILE%"
      },
      {
        "guid": "{098bcacf-f271-4b79-b6c3-315bb4240e54}",
        //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -mingw32",
        "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MINGW32 /bin/bash --login",
        "icon": "C:/msys64/mingw32.ico",
        "name": "MSYS2 MinGW 32-bit",
        "startingDirectory": "%USERPROFILE%"
      },
      {
        "guid": "{20ca76e4-8d6f-4d37-8468-dbf02385dd18}",
        //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -ucrt64",
        "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=UCRT64 /bin/bash --login",
        "icon": "C:/msys64/ucrt64.ico",
        "name": "MSYS2 UCRT 64-bit",
        "startingDirectory": "%USERPROFILE%"
      },
      {
        "guid": "{87536769-301c-4fee-89c9-c1aa8950e471}",
        //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -clang64",
        "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=CLANG64 /bin/bash --login",
        "icon": "C:/msys64/clang64.ico",
        "name": "MSYS2 Clang 64-bit",
        "startingDirectory": "%USERPROFILE%"
      },

#2785 will improve this a bit by letting you set the env-vars in the config rather than using env (although it's not bad now), and eventually, #4000 will allow these to be auto-generated by a plugin, which could presumably only provide this environments you have installed, and/or honour your <MSYSTEM>.ini so that you get the same behaviour running inside and outside Windows Terminal, and have a single place to set the MSYS env-var configs.

#5571 would build on #4000 to make it easier to deal with the multiple MSYSTEM values, perhaps.

Note that I have OSC 9;9 output (see https://github.com/microsoft/terminal/issues/3158#issuecomment-803502834) hooked up here, otherwise CHERE_INVOKING=1 causes it to start in /c/WINDOWS/system32.

My OSC 9;9 setup is adding this to ~/.bashrc

# Enable OSC 9;9 generation
__osc9_9 () {
	history -a # See earlier setting of PROMPT_COMMAND
	printf "\033]9;9;%s\033\\" "$(cygpath --windows ${PWD})"
}
export PROMPT_COMMAND="__osc9_9"

Edit: Added "startingDirectory": "%USERPROFILE%" to each profile, which had been lost while verifying CHERE_INVOKING=1 behaviour. It's not important, as that's only slightly-more-useful as a starting directory that C:\Windows\system32, but it is more-consistent with the git-bash config snippets, for example.

@TBBle commented on GitHub (May 2, 2021): Here's what I'm current using, that covers all five of the current MSYS2 MSYSTEMs, and does not end up with a needless `cmd` process in the tree: ```jsonc { "guid": "{c1372a71-8d9f-49d7-99db-8cb284c50b98}", //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -msys2", "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MSYS /bin/bash --login", "icon": "C:/msys64/msys2.ico", "name": "MSYS2 MSYS", "startingDirectory": "%USERPROFILE%" }, { "guid": "{2367860f-e6b6-4e91-821a-287e0cceee71}", //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -mingw64", "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MINGW64 /bin/bash --login", "icon": "C:/msys64/mingw64.ico", "name": "MSYS2 MinGW 64-bit", "startingDirectory": "%USERPROFILE%" }, { "guid": "{098bcacf-f271-4b79-b6c3-315bb4240e54}", //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -mingw32", "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=MINGW32 /bin/bash --login", "icon": "C:/msys64/mingw32.ico", "name": "MSYS2 MinGW 32-bit", "startingDirectory": "%USERPROFILE%" }, { "guid": "{20ca76e4-8d6f-4d37-8468-dbf02385dd18}", //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -ucrt64", "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=UCRT64 /bin/bash --login", "icon": "C:/msys64/ucrt64.ico", "name": "MSYS2 UCRT 64-bit", "startingDirectory": "%USERPROFILE%" }, { "guid": "{87536769-301c-4fee-89c9-c1aa8950e471}", //"commandline": "\"C:/msys64/msys2_shell.cmd\" -defterm -no-start -clang64", "commandline": "C:/msys64/usr/bin/env.exe MSYS='enable_pcon winsymlinks:nativestrict' CHERE_INVOKING=1 MSYSTEM=CLANG64 /bin/bash --login", "icon": "C:/msys64/clang64.ico", "name": "MSYS2 Clang 64-bit", "startingDirectory": "%USERPROFILE%" }, ``` #2785 will improve this a bit by letting you set the env-vars in the config rather than using `env` (although it's not _bad_ now), and eventually, #4000 will allow these to be auto-generated by a plugin, which could presumably only provide this environments you have installed, and/or honour your `<MSYSTEM>.ini` so that you get the same behaviour running inside and outside Windows Terminal, and have a single place to set the `MSYS` env-var configs. #5571 would build on #4000 to make it easier to deal with the multiple `MSYSTEM` values, perhaps. Note that I have OSC 9;9 output (see https://github.com/microsoft/terminal/issues/3158#issuecomment-803502834) hooked up here, otherwise `CHERE_INVOKING=1` causes it to start in `/c/WINDOWS/system32`. My OSC 9;9 setup is adding this to ~/.bashrc ```bash # Enable OSC 9;9 generation __osc9_9 () { history -a # See earlier setting of PROMPT_COMMAND printf "\033]9;9;%s\033\\" "$(cygpath --windows ${PWD})" } export PROMPT_COMMAND="__osc9_9" ``` Edit: Added `"startingDirectory": "%USERPROFILE%"` to each profile, which had been lost while verifying `CHERE_INVOKING=1` behaviour. It's not important, as that's only slightly-more-useful as a starting directory that `C:\Windows\system32`, but it is more-consistent with the git-bash config snippets, for example.
Author
Owner

@angelog0 commented on GitHub (May 7, 2021):

@TBBle, why do you use MSYS='enable_pcon ....? What is enable_pcon? Which is its usefulness? (where is documented?) Thanks

@angelog0 commented on GitHub (May 7, 2021): @TBBle, why do you use `MSYS='enable_pcon ....`? What is `enable_pcon`? Which is its usefulness? (where is documented?) Thanks
Author
Owner

@TBBle commented on GitHub (May 8, 2021):

That's the flag to enable psuedo console support, the main upshot of which is that you don't need to use winpty to run non-MINGW-compiled interactive console applications successfully, e.g. system-installed Python, under bash, or through pipes, etc.

Poking around, I think I added it to my config while trying to understand why tmux doesn't work, I don't recall actually having this issue, as I rarely use native windows console applications under bash/MSYS anyway.

The flag enable_pcon isn't documented AFAIK, it's an MSYS-specific additions to Cygwin's disable_pcon, and is equivalent to nodisable_pcon, although the Cygwin docs don't mention that you can use no to invert it.

Cygwin enables the psuedo console by default, so they offer the disable_pcon option to disable that if you're having issues. MSYS2 had issues, so they changed their default to disable the pseudo console, which means that to enable the pseudo console, you needed to use nodisable_pcon, and that's a mouthful, so they added enable_pcon as an equivalent.

See https://github.com/msys2/msys2-runtime/pull/6 and https://github.com/msys2/MSYS2-packages/pull/1964

@TBBle commented on GitHub (May 8, 2021): That's the flag to enable psuedo console support, the main upshot of which is that you don't need to use [`winpty`](https://github.com/rprichard/winpty) to run non-MINGW-compiled interactive console applications successfully, e.g. system-installed Python, under bash, or through pipes, etc. Poking around, I think I added it to my config [while trying to understand why tmux doesn't work](https://github.com/msys2/MSYS2-packages/issues/1684#issuecomment-634694362), I don't recall actually having this issue, as I rarely use native windows console applications under bash/MSYS anyway. The flag `enable_pcon` isn't documented AFAIK, it's an [MSYS-specific additions to Cygwin's `disable_pcon`](https://cygwin.com/cygwin-ug-net/using-cygwinenv.html), and is equivalent to `nodisable_pcon`, although the Cygwin docs don't mention that you can use `no` to invert it. Cygwin enables the psuedo console by default, so they offer the `disable_pcon` option to disable that if you're having issues. MSYS2 had issues, so [they changed their default to disable the pseudo console](https://github.com/msys2/MSYS2-packages/blob/409936cda5d4f911edcd697c087afb3cd4d15535/msys2-runtime/0020-Default-to-disable_pcon.patch), which means that to enable the pseudo console, you needed to use `nodisable_pcon`, and that's a mouthful, so [they added `enable_pcon` as an equivalent](https://github.com/msys2/MSYS2-packages/blob/409936cda5d4f911edcd697c087afb3cd4d15535/msys2-runtime/0021-Introduce-the-enable_pcon-value-for-MSYS.patch). See https://github.com/msys2/msys2-runtime/pull/6 and https://github.com/msys2/MSYS2-packages/pull/1964
Author
Owner

@angelog0 commented on GitHub (May 8, 2021):

@TBBle, thanks for clarification.

@angelog0 commented on GitHub (May 8, 2021): @TBBle, thanks for clarification.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2320