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

查看:290
本文介绍了如何将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天全站免登陆