DEV Community

yumetodo
yumetodo

Posted on

Make the integrated shell of Visual Studio Code to bash of MSYS2

Notice

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

Visual Studio Code 15.1の統合シェルをMSYS2のbashにする - Qiita

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

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:

{
    "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"
}
Enter fullscreen mode Exit fullscreen mode

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

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

ref:

terminal.integrated.shellArgs.windows

Passing --login, -l will same effect.

Now, let's read man bash.

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).
Enter fullscreen mode Exit fullscreen mode

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:

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

Top comments (1)

Collapse
 
airbus5717 profile image
Airbus5717

thanks alot for this