Using msys shell in Visual Studio Code

according to MSYS terminals, we can use this:

    "terminal.integrated.profiles.windows": {
        "msys mingw64": {
            "path": "C:/msys64/msys2_shell.cmd",
            "args": [
                "-defterm",
                "-here",
                "-no-start",
                "-mingw64"
            ]
        }
    },

this starts msys mingw64. to start other shell, just change -mingw64 to -mingw32 or -msys.


According to the msys.bat script, the actual executable that is launched depends on your TTY settings. The default setting uses the native command prompt and launches the sh.exe file as you can see from the following snippet:

:startsh
if NOT EXIST %WD%sh.exe goto notfound
start %WD%sh --login -i
exit

To get this to work in Visual Studio Code, you will need to add the following user settings:

"terminal.integrated.shell.windows": "C:\\MinGW\\msys\\1.0\\bin\\sh.exe",
"terminal.integrated.shellArgs.windows": ["--login", "-i"]

The path to the sh.exe file may be different depending on your install location for MSYS.

EDIT: (2019-01-20)

While the above still works for MSYS v1.0, I have since switched over to MSYS2 (https://www.msys2.org/). You can use the following settings to setup your Visual Studio Code to work with MSYS2 just as for v1.0 (once again, your install location might be different than mine):

"terminal.integrated.shell.windows": "C:\\msys64\\usr\\bin\\bash.exe",
"terminal.integrated.shellArgs.windows": ["--login", "-i"]

For extra-credit, we are going to modify an environment variable so that we always open the terminal in the current directory. There are various ways to accomplish this via scripting etc. However, the simplest way to do it, in my opinion, is to use the CHERE_INVOKING environment variable. By setting this flag to 1 it will inform the shell to use the current directory as the default entry point. Here is a complete tutorial on how to enable this flag:

  1. Press the windows key and type run and hit enter
  2. In the run dialog, type the following:

    rundll32.exe sysdm.cpl,EditEnvironmentVariables
    

    Run Dialog to open Environment Variables

  3. In the Environment Variables dialog that is opened, add a new user variable called CHERE_INVOKING and set it's value to 1.

    enter image description here

With this flag enabled in the Windows system, it should automatically open the terminal from the location where you called the bash.exe executable. For Visual Studio Code, this will be your root project directory. Enjoy!