Make the integrated shell of Visual Studio Code to bash of MSYS2
Tags: visualstudiocode, msys2, bash
Published: 2018-05-22 12:23:56

---
title: Make the integrated shell of Visual Studio Code to bash of MSYS2
published: true
description: 
tags: VisualStudioCode,MSYS2,bash
---

# Notice

This article is a translation of the post written in Japanese below:


[Visual Studio Code 15.1の統合シェルをMSYS2のbashにする - Qiita](https://qiita.com/yumetodo/items/42132a1e8435504448aa)

# Target Visual Studio Code version

15.1 or later

# Previous research

First of all, when you google about this story, the story that uses git of msys2 gets mixed, there is no googleability.

Well, first of all, you can find this post:

Visual Studio CodeのIntegrated Terminalでmsys2のzshを使う - 備忘録β版
http://yami-beta.hateblo.jp/entry/2016/06/08/000000


Then, there is such information below:

>mattnさんによる実行モジュールがあるようなので、そちらを用いると良さそうです。（コメント欄参照）
>(en)There seems to be an execution module by mattn, so it seems good to use it. (See comment field)
[Visual Studio Code で msys2 の bash を使う方法 · GitHub](https://gist.github.com/mattn/000735084394601b225a861af4afd35e)

So, I watch that:

>go で`bash-login.go`をビルドした後、出来上がった`exe`を以下の様に指定する。
>(en)After buildin `bash-login.go` with go, specify the completed `exe` as follows.

Well... build with go ...? I feel lazy even if I need to build only once.

While watching as if there is any other information,

Visual Studio Codeの統合シェルをMSYS2のBashにしたら.bash_profileが読み込まれなかった - Qiita
http://qiita.com/catfist/items/ea925fb9e0ba5c0ba9f3

Although it can be found. However, they says:

> Do not open workspace as working directory

Moreover, it is ridiculous to use VSCode extension to resolve it. WTF!

# The way to make the integrated shell of Visual Studio Code to bash of MSYS2

Write below in `setting.json`:

```json
{
    "terminal.integrated.shell.windows": "C:\\msys64\\usr\\bin\\bash.exe",
    "terminal.integrated.env.windows": {
        "MSYSTEM": "MINGW64",
        "CHERE_INVOKING": "1"
    },
    "terminal.integrated.shellArgs.windows": [
        "--login"
    ],
    "terminal.integrated.cursorStyle": "line"
}
```

`terminal.integrated.cursorStyle` is optional.

# explanation

## `terminal.integrated.shell.windows`

Specify full-path for bash. Be careful not to specify the bash not part of msys2(ex. the bash of git-bash).

## `terminal.integrated.env.windows`

You can set environmental variable when create process.

### `MSYSTEM`

Every MSYS2 user will know that MSYS2 has 3 mode, MSYS, MINGW32, MINGW64, and `$PATH` is also(`/usr/bin`, `/mingw32/bin`, `/mingw64/bin`).

`MSYS` is almost only for creating msys2 package.

`MINGW32` is based on the gcc that exception model is dwarf, not SEH, due to patent of Borland, for i686.

`MINGW64` is main environmental.

### `CHERE_INVOKING`

For flags that decide whether to set the working directory to the path of environment variable `$HOME` when logging in to bash, setting it to 1 prevents movement.

In the post below:
Visual Studio Codeの統合シェルをMSYS2のBashにしたら.bash_profileが読み込まれなかった - Qiita
http://qiita.com/catfist/items/ea925fb9e0ba5c0ba9f3
they says that cannot open workspace directory as current directory. The reason is they forget to set this flag. No VSCode extension is required like [@catfist](https://qiita.com/catfist)


Well, `msys2_shell.cmd`'s code is too unreadable, so it's unavoidable if they did not understand.

ref:

- [Cygwin導入＆ある程度日本語化（Cygwin-JE未使用）｜mizuk6nの【公開備忘録】](https://ameblo.jp/mizuk6n/theme-10002628249.html)

## `terminal.integrated.shellArgs.windows`

Passing `--login`, `-l` will same effect.

Now, let's read `man bash`.

```plain
BASH(1)                                                      General Commands Manual                                                     BASH(1)

NAME
       bash - GNU Bourne-Again SHell
OPTIONS
       -l        Make bash act as if it had been invoked as a login shell (see INVOCATION below).

       --login
              Equivalent to -l.

       --noprofile
              Do  not  read  either  the  system-wide  startup  file  /etc/profile  or any of the personal initialization files ~/.bash_profile,
              ~/.bash_login, or ~/.profile.  By default, bash reads these files when it is invoked as a login shell (see INVOCATION below).
```

>see INVOCATION below


Please read it yourself.

To summarize, if you do not pass `-l` or `--login`, `~/.Bash_profile` will not be loaded.

More detail, That is about login shell and interactive shell. Please see below:

- [ログインシェルとインタラクティブシェルと~/.bashrc達の関係 - Qiita](http://qiita.com/incep/items/7e5760de0c2c748296aa)
- [bashのログインシェルとインタラクティブシェル | kanonjiのブログ](http://kanonji.info/blog/2013/06/20/bash%E3%81%AE%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3%E3%82%B7%E3%82%A7%E3%83%AB%E3%81%A8%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%A9%E3%82%AF%E3%83%86%E3%82%A3%E3%83%96%E3%82%B7%E3%82%A7%E3%83%AB/)

## `terminal.integrated.cursorStyle`

**optional**.

Specify the style of cursor of terminal. The default is `"block"`. I like line-style so that specify `"line"`.

# Result

![img](https://thepracticaldev.s3.amazonaws.com/i/y9s5s7q9oq06n4q1xswq.png)