LoginSignup
4
4

More than 5 years have passed since last update.

msys2_shell.cmdを使ってVS Codeの総合シェルをMSYS2 bashにする

Last updated at Posted at 2018-01-26

はじめに

Visual Studio Codeの統合シェルをMSYS2のbashにする
という記事はすでにあるのですが、知らずに作ってしまいました。
msys2_shell.cmdの解説を兼ねて残しておきます。

実行環境

Visual Studio Code バージョン 1.19.2
MSYS2 64Bit版(x86_64)1 20161025

msys2_shell.cmdとは

かつてはmingw32_shell.bat,mingw64_shell.bat,msys2_shell.batがあったのですが、
filesystemパッケージの更新によりmsys2_shell.cmdへと統合されました。

C:\\msys64\\msys2_shell.cmd --helpを実行すると以下の文章が出力されます。

Usage:
    msys2_shell.cmd [options] [bash parameters]

Options:
    -mingw32 | -mingw64 | -msys[2]   Set shell type
    -defterm | -mintty | -conemu     Set terminal type
    -here                            Use current directory as working
                                     directory
    -where DIRECTORY                 Use specified DIRECTORY as working
                                     directory
    -[use-]full-path                 Use full currnent PATH variable
                                     instead of triming to minimal
    -no-start                        Do not use "start" command and
                                     return bash resulting errorcode as
                                     this batch file resulting errorcode
    -help | --help | -? | /?         Display this help and exit

Any parameter that cannot be treated as valid option and all
following parameters are passed as bash command parameters.

要約すると

使い方: msys2_shell.cmd [オプション] [シェルの引数]

オプション:
    -mingw32 | -mingw64 | -msys[2]   シェルタイプの設定
    -defterm | -mintty  | -conemu    ターミナルタイプの設定
    -here                            カレントディレクトリを
                                     作業ディレクトリに設定する
    -where DIRECTORY                 "DIRECTORY" を
                                     作業ディレクトリに設定する
    -[use-]full-path                 WindowsのPATH環境変数を
                                     MSYS2のPATH変数に引き継ぐ
    -no-start                        "start" コマンドを使わずに起動し
                                     シェルの返したエラーコードを
                                     このバッチのエラーコードとして返す
    -help | --help | -? | /?         helpを表示して終了する

オプションではない引数とそれ以降の引数はシェルの引数として渡されます。

つまり、msys2_shell.cmdの引数に
-defterm -no-startを指定すればbash.exeを同一ターミナル上で実行でき、
-hereを指定すればVS Codeのワークスペースを作業ディレクトリにでき2
-full-pathを指定すればWindowsのPATH環境変数が引き継げます。

結論

setting.json
{
    "terminal.integrated.shell.windows":"C:\\msys64\\msys2_shell.cmd",
    "terminal.integrated.shellArgs.windows": [
        "-mingw64","-defterm","-no-start","-here","-full-path"
    ],
    "terminal.integrated.setLocaleVariables":true
}

を設定に書くだけです3

解説

設定の名称 説明
"terminal.integrated.shell.windows" [Windows]ターミナルで使うシェルのパス
"terminal.integrated.shellArgs.windows" [Windows]ターミナルで使うシェルの引数
"terminal.integrated.setLocaleVariables" ターミナル起動時にロケール変数を設定する

つまり

set LANG=(ユーザーロケール)
C:\\msys64\\msys2_shell.cmd -mingw64 -defterm -no-start -here -full-path

をターミナル起動時に実行するということです。

参考

Visual Studio Code 15.1の統合シェルをMSYS2のbashにする
MSYS2の更新に伴う起動用ショートカットの修正
Windows環境でVSCode+MSYSで快適に使う方法


  1. 32Bit版(i686)をお使いの方はC:\\msys64C:\\msys32に読み替えてください。 

  2. .bash_profile等はMSYS2のホームディレクトリから参照されます。 

  3. "-mingw64"の部分を"-mingw32"にすればMINGW32"-msys"にすればMSYS Shellが使えます。 

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4