VS Code 配置 MSYS2 作为终端默认 shell

作者:海云青飞

编辑 VS Code user settings.json

  • 点击 VS Code 右上角 ...
  • 点击 Configure Editors

或者使用快捷键 Ctrl + ,

添加或更新(搜索) terminal.integrated.profiles.windows 配置

如下设置:

        "MSYS":
        {
            "path": "cmd.exe",
            "args": [
                "/c",
                // -msys 必须小写,否则报错
                "C:/Users/tuenhai.com/scoop/apps/msys2/current/msys2_shell.cmd -defterm -here -no-start -use-full-path -msys"
            ],

            // another way
            //"path": "C:/Users/tuenhai.com/scoop/apps/msys2/current/usr/bin/bash.exe",
            //"args": ["--login", "-i"],

            "env":
            {
                "CHERE_INVOKING": "1",
                "MSYSTEM": "MSYS",
                //  不起作用
                //"MSYS2_PATH_TYPE": "inherit"
                // 不起作用
                //"PATH": "/custom;/usr/bin;/mingw64/bin;${env:PATH}"
            },
            "color": "terminal.ansiMagenta"
        }
    },
    "terminal.integrated.defaultProfile.windows": "MSYS",

    //"terminal.integrated.shellArgs.windows": [
    //    "--login"
    //],
    "terminal.integrated.cursorStyle": "line",

海云青飞 注:

  • 如果已经在 Msys2 ~/.bash_profile~/.bashrc 中设置了 PATH

    举例

    ~/.bashrc:

    user=/c/Users/tuenhai.com
    
    PATH=${user}/bin:$PATH
    

    如上设置后,启动 VS Code,在 MSYS shel 中打印 PATH:

    echo $PATH
    

    输出以 /c/Users/tuenhai.com/bin 开头,后面还包括系统环境变量的 PATH

Explantion

  • CHERE_INVOKING

    For flags that decide whether to set the working directory to the path of environment variable $HOME when logging in to bash, setting it to 1 prevents movement

  • terminal.integrated.shellArgs.windows

    Passing --login, -l will same effect

    To summarize, if you do not pass -l or --login, ~/.Bash_profile will not be loaded

  • terminal.integrated.cursorStyle

    Specify the style of cursor of terminal, "line" or "block", The default is "block"

相关内容

2024-09-15


独立思考最难得,赞赏支持是美德!(微信扫描下图)