全面切换到MSYS2

全面切换到MSYS2

最近折腾了下在Windows下编译mosh,发现MSYS2真是个不错的东东,连mosh的native包都有……。慎重考虑下,打算全面切换到MSYS2,不再使用Git for Windows提供的Git Bash了。

1、Kerberos配置

$KerberosInstalled = (Test-Path -Path "C:\ProgramData\MIT\Kerberos5" -PathType Container)
$MSYS2Installed = (Test-Path -Path "C:\Software\msys64\etc\krb5" -PathType Container)
if ($KerberosInstalled) {
    New-Item -Path "C:\ProgramData\MIT\Kerberos5\krb5.ini" -ItemType SymbolicLink -Value "$env:UserProfile\OneDrive\Windows\WSL\krb5.ini" -Force
    SETX KRB5CCNAME "API:Initial default ccache"
}

if ($MSYS2Installed) {
    New-Item -Path "C:\Software\msys64\etc\krb5\krb5.conf" -ItemType SymbolicLink -Value "$env:UserProfile\OneDrive\Windows\WSL\krb5.ini" -Force
}

if ($MSYS2Installed -And $KerberosInstalled) {
    New-Item -Path "C:\Software\msys64\usr\lib\libkrb5_cc.dll" -ItemType SymbolicLink -Value "C:\Program Files\MIT\Kerberos\bin\krbcc64.dll" -Force
}

测试了下都没啥问题。

$ git pl
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 19 (delta 2), reused 19 (delta 2), pack-reused 0
展开对象中: 100% (19/19), 10.21 KiB | 82.00 KiB/s, 完成.

$ssh devbox
Linux n37-052-143 4.19.117.bsk.12-amd64 #4.19.117.bsk.12 SMP Debian 4.19.117.bsk.12 Thu Mar 17 16:41:16  x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

2、添加到Windows Terminal

启动命令行如下👇,其他随意

C:\Software\msys64\msys2_shell.cmd -here -full-path -ucrt64 -defterm -no-start

3、修改HOME路径

在/etc/fstab中加一行

##################################################################
# Canonicalize the two home directories by mounting the windows  #
# user home with the same path mapping as unix.                  #
##################################################################
C:/Users/lifei /home/lifei ntfs binary,posix=0,noacl,auto,user 0 0

4、pageant & /tmp

pageant默认的/tmp目录是Windows系统的临时目录,而MSYS2是自己搞了一个/tmp。这里也需要在/etc/fstab里映射一下。

$ cat /etc/fstab
# For a description of the file format, see the Users Guide
# https://cygwin.com/cygwin-ug-net/using.html#mount-table

# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
none /tmp usertemp binary,posix=0,noacl 0 0

还要记得安装一下ssh-pageant。

pacman -S ssh-pageant

5、VS Code

    "terminal.integrated.profiles.windows": {
        "MSYS2": {
            "icon": "terminal-bash",
            "path": "C:\\Software\\msys64\\msys2_shell.cmd",
            "args": [
                "-here",
                "-full-path",
                "-ucrt64",
                "-defterm",
                "-no-start"
            ]
        }
    },