Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

bash - How do I integrate MSYS2 shell into Visual studio code on Window?

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"]
}

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.

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.

How do I properly integrate MSYS2 shell into my vscode?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To inhibit the working directory change from your current directory, set the CHERE_INVOKING environment variable to a non-empty value:

    "terminal.integrated.env.windows": {
        "CHERE_INVOKING": "1"
    },

In MSYS login scripts, setting the CHERE_INVOKING variable serves only to prevent a shell from doing a cd "${HOME}", and nothing else.

If you require a MinGW toolchain, set the MSYSTEM environment variable to select a toolchain. Recognized values are MSYS (default), MINGW32 or MINGW64.

    "terminal.integrated.env.windows": {
        "MSYSTEM": "MINGW64",
    },

In full, the VS Code settings might look like so:

{
    "terminal.integrated.shell.windows": "C:\msys64\usr\bin\bash.exe",
    "terminal.integrated.shellArgs.windows": [
        "--login",
    ],
    "terminal.integrated.env.windows": {
        "CHERE_INVOKING": "1",
        "MSYSTEM": "MINGW64",
    },
}

To provide some context on the very cryptic nomenclature of CHERE_INVOKING: chere is apparently a Cygwin command for installing and managing a "Command Prompt Here" folder context menu item. Although MSYS2 inherits the environment variable from Cygwin, it doesn't actually inherit the command itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...