如何将MSYS2 shell集成到Windows上的Visual Studio Code?

39

我尝试将MSYS2 shell集成到Visual studio Code的终端中。这是我的用户设置:

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

然而,我遇到了一个问题,--login 会将当前工作目录更改为Windows主目录。我希望当前目录在我的工作区根目录。

我进一步尝试添加一个标志 -c 'cd ${workspaceRoot}'。但是,bash 会在启动时崩溃。如果删除 --login,可以正确地获得当前目录,但是没有登录模式,所有其他 shell 命令(如lscd等)都不可用。

如何正确地将 MSYS2 shell 集成到我的 vscode 中?


1
对于所有查看答案的人:自2021年4月以来,用于terminal.integrated.shell.windows的设置已经指向terminal.integrated.profiles.windows - Abel Cheung
12个回答

0
在你的settings.json文件中,你可以输入以下内容:
"terminal.integrated.profiles.windows": {
    "MSYS2 CLANG64": {
      "path": ["C:\\msys64\\usr\\bin\\bash.exe"],
      "args": ["-l"],
      "env": { "MSYSTEM": "CLANG64" },
      "overrideName": true
    },
    "MSYS2 CLANG32": {
      "path": ["C:\\msys64\\usr\\bin\\bash.exe"],
      "args": ["-l"],
      "env": { "MSYSTEM": "CLANG32" },
      "overrideName": true
    },
    "MYSYS2 MINGW64": {
      "path": ["C:\\msys64\\usr\\bin\\bash.exe"],
      "args": ["-l"],
      "env": { "MSYSTEM": "MINGW64" },
      "overrideName": true
    },
    "MYSYS2 MINGW32": {
      "path": ["C:\\msys64\\usr\\bin\\bash.exe"],
      "args": ["-l"],
      "env": { "MSYSTEM": "MINGW32" },
      "overrideName": true
    }
  }

0

按 F1 + 编写 settings.json, 然后在 {} 末尾添加以下行:

"terminal.integrated.shell.windows": "C:\\msys32\\msys2_shell.cmd",
"terminal.integrated.shellArgs.windows": ["-defterm", "-mingw32", "-no-start", "-here"],

它看起来会像这样:(显然,settings.json 可能与下一个示例不同)
"telemetry.enableTelemetry": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.runInTerminal": true,
"liveshare.audio.startCallOnShare": true,
"window.zoomLevel": 1,
"explorer.confirmDelete": false,
"C_Cpp.updateChannel": "Insiders",

"terminal.integrated.shell.windows": "C:\\msys32\\msys2_shell.cmd",
"terminal.integrated.shellArgs.windows": ["-defterm", "-mingw32", "-no-start", "-here"]
请注意,在粘贴建议的代码行前,必须添加逗号 ","。

请注意,尽管此答案可以成功地从 vscode 集成终端中启动基本的 msys2/mingw shell,但在需要激活 python venv 时可能无法正常工作。对于使用 venv 的 python 项目,我需要直接启动 bash.exe - Abel Cheung

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接