前言

之前在电脑上安装过scoop包管理工具,但是毕竟windows无法安装某些应用,又不想安装WSL,冲浪后发现可以类 Unix 环境和命令行界面实现(如Cygwin,MSYS2), 且Git for Windows 预包装了一个名为 Git BASH 的最小化 MSYS2 环境,于是就想折腾一下。

安装Git for Winows

下载地址: https://gitforwindows.org/

(必备软件,跳过即可)

准备二进制文件

下载

在MSYS2的Package能找到pacman https://packages.msys2.org/package/pacman?repo=msys&variant=x86_64

下载好对应的 pkg.tar.zst文件 和 Dependencies对应的全部 pkg.tar.zst文件到Git安装目录。大概核心文件包括
pacman gnupg msys2-keyring pacman-mirrors zstd...

解压

由于安装过scoop可以通过scoop安装zstd,如果没有请移步官网。

scoop install zstd

解压到

zstd -d *.zst
for file in *.tar; do
  tar xvf "$file" -C /
done

初始化

 pacman-key --init && pacman-key --populate msys2

使用

pacman -Sy

tmux

pacman -S tmux --overwrite "*"

zsh相关

安装zsh

pacman -S zsh --overwrite "*"

设置为默认

vim ~/.bashrc
# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi

安装Oh My Zsh

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

下载插件 Zsh-Autosuggestions、Zsh-Syntax-Highlighting等

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

配置 zshrc

vim ~/.zshrc
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source .zshrc

其他

  1. 直接安装MSYS2后使用pacman安装git可以完全省略这些步骤。
  2. 如果出现 错误:failed to synchronize all databases (无效或已损坏的数据库 (PGP 签名)), error: mingw32: signature from "Christoph Reiter (MSYS2 master key) <[email protected]>" is unknown trust

    请保证相关依赖下载完全并解压到对应正确的未知,或者

    rm -r /etc/pacman.d/gnupg/

    后重新初始化

文章目录