安装 Oh-My-Zsh 并启用 Powerlevel10k 主题及部分实用插件

经常需要配置安装 ZSH,这里放一个自用的安装方法吧,基本上只要复制命令并执行就可以了,不用去手动编辑文件。

包括字体安装,启用 zsh-autosuggestionszsh-syntax-highlighting 等实用插件。

开始安装

安装依赖

1
2
3
4
# 更新软件源
sudo apt update && sudo apt upgrade -y
# 安装 zsh git curl 字体
sudo apt install zsh git curl fonts-powerline -y

配置 zsh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 这里开始,切换到你需要换为 zsh 的用户!

chsh -s $(which zsh) $(whoami)

# 也可用 root
# sudo chsh -s $(which zsh) username

# 安装 OMZ
sh -c "$(curl -fsSL https://install.ohmyz.sh/)"

# 从 .bashrc 迁移配置,手动完成

# powerlevel10k 主题
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

sed -i.bak 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc

# zsh-autosuggestions 插件
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# zsh-syntax-highlighting 插件
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 启用插件
sed -i.bak 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract)/' ~/.zshrc

新开个终端,会自动提示主题配置。如果没提示,手动运行:

1
p10k configure

END

完工。

如果是使用 Xshell 远程连接,建议在本地主机安装支持图标的字体,比如 NerdFont。

随后,编辑连接配置,手动指定一下字体。