Skip to content

Install Zsh on Windows

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

Windows Terminal 配置 Git Bash

安装 Zsh

先下载 Zsh 的压缩包,解压后,得到 etc 和 usr 两个文件夹和另外四个文件:

sh
PS C:\Users\Lenovo\Downloads\zsh-5.9-4-x86_64.pkg> tree -l 2

C:\Users\Lenovo\Downloads\zsh-5.9-4-x86_64.pkg
├── etc
|  └── zsh
└── usr
   ├── bin
   ├── lib
   └── share

directory: 6

将其全部复制、粘贴放到 Git Bash 的安装目录,默认是 C:\Program Files\Git\ 目录。

如果你跟我一样,决定默认使用 zsh,而不进入 bash,可以在用户家目录下创建 ~/.bashrc 并加上下面代码:

# ~/.bashrc
# This file is required only on Windows machines
# Virtually tells bash.exe to enter zsh.exe
if [ -t 1 ]; then
  exec zsh
fi

然后,将 macOS 下的 ~/.zshrc 配置文件也直接放到用户家目录下,从 Windows Terminal 重新运行 Git Bash 即可。首次运行 zsh 将根本 ~/.zshrc 配置文件中的设置,安装插件,大致在做以下工作。

这时已经可以在 Windows Terminal 将原先 Git Bash 这个 profile 改名为 Zsh,并改用 Zsh logo,以跟原先配置的 Git Bash 有所区分。

安装 ohmyzsh

sh
git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
cd ohmyzsh/tools
nvim install.sh
# open install.sh and revise REMOTE accordingly
# REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
sh install.sh

下载 powerlevel10k 主题

sh
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

~/.zshrc 设置 ZSH_THEME="powerlevel10k/powerlevel10k"。接下来,重新打开一个新的终端,终端会自动引导你配置 powerlevel10k 主题。

把 Zsh 集成到 Windows Terminal

这里的内容待补充。

安装插件

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

启用插件

修改 ~/.zshrc 中插件列表为:

sh
plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)

其中有两个是上面刚刚安装,其他则为 Zsh 内置插件。

最近更新