将MSYS添加到Windows终端

6
我通过编辑settings.json文件,将bash添加到Windows终端中。当我尝试编译一个简单的C++程序时,它会抛出一个错误,提示未检测到gcc或g++。 如何正确地添加MSYS bash终端,以便我可以从Windows终端编译文件。
在settings.json中,我添加了bash shell的路径,如下所示:
{
  "commandline": "powershell.exe",
  "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
  "hidden": false,
  "name": "Windows PowerShell"
},
{
  "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
  "hidden": false,
  "name": "Azure Cloud Shell",
  "source": "Windows.Terminal.Azure"
},
{
  "commandline": "C:\\msys64\\usr\\bin\\bash.exe -i -l",
  "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
  "hidden": false,
  "name": "msys2"
},
{
  "guid": "{495d29da-4bfb-4956-abd8-ed1760703232}",
  "commandline": "cmd.exe",
  "hidden": false,
  "name": "cmd.exe"
}

1
当您在终端之外运行msys时,编译器的路径是什么?当您在Windows终端内运行时,该目录是否仍在PATH上?您可能需要参考此文档,其中介绍了git bash和msys2之间的一些细微差别。 - zadjii
路径与下载的路径相同:C:\msys64\... - RAT
相关链接:SuperUser: 在MSYS2上更改默认shell - undefined
2个回答

9

我建议去查看文档,但这是我的MSYS编辑版本:

{
    "commandline": "C:\\msys64\\msys2_shell.cmd -defterm -here -no-start -mingw64 -shell bash",
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "hidden": false,
    "name": "msys2"
}

使用PowerShell中的New-Guid命令来创建新的GUID。


7

从头开始安装和设置MSYS2,包括将所有7个配置文件添加到Windows终端

在2023年10月31日,作为一份恐怖的礼物,测试了最新版本的MSYS2(msys2-x86_64-20231026.exe)从https://www.msys2.org/下载,在Windows 11上运行。

作为一个更适合初学者、更详细和定制化的版本,这里提供了我和其他初学者肯定需要的额外细节。

请注意,MSYS2包括MinGW-w64和Pacman软件包管理器,是一个功能强大的类Linux终端和Windows下的GCC和LLVM(clang)构建环境。它类似于Cygwin,而Git for Windows中的Git Bash使用了MSYS2 mingw64环境。然而,MSYS2经过优化用于构建软件,所以对于使用Git,他们建议您单独安装和使用Git for Windows的Git Bash。因此,您可以将常规的MSYS2视为本地的Windows构建环境,而将Git Bash视为基于MSYS2的本地Windows git和开发环境。

MSYS2有点像在Windows内部运行的轻量级Linux版本。与WSL(Windows子系统Linux)相比,WSL是在Windows上运行的Linux,而MSYS2有一个巨大的限制:来自https://www.msys2.org/docs/what-is-msys2/(强调添加):

MSYS2允许您构建本机Windows程序,而使用WSL只能进行交叉编译,这使得事情更加复杂。

所以:

从Git Bash中,你可以在Windows本机上运行git命令。
从MSYS2 UCRT64(或类似的)终端中,你可以在Windows本机上运行gcc构建命令。例如:从我的eRCaGuy_hello_world存储库中的https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world/blob/master/c/hello_world_extra_basic.c#L24这样:
gcc -Wall -Wextra -Werror -O3 -std=gnu17 hello_world_extra_basic.c -o bin/a -lm && bin/a

从WSL(Windows子系统)中,你可以在Windows中拥有真正的Linux环境。前两个是Windows中的类Linux环境。WSL是真正的Linux环境在Windows中。

添加到Windows终端的所有7个MSYS2配置文件描述

以下是7种MSYS2的shell/环境类型:

  1. msysmsys2(现在是同一个东西)- 基本的MSYS2工具;以下所有其他环境都继承自此环境;包含GCC 64位编译器和Cygwin C库
  2. mingw32 - 适用于Windows 32位的精简GNU;包含GCC 32位编译器
  3. mingw64 - 适用于Windows 64位的精简GNU;包含GCC 64位编译器
  4. ucrt64 - 适用于Windows 64位的UCRT(通用C运行时库);包含GCC 64位编译器;MSYS2 表示:“如果不确定,请选择UCRT64 [这个]”。也请参阅此评论。默认仅适用于Windows 10或更高版本。
  5. clang64 - 包含LLVM/Clang 64位编译器
  6. clang32 - 包含LLVM/Clang 32位编译器
  7. clangarm64 - 包含LLVM/Clang 64位ARM(AArch64)编译器

来自: https://www.msys2.org/docs/environments/:

enter image description here

也来自https://www.msys2.org/docs/environments/(强调添加):
引用: MSYS2带有不同的环境,你首先要决定使用哪一个。这些环境之间的区别主要体现在环境变量、默认编译器/链接器、架构、使用的系统库等方面。如果你不确定,选择UCRT64环境。 MSYS环境始终处于活动状态。所有其他环境都继承自MSYS环境,并在其基础上添加各种功能。
例如,在UCRT64环境中,$PATH变量以/ucrt64/bin:/usr/bin开头,因此你可以使用所有基于ucrt64的工具以及所有msys工具。
活动环境通过MSYSTEM环境变量进行选择。将MSYSTEM设置为UCRT64并启动登录shell,你将进入该环境。
有关GCC vs LLVM/Clang和MSVCRT vs UCRT的详细信息,请参阅此处:https://www.msys2.org/docs/environments/

UCRT(通用C运行时)是较新的版本,也是Microsoft Visual Studio默认使用的版本。它应该能够像使用MSVC编译的代码一样工作和表现。

  • 它仅默认安装在Windows 10(或更高版本)上

主要参考资料:

  1. https://www.msys2.org/docs/what-is-msys2/

    MSYS2与WSL的区别

    MSYS2允许您构建本机的Windows程序,而使用WSL只能进行交叉编译,这使得事情变得更加复杂。

  2. https://www.msys2.org/docs/environments/ - 非常有用!

  3. https://www.msys2.org/docs/who-is-using-msys2/

    Git for Windows基于MSYS2

在Windows Terminal中设置所有7个MSYS2 shell/环境

  1. Download and install the latest version of MSYS2.

    1. You can get it here: https://www.msys2.org/.
  2. Ensure Windows Terminal is installed. If you have Windows 11 or later, it's already installed. If you have Windows 10 or older, you'll need to manually install Windows Terminal from the Microsoft Store, here: https://apps.microsoft.com/detail/9N0DX20HK701?hl=en-zm&gl=ZM

  3. Open Windows PowerShell and run New-Guid 7 times, one for each MSYS2 profile entry we will create below. Copy and paste the numbers out into a text editor. You'll need these numbers later. Example: here are my generated GUID numbers:

    6f0ee3d1-ac4f-48ca-bcf5-a9795f9942d2
    80414396-5ef4-490b-af88-29600c19ca4a
    aef16ae0-7dd1-4ac7-abd8-60a646abb9ca
    a718a3d5-9e77-4d0d-b7b6-69ec3d190206
    1f2869c0-1310-403b-93a7-9227f42eeb24
    10c96d8f-9e6b-48f6-8f59-034c586d7e57
    ada1f939-0f7b-400c-b755-8cbff4fd40a8
    
  4. Open Windows Terminal, and add 7 new MSYS2 profile entries:

    Open Windows Terminal.

    Then, click the little drop-down arrow at the top-right of the open tab, and select "Settings" --> in the Settings tab that opens up, click "Open JSON file" in the bottom-left, as shown here:

    enter image description here

    In the JSON settings file that opens up, look for the "profiles" section in the JSON file:

    "profiles":
    {
        "defaults": {},
        "list":
        [
            // ...
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },  // <=== add this comma here!
    
            // new profile entries go here! <=====
        ]
    },
    

    Here, we will add 7 new MSYS2 profiles. Use a unique GUID from your previously-generated list above for each entry. Be sure to add a comma at the end of the last pre-existing profile entry above.

    Here are my new entries in the JSON "profiles" list above. Your GUIDs should be different, based on what you generated above (I actually don't know if yours need to be different from mine; I just know each entry needs a unique GUID one from another). Ensure you put a comma after each entry, including adding a comma after the ending } of the last entry just above. Notice the Linux-like forward slashes in the paths.

    My 7 new MSYS2 profiles:

    "profiles":
    {
        "defaults": {},
        "list":
        [
            // ============================
            // previous profiles above here
            // ============================
    
            // -msys and -msys2 (same thing now: both options run msys2)
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -msys2 -shell bash",
                "guid": "{6f0ee3d1-ac4f-48ca-bcf5-a9795f9942d2}",
                "hidden": false,
                "name": "MSYS2: msys2",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/msys2.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -mingw32
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw32 -shell bash",
                "guid": "{80414396-5ef4-490b-af88-29600c19ca4a}",
                "hidden": false,
                "name": "MSYS2: mingw32",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/mingw32.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -mingw64
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64 -shell bash",
                "guid": "{aef16ae0-7dd1-4ac7-abd8-60a646abb9ca}",
                "hidden": false,
                "name": "MSYS2: mingw64",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/mingw64.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -ucrt64 (recommended default)
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell bash",
                "guid": "{a718a3d5-9e77-4d0d-b7b6-69ec3d190206}",
                "hidden": false,
                "name": "MSYS2: ucrt64 (recommended default)",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/ucrt64.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -clang64
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -clang64 -shell bash",
                "guid": "{1f2869c0-1310-403b-93a7-9227f42eeb24}",
                "hidden": false,
                "name": "MSYS2: clang64",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/clang64.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -clang32
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -clang32 -shell bash",
                "guid": "{10c96d8f-9e6b-48f6-8f59-034c586d7e57}",
                "hidden": false,
                "name": "MSYS2: clang32",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/clang32.ico",
                "font": 
                {
                    "size": 10
                }
            },
    
            // -clangarm64
            {
                "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -clangarm64 -shell bash",
                "guid": "{ada1f939-0f7b-400c-b755-8cbff4fd40a8}",
                "hidden": false,
                "name": "MSYS2: clangarm64",
                // "startingDirectory": "C:/msys64/home/%USERNAME%", // alternative
                "startingDirectory": "%USERPROFILE%", // ie: C:\Users\my_username
                "icon": "C:/msys64/clangarm64.ico",
                "font": 
                {
                    "size": 10
                }
            },
    

    Copy and paste those 7 new profiles above into the correct location in your Windows Terminal JSON settings file.

    Save the JSON file, and close it.

  5. How to change your default shell:

    Note that if you want to use another shell, such as fish or zsh, you can use -shell fish or -shell zsh instead of -shell bash in the profile commands above. See here: https://www.msys2.org/docs/terminals/. If you aren't sure, stick with -shell bash.

  6. Back in Windows Terminal, click the little drop-down arrow at the top right of your tabs at the top. You'll now see these 7 new MSYS2 entries you just added!:

    enter image description here

  7. Click each one to test it, and ensure they all run.

  8. Choose an MSYS2 environment as your default Windows Terminal profile:

    Click the little drop-down arrow to the right of the tabs at the top, and go to "Settings" again --> choose the "Startup" tab on the left.

    Change the "Default profile" --> "MSYS2: ucrt64 (recommended default)".

    Turn "Launch on machine startup" to "On".

    Change "When Terminal starts" to "Open windows from a previous session".

    Click "Save".

    Here are what my Windows Terminal "Startup" settings looks like:

    enter image description here

  9. Change your HOME (~) dir from MSYS2's default of C:\msys64\home\my_username to your regular Windows home dir of C:\Users\my_username:

    Open up C:\msys64\home\my_username\.bash_profile in a text editor, such as VSCode. Modify it so that it looks like this. Note: you can just comment everything out with # and add this to the top:

    # Change your home (`~`) dir to `C:\Users\my_username`
    HOME="/c/Users/$(whoami)"
    
    # Source your `C:\Users\my_username\.profile` file, if it exists
    if [ -f "$HOME/.profile" ]; then
        . "$HOME/.profile"
    fi
    

    Close and re-open Windows Terminal. Run echo ~ and echo "$HOME" and ensure they now both show /c/Users/my_username. Run ls -a and ensure you see the contents of your normal Windows home directory for your user. pwd should show that you are currently in that directory too, since we set this via "startingDirectory": "%USERPROFILE%", in the JSON file above.

  10. Install Ubuntu's default ~/.profile and ~/.bashrc files:

    Now, create a C:\Users\my_username\.profile file, if you don't already have one, and put the entire contents of this default Ubuntu ~/.profile file into it, from my repo: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/etc/skel/.profile

    If you don't have ~/.profile file yet, the easiest way to do that is to open up your MSYS2: ucrt64 terminal and run the following:

    cd ~
    
    # download Ubuntu's default ~/.profile file
    wget https://raw.githubusercontent.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/master/etc/skel/.profile
    
    # we might as well get the ~/.bash_logout file too
    wget https://raw.githubusercontent.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/master/etc/skel/.bash_logout
    

    Now, go here for Ubuntu's default ~/.bashrc file: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/etc/skel/.bashrc. Copy and paste the entire contents of this file into the top of your ~/.bashrc file.

    Put a nice # ================== END OF UBUNTU'S DEFAULT ~/.bashrc FILE ==================== marker into the end of your ~/.bashrc file, and add any custom entries you want below that.

  11. IMPORTANT: we do not want to remove the UCRT64 and MINGW64 type entries from our PS1 Prompt String 1 variables (which appear in the terminal before each line where you type), because we like seeing these important markers in our prompt, to remind us which MSYS2 shell we are in. So, go into your ~/.bashrc file and comment out all changes that Ubuntu does to the PS1 variable, like this:

    Change this:

    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    fi
    unset color_prompt force_color_prompt
    
    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    esac
    

    ...to this. Notice that the PS1= changes are all commented out by doing this:

    # if [ "$color_prompt" = yes ]; then
    #     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    # else
    #     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    # fi
    unset color_prompt force_color_prompt
    
    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        # PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    esac
    
  12. IMPORTANT: we do not want to accidentally override any really important system calls or build commands, such as make.

    Go into your ~/.bashrc and ~/.profile files and search for anything silly, like overriding the make command. I had this in my ~/.bashrc file from some earlier hacks:

    alias make="'/c/Program Files/Microchip/MPLABX/v6.10/gnuBins/GnuWin32/bin/make.exe'"
    

    Don't do that! That could mess up everything when trying to build software in your MSYS2 terminals! Delete or comment out such nonsense, like this:

    # alias make="'/c/Program Files/Microchip/MPLABX/v6.10/gnuBins/GnuWin32/bin/make.exe'"
    
  13. Now, close and re-open all Windows terminal windows, or run . ~/.profile in each one to re-source your ~/.profile file.

    If you don't know what "re-sourcing" means, read my answer here: source (.) vs export (and also some file lock [flock] stuff at the end).

    Run alias to see all of your aliases. Look for any silly aliases you don't want, and delete or comment them out from your ~/.bashrc or ~/.profile files if necessary. Again, I had a ridiculous make alias (see above) ruining everything!

    Also run echo "$PATH" to look for any silliness in your PATH that shouldn't be there. If you haven't been modifying your PATH before, it should be fine.

  14. Test your new, beautiful Ubuntu settings: run ll and you'll see this alias now works! It is an alias for ls -alF, and comes from your ~/.bashrc file now.

  15. Update MSYS2:

    time pacman -Suy
    

    Choose yes (y) if there are packages to upgrade.

    Source: https://www.msys2.org/docs/updating/

  16. Install GCC into the MSYS2 UCRT64 environment:

    pacman -S mingw-w64-ucrt-x86_64-gcc
    # Press Enter or type Y then Enter to continue
    
    # Check the gcc version to ensure it installed correctly
    # Example output: `gcc.exe (Rev2, Built by MSYS2 project) 13.2.0`
    gcc --version
    

    Source:

    I learned this from the "Getting Started" content right on the home page of the MSYS2 project, here: https://www.msys2.org/.

  17. Install VSCode and add the code executable into your PATH:

    Install VSCode from here, if you don't already have it: https://code.visualstudio.com/

    The code executable is found in the "$HOME/AppData/Local/Programs/Microsoft VS Code/bin" dir.

    Add it to your PATH by adding this line to the bottom of your ~/.bashrc file:

    DIR="$HOME/AppData/Local/Programs/Microsoft VS Code/bin"
    if [ -d "$DIR" ] ; then
        PATH="$DIR:$PATH"
    fi
    

    Close and re-open all terminals, or run . ~/.profile in each one to re-source your ~/.profile and ~/.bashrc files.

    Now run code . in a terminal and it will open up a new instance of VSCode in your current directory. Now we're rockin'.

  18. Install and configure git:

    This is beyond the scope of this answer, but oddly enough, MSYS2 currently recommends you install and use Git For Windows and Git Bash (based on MSYS2) instead of trying to install git within MSYS2: https://www.msys2.org/docs/git/

    So, here are some links to resources I've created to help you install Git for Windows / Git Bash:

    1. Installing Git For Windows: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/issues/27#issue-1950880578
    2. Adding Git-Bash to the new Windows Terminal
    3. Running SSH Agent when starting Git Bash on Windows
    4. Python not working in the command line of git bash

    At a minimum: install Git for Windows. Then, add this to the bottom of your ~/.bashrc file to give your MSYS2 environments the most basic of git usage and access:

    alias git="$HOME/AppData/Local/Programs/Git/bin/git.exe"
    

    Close and re-open all terminals, or run . ~/.profile to re-source your ~/.profile and ~/.bashrc files, and your MSYS2 environments can now run this:

    git --version
    # I see: `git version 2.42.0.windows.2`
    
  19. Now that you have MSYS2 installed and working, your Windows computer is much more useful and functional!

    But, since I can't easily install git into MSYS2, I guess I'll still be using separate terminals: MSYS2 terminals for building, and the Git Bash terminal for git.

    What a pain Windows is. Just wipe it and install Linux Ubuntu. Linux Ubuntu is the only OS installed on most of my computers, including for my kids. :)

附加的MSYS2配置注意事项

@Weed Cookie的回答对我很有帮助。它向我展示了如何使用PowerShell生成GUID,并如何使用-shall bash指定shell。

这份MSYS2文档是最有用的:https://www.msys2.org/docs/terminals/。它向我展示了如何使用-ucrt64-msys2等来指定命令行、图标、字体、起始目录和"shell类型"。

我知道有3个地方可以看到这7个MSYS2环境的存在。对我来说,这并不容易找到。这里是它们:

打开文本编辑器,打开"C:\msys64\msys2_shell.cmd" Windows批处理文件,并查找以下行:
rem Shell types if "x%~1" == "x-msys" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams if "x%~1" == "x-msys2" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams if "x%~1" == "x-mingw32" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW32& goto :checkparams if "x%~1" == "x-mingw64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW64& goto :checkparams if "x%~1" == "x-ucrt64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=UCRT64& goto :checkparams if "x%~1" == "x-clang64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANG64& goto :checkparams if "x%~1" == "x-clang32" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANG32& goto :checkparams if "x%~1" == "x-clangarm64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANGARM64& goto :checkparams if "x%~1" == "x-mingw" shift& set /a msys2_shiftCounter+=1& (if exist "%WD%..\..\mingw64" (set MSYSTEM=MINGW64) else (set MSYSTEM=MINGW32))& goto :checkparams
在这些行中,我们看到了上面列出的7种shell类型。可以看到x-msysx-msys2是一样的,因为它们都调用了set MSYSTEM=MSYSx-mingw是一个特殊情况,因为它检查mingw64目录是否存在,如果存在,则设置MSYSTEM=MINGW64;否则设置MSYSTEM=MINGW32
如果在命令提示符中运行C:\msys64\msys2_shell.cmd --help,您会看到以下内容:
C:\>.\msys64\msys2_shell.cmd --help Usage: msys2_shell.cmd [options] [login shell parameters]
Options: -mingw32 | -mingw64 | -ucrt64 | -clang64 | -msys[2] Set shell type -defterm | -mintty | -conemu Set terminal type -here Use current directory as working directory -where DIRECTORY Use specified DIRECTORY as working directory -[use-]full-path Use full current PATH variable instead of trimming to minimal -no-start Do not use "start" command and return login shell resulting errorcode as this batch file resulting errorcode -shell SHELL Set login shell -help | --help | -? | /? Display this help and exit
Any parameter that cannot be treated as valid option and all following parameters are passed as login shell command parameters.
注意,“shell type”选项是-mingw32-mingw64-ucrt64-clang64-msys[2]。其中-msys[2]表示您可以使用-msys-msys2来指定MSYS2 shell类型。但是,它们缺少两种类型:-clang32-clangarm64!因此,唯一查看这些类型的方法是查看C:\msys64\msys2_shell.cmd批处理文件本身,而不是查看其帮助菜单。
如果您查看C:\Users\my_username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\MSYS2,您会看到以下6个开始菜单项:
'MSYS2 CLANG64.lnk' 'MSYS2 CLANGARM64.lnk' 'MSYS2 MINGW32.lnk' 'MSYS2 MINGW64.lnk' 'MSYS2 MSYS.lnk' 'MSYS2 UCRT64.lnk'
再次,它们缺少一个类型:clang32。
您可以在C:\msys64中看到所有7个.exe可执行文件。
MSYS2: ucrt64命令行中可以看到所有7个可执行文件: ls -1 /c/msys64/*.exe 输出:
/c/msys64/clang32.exe /c/msys64/clang64.exe /c/msys64/clangarm64.exe /c/msys64/mingw32.exe /c/msys64/mingw64.exe /c/msys64/msys2.exe /c/msys64/ucrt64.exe /c/msys64/uninstall.exe 您还可以在线查看并在此表中看到所有7个类型:https://www.msys2.org/docs/environments/

其他参考资料

  1. Windows命令提示符中代替~(用户主目录)的方法是什么? - 答案:使用%USERPROFILE%%HOMEDRIVE%%HOMEPATH%(参见我的评论
  2. 奇怪的是:尽管Git Bash基于MSYS2,但你不能轻松地将git安装到MSYS2中。实际上,MSYS2建议你安装Git for Windows并使用Git Bash:https://www.msys2.org/docs/git/

实验性

在安装Git for Windows之后,尝试在各种MSYS2环境中使git正常工作:

add_git_paths()
{
    # NB: add these paths to the END of the existing path, NOT the beginning.
    # - ie: use `PATH="$PATH:$DIR"`, NOT `PATH="$DIR:$PATH"`.
    # - These paths contain `git` and other executables from Git Bash from Git 
    #   for Windows, and although I want access to them, I do NOT want them to
    #   override other executables with the same name which are already provided
    #   directly by MSYS2.

    DIR="$HOME/AppData/Local/Programs/Git/mingw64/bin"
    if [ -d "$DIR" ] ; then
        PATH="$PATH:$DIR"
    fi

    DIR="$HOME/AppData/Local/Programs/Git/usr/bin"
    if [ -d "$DIR" ] ; then
        PATH="$PATH:$DIR"
    fi
}

add_git_paths

更安全:
alias git="$HOME/AppData/Local/Programs/Git/bin/git.exe"

待办事项

  1. [ ] 将chocolatey/ripgrep (/c/ProgramData/chocolatey/bin)的bin目录添加到MSYS的PATH环境变量中。这将使我能够使用rg命令。
  2. [ ] 将meld (/c/Program Files/Meld/meld)添加到MSYS的PATH环境变量中。

另请参阅

我在其他回答中提到或引用了这个答案的链接: 1. [如何在MSYS2上更改HOME目录和启动目录?](link1) 2. [Super User:如何更改我的MinGW/MSYS + mintty的主目录?](link2) 3. [Super User:MinGW Bash配置文件](link3) 4. [在Windows的终端/命令提示符中,VSCode的`code .`命令无法工作](link4) 5. [Super User:在MSYS2上更改默认shell](link5)
关于选择七个MSYS2环境的更多指导,请参考:[链接6](link6)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接