详细介绍在Linux系统中安装Zsh、Oh My Zsh以及常用插件的完整配置过程。

Debian 配置 zsh 和 oh-my-zsh 指南
2 mins
370 words
Loading views

安装 Zshh2

Zsh 是一个功能强大的 Shell,提供了丰富的增强特性和更佳的用户体验。首先,更新包列表并安装 Zsh:

Terminal window
sudo apt update
sudo apt install zsh
# 验证安装版本
zsh --version

设置 Zsh 为默认 Shellh3

Terminal window
chsh -s $(which zsh)

验证当前 Shell:

Terminal window
echo $SHELL # 应显示 /usr/bin/zsh

安装 Oh My Zshh2

通过官方脚本安装(任选一种方式):

Terminal window
# 使用 curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 或使用 wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

插件推荐h3

效率增强h4

插件名称功能描述安装命令
zsh-autosuggestions历史命令自动提示git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM}/plugins/zsh-autosuggestions
zsh-syntax-highlighting实时语法高亮git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting
fzf模糊搜索文件/命令sudo apt install fzf && git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install

Git 工具h4

插件名称功能描述备注
git内置 Git 快捷命令gst = git status
git-extras扩展 Git 命令需额外安装:sudo apt install git-extras
gitfast快速 Git 补全适合大型仓库

开发工具h4

插件名称支持工具
dockerDocker 命令补全
npmnpm 包管理补全
pythonPython 相关工具补全

系统管理h4

插件名称功能描述
systemdsystemctl 命令补全
sudo按两次 ESC 快速添加 sudo
tmuxTmux 会话管理

趣味插件h4

.zshrcplugins 列表中添加 emojicowsay,例如:

Terminal window
plugins=(... emoji cowsay)

需先安装 cowsay

Terminal window
sudo apt install cowsay

完整配置示例h3

.zshrc 文件片段:

Terminal window
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
fzf
docker
systemd
sudo
emoji
)

补充工具h2

Tmuxh3

Terminal window
apt install tmux -y || yum install tmux -y
curl -SsL https://pan.0197011.xyz/down/s/tmux.sh | bash

命令替代h3

Terminal window
apt install btop -y || yum install btop -y