加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 如何将MSYS2 shell集成到Window上的Visual Studio代码中

发布时间:2020-12-16 01:13:48 所属栏目:安全 来源:网络整理
导读:我试图将MSYS2 shell集成到Visual Studio Code集成终端中.这是我的用户设置: { "terminal.integrated.shell.windows": "C:msys64usrbinbash.exe","terminal.integrated.shellArgs.windows": ["--login","-i"]} 但是,我遇到了一个问题,其中–login将
我试图将MSYS2 shell集成到Visual Studio Code集成终端中.这是我的用户设置:
{
    "terminal.integrated.shell.windows": "C:msys64usrbinbash.exe","terminal.integrated.shellArgs.windows": ["--login","-i"]
}

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

我的进一步尝试是尝试添加标志-c’cd ${workspaceRoot}’.然而,bash会在开始时崩溃.我可以通过删除–login来正确访问当前目录,但是没有登录模式,所有其他shell命令(ls,cd等)都不可用.

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

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

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

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

编辑

原来的答案似乎在当时有用,但是当我尝试在VSCode中开始使用任务时,它显然无法正常工作.尝试运行一个简单调用make all的任务会导致以下错误:

/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)但是在错误的目录中启动,并且“终端” .integrated.shellArgs.windows“:[” – “”,“cd $OLDPWD; exec bash”]使用正确的环境在正确的目录中启动但无法运行任务.

我想出了迄今为止似乎工作正常的解决方案.
在VSCode设置中:

"terminal.integrated.shell.windows": "C:msys64usrbinbash.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读