最简配置zsh

之前配置好了oh-my-zsh, 但是作为一个终端来讲没必要配置很多插件,因为我们的需要是有限的,而安装oh-my-zsh仅仅是为了实现一个主题而己,这显然不太符合Archlinux的精神。本文就是基于zsh自身的功能定制了一个最简配置,使用pacman来管理zsh必要的几个插件,这样更方便升级更新。

安装插件

安装zsh的和必要插件
1
2
3
4
5
sudo pacman -S zsh-autosuggestions
sudo pacman -S zsh-completions
sudo pacman -S zsh-theme-powerlevel10k
sudo pacman -S zsh-syntax-highlighting-git
paru -S zsh-z-git

配置zsh

~/.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-z/zsh-z.plugin.zsh
source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# 开启拼写检查,带颜色
autoload U colors && colors
setopt correct
export SPROMPT="Correct $fg[red]%R$reset_color to $fg[green]%r$reset_color [Yes, No, Abort, Edit]"
# 补全大小写敏感
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
# For a full list of active aliases, run `alias`.
# Example aliases
alias zpush="git add . && git commit -m $HOST-$(date "+%Y%m%d") && git push"

配置主题

按照上述步骤可以安装成功各插件,启动终端后自动调出主题powerlevel10k的配置对话,但是注意为了正确的显示图标,还需要安装相应的字体nerd fonts

1
sudo pacman -S nerd-fonts

同时在终端配置好其使用的字体,应当选择DroidSansMono Nerd Fonts, 字体样式选择Book, 重启终端后zsh主题配置完成。

参考文章