1. msys2 zsh on-my-zsh git vim shell winpty

  • 进入msys2官网,安装msys2
  • 修改源
  • 使用pacman安装zsh git vim winpty
pacman -Sy zsh git vim winpty
  • 安装oh-my-zsh–>修改【6. 配置home路径为windows用户目录】后执行安装

2. 修改C:\msys64\msys2_shell.cmd

  • 修改set "LOGINSHELL=zsh"
  • 取消注释set MSYS=winsymlinks:nativestrict
  • 取消注释set MSYS2_PATH_TYPE=inherit
set "LOGINSHELL=zsh"
set /a msys2_shiftCounter=0

rem To activate windows native symlinks uncomment next line
set MSYS=winsymlinks:nativestrict

rem Set debugging program for errors
rem set MSYS=error_start:%WD%../../mingw64/bin/qtcreator.exe^|-debug^|^<process-id^>

rem To export full current PATH from environment into MSYS2 use '-use-full-path' parameter
rem or uncomment next line
set MSYS2_PATH_TYPE=inherit

3. 修改~/.zshrc配置,winpty解决ping输出乱码问题

alias ping="/bin/winpty ping"
alias netstat="/bin/winpty netstat"
alias nslookup="/bin/winpty nslookup"
alias open="shell"

4. 解决on-my-zsh打开git目录卡顿、慢的问题

git config --global --add on-my-zsh.hide-dirty 1
git config  --global --add on-my-zsh.hide-status 1

取消置为1

5. 解决vscode源码管理器git不工作问题

  • 在/usr/bin/下面新建git-vscode.bat
@echo off
setlocal

rem If you don't add path for msys2 into %PATH%, enable following line.
set PATH=c:\msys64\usr\bin;%PATH%

if "%1" equ "rev-parse" goto rev_parse
git %*
goto :eof
:rev_parse
for /f %%1 in ('git %*') do cygpath -w %%1% 
  • 修改setting.json
"git.path": "c:/msys64/usr/bin/git-vscode.bat",
"terminal.integrated.shell.windows": "C:\\msys64\\msys2_shell.cmd",
"terminal.integrated.shellArgs.windows": [
    "-defterm", "-mingw64", "-no-start", "-here", "-lic", "cd $PWD; exec zsh"
],
  • 重启vscode

6. 配置home路径为windows用户目录

  • 修改/etc/nsswitch.conf
db_home: windows

7. 创建快捷方式

  • 右键新建快捷方式
C:\Windows\System32\cmd.exe /c C:\msys64\msys2_shell.cmd

8. Microsoft store 安装 Windows Terminal,配置 msys2

// 修改defaultProfile为msys2 guid
"defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6301}",

"profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [

// 添加msys2 start

            {
                // Make changes here to the powershell.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6301}",
                "name": "MSYS2",
                "commandline": "C:\\msys64\\msys2_shell.cmd -msys -defterm -no-start",
                "hidden": false,
                "fontSize":16,
                "tabTitle": "MSYS2",
                "colorScheme":"Campbell",
                "startingDirectory":"%userprofile%",
                "suppressApplicationTitle":true
            },
// 添加msys2 end