Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Windows Terminal for MSYS2 #1669

Closed
angelog0 opened this issue Jun 27, 2019 · 11 comments
Closed

Using Windows Terminal for MSYS2 #1669

angelog0 opened this issue Jun 27, 2019 · 11 comments
Labels
Area-Interop Communication between processes Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-Answered Related to questions that have been answered

Comments

@angelog0
Copy link

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

Thanks...

@angelog0 angelog0 added the Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs label Jun 27, 2019
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label Jun 27, 2019
@MoeRT09
Copy link

MoeRT09 commented 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

@angelog0
Copy link
Author

@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.

@miniksa miniksa added Area-Interop Communication between processes Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-Answered Related to questions that have been answered and removed Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs labels Jun 28, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jun 28, 2019
@miniksa miniksa closed this as completed Jun 28, 2019
@Witchilich
Copy link

Witchilich commented 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
        },

@viruscamp
Copy link

Use these:

"commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw64"
"commandline" : "C:/msys64/msys2_shell.cmd -defterm -no-start -mingw32"

@bitcrazed bitcrazed removed their assignment May 5, 2020
@rkitover
Copy link
Contributor

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

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

@MeowningMaster
Copy link

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

@angelog0
Copy link
Author

angelog0 commented 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"
            }

@TBBle
Copy link

TBBle commented 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 #3158 (comment)) 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.

@angelog0
Copy link
Author

angelog0 commented May 7, 2021

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

@TBBle
Copy link

TBBle commented 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 msys2/msys2-runtime#6 and msys2/MSYS2-packages#1964

@angelog0
Copy link
Author

angelog0 commented May 8, 2021

@TBBle, thanks for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interop Communication between processes Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

9 participants