如何将 MSYS2 shell 集成到 Window 上的 Visual Studio 代码中? [英] How do I integrate MSYS2 shell into Visual studio code on Window?

查看:28
本文介绍了如何将 MSYS2 shell 集成到 Window 上的 Visual Studio 代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to integrate MSYS2 shell into Visual studio Code integrated terminal. Here's my user settings:

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

但是,我遇到了一个问题,--login 将当前工作目录更改为 Windows 主目录.我希望当前目录位于我的工作区的根目录下.

However, I ran into a problem where --login changes the current working directory to Windows home. I want the current directory to be at the root of my workspace.

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

My further attempt was I tried add a flag -c 'cd ${workspaceRoot}'. However, the bash would crashed on start. I could properly get to current directory by removing --login, but without login mode, all other shell command (ls, cd, etc) are not available.

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

How do I properly integrate MSYS2 shell into my vscode?

推荐答案

原创但不工作 100%(接受为答案)

这将正确启动 MSYS2 bash shell,以便您的 .bash_login 被执行:

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

编辑

最初的答案当时似乎有效,但是当我尝试在 VSCode 中开始使用任务时,它显然不起作用.尝试运行一个简单地调用 make all 的任务会导致以下错误:

Edit

The original answer seemed to work at the time, but when I tried to start using tasks in VSCode it was clearly not working. Trying to run a task that simply called make all caused the following error:

/usr/bin/bash:/d: 没有那个文件或目录
终端进程以退出代码终止:127

/usr/bin/bash: /d: No such file or directory
The terminal process terminated with exit code: 127

从其他答案中,使用 "terminal.integrated.shellArgs.windows": ["--login", "-i"] 获得了几乎正确的环境(MSYS 而不是 MINGW64)但在错误的目录中启动,并且 "terminal.integrated.shellArgs.windows": ["-lic", "cd $OLDPWD; exec bash"] 以正确的环境在正确的目录中启动,但是无法运行任务.

From the other answers, using "terminal.integrated.shellArgs.windows": ["--login", "-i"] got the almost the correct environment (MSYS instead of MINGW64) but started in the wrong directory, and "terminal.integrated.shellArgs.windows": ["-lic", "cd $OLDPWD; exec bash"] started in the correct directory with the correct environment but could not run tasks.

我想出了这个到目前为止似乎工作正常的解决方案.
在 VSCode 设置中:

I came up with this solution that so far seems to work fine.
In VSCode settings:

"terminal.integrated.shell.windows": "C:\msys64\usr\bin\bash.exe",
"terminal.integrated.env.windows":
{
    "MSYSTEM": "MINGW64",
    //"MSYS2_PATH_TYPE": "inherit",
    "MSVSCODE": "1"
},

.bashrc 中:

if [ ! -z "$MSVSCODE" ]; then
    unset MSVSCODE
    source /etc/profile
    cd $OLDPWD
fi

这篇关于如何将 MSYS2 shell 集成到 Window 上的 Visual Studio 代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆