初始化msys2环境
准备工作
Git for Windows做了大量优化,所以这里直接借用Git for Windows的一些配置。我们首先安装Git for Windows。
安装msys2
从清华大学镜像源下载msys2软件包,并安装。
初始化msys2环境
在GitBash中执行下面的脚本,完成初始化配置。
readonly GIT_HOME=/d/env/git
readonly MSYS_HOME=/d/env/msys
readonly _USER=kehao
# wget https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/msys2-base-x86_64-20220904.tar.xz
# tar -xvf msys2-base-x86_64-20220904.tar.xz -C /d/env/
# mv /d/env/msys64 /d/env/msys
# pacman source
if [ 0 -eq "$(head -n8 $MSYS_HOME/etc/pacman.d/mirrorlist.mingw32 | grep -c 'tsinghua')" ]; then
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang32' >$MSYS_HOME/etc/pacman.d/mirrorlist.clang32
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang64' >$MSYS_HOME/etc/pacman.d/mirrorlist.clang64
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/$repo' >$MSYS_HOME/etc/pacman.d/mirrorlist.mingw
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686' >$MSYS_HOME/etc/pacman.d/mirrorlist.mingw32
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64' >$MSYS_HOME/etc/pacman.d/mirrorlist.mingw64
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch' >$MSYS_HOME/etc/pacman.d/mirrorlist.msys
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/ucrt64' >$MSYS_HOME/etc/pacman.d/mirrorlist.ucrt64
fi
$MSYS_HOME/usr/bin/bash.exe --login -i -c 'exit 0'
# git-prompt
cp $GIT_HOME/etc/profile.d/git-prompt.sh $MSYS_HOME/etc/profile.d/git-prompt.sh
if [ 0 -eq "$(grep -c 'git-prompt' $MSYS_HOME/etc/bash.bashrc)" ]; then
echo 'shopt -q login_shell || . /etc/profile.d/git-prompt.sh' >>$MSYS_HOME/etc/bash.bashrc
fi
# vimrc
if [ ! -f $MSYS_HOME/etc/vimrc ]; then
echo 'set mouse-=a' >>$MSYS_HOME/etc/vimrc
fi
# gitconfig
cp $GIT_HOME/etc/gitconfig $MSYS_HOME/etc/gitconfig
cp $GIT_HOME/etc/gitattributes $MSYS_HOME/etc/gitattributes
# profile
cp $MSYS_HOME/home/$_USER/.bashrc /c/Users/$_USER/.bashrc
cp $MSYS_HOME/home/$_USER/.bash_profile /c/Users/$_USER/.bash_profile
cp $MSYS_HOME/home/$_USER/.profile /c/Users/$_USER/.profile
cp $MSYS_HOME/home/$_USER/.inputrc /c/Users/$_USER/.inputrc
echo "alias ll='ls -lsh --color=auto'" >>/c/Users/$_USER/.bashrc
# env
if [ 0 -gt "$(grep -c 'MSYS2_PATH_TYPE:-minimal' $MSYS_HOME/etc/profile)" ]; then
sed -i 's/MSYS2_PATH_TYPE:-minimal/MSYS2_PATH_TYPE:-inherit/g' $MSYS_HOME/etc/profile
fi
# db_home
if [ 0 -eq "$(grep -c '#db_home' $MSYS_HOME/etc/nsswitch.conf)" ]; then
sed -i '/db_home/s/^/#&/' $MSYS_HOME/etc/nsswitch.conf
sed -i '/db_home/adb_home: windows' $MSYS_HOME/etc/nsswitch.conf
fi
# login start directory
if [ 0 -eq "$(grep -c 'CHERE_INVOKING=1' $MSYS_HOME/etc/profile)" ]; then
sed -i '/*.post/iCHERE_INVOKING=1' $MSYS_HOME/etc/profile
fi
# pacman -Sy
rm -f $MSYS_HOME/var/lib/pacman/sync/*
$MSYS_HOME/usr/bin/bash.exe --login -i -c 'update-ca-trust;pacman -Sy'
配置到Windows Terminal
终端配置
{
"colorScheme": "BlulocoDark",
"commandline": "D:\\env\\msys\\usr\\bin\\bash.exe --login -i",
"font":
{
"face": "Consolas",
"size": 16
},
"guid": "{c23bfc47-2148-4b58-a228-4edea4a6e08f}",
"hidden": false,
"icon": "D:\\env\\msys\\msys2.ico",
"name": "msys",
"opacity": 100,
"startingDirectory": "%USERPROFILE%"
}
颜色配置
{
"background": "#282C34",
"black": "#41444D",
"blue": "#3476FF",
"brightBlack": "#8F9AAE",
"brightBlue": "#10B1FE",
"brightCyan": "#5FB9BC",
"brightGreen": "#3FC56B",
"brightPurple": "#FF78F8",
"brightRed": "#FF6480",
"brightWhite": "#FFFFFF",
"brightYellow": "#F9C859",
"cursorColor": "#FFCC00",
"cyan": "#4483AA",
"foreground": "#B9C0CB",
"green": "#25A45C",
"name": "BlulocoDark",
"purple": "#7A82DA",
"red": "#FC2F52",
"selectionBackground": "#B9C0CA",
"white": "#CDD4E0",
"yellow": "#FF936A"
}
安装一软件
pacman -S msys/vim
pacman -S msys/git
pacman -S msys/make
pacman -S msys/man-db