让Ubuntu终端效率翻倍!Zsh配置+高颜值主题+实用插件指南_ubuntu zsh
文章目录
一、安装 Zsh
在 bash 中执行以下命令:
# 安装sudo apt update && sudo apt install zsh -y# 设置为默认终端chsh -s $(which zsh)
重启系统或者重新登陆后生效
二、安装 Oh My Zsh(管理框架)
sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\"
三、主题推荐
1. 安装字体
安装 Powerlevel10k,需要预先下载主题所需字体
# 下载安装所需字体wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttfwget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttfwget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttfwget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
双击下载的字体并安装,在终端–配置文件首选项–配置文件(默认配置)–自定义字体中,选择“MesloLGS NF Regular”或者“MesloLGS NF”
安装完成后刷新字体缓存
sudo fc-cache -fv
2. 安装主题
推荐 Powerlevel10k 主题
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
3. 修改配置文件
在 ~/.zshrc
文件中将主题设置为 Powerlevel10k
ZSH_THEME=\"powerlevel10k/powerlevel10k\"
4. 重新加载配置后会自动运行配置向导
source ~/.zshrc
应该会自动弹出powerlevel10k
的主题设置,如果未弹出,输入p10k configure
即可手动进入设置页面,后续修改也可使用p10k configure
进入修改
5. 其他主题推荐
- Spaceship:前端/全栈开发
- Starship:多 Shell 环境
- Pure:追求纯净体验
- Agnoster:服务器管理
- Powerline:与 Vim 的 powerline 状态栏风格统一
- Dracula:长时间编码
四、推荐插件安装
1. 语法高亮
sudo apt install zsh-syntax-highlighting -yecho \"source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh\" >> ~/.zshrc
2. 自动补全
sudo apt install zsh-autosuggestions -yecho \"source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh\" >> ~/.zshrc
3. 其他实用插件
-
zsh-vi-mode:将 Zsh 变成完整的 Vi/Vim 编辑模式
git clone https://github.com/jeffreytse/zsh-vi-mode ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-vi-mode
-
forgit:交互式 git 命令增强
git clone https://github.com/wfxr/forgit.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/forgit
-
zsh-autocomplete:输入时实时显示补全建议
git clone https://github.com/marlonrichert/zsh-autocomplete.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autocomplete
下载完成后,编辑 ~/.zshrc
修改插件配置,在 plugins数组
后添加对应的插件名称:
plugins=(git sudo docker docker-compose kubectl ubuntu forgit zsh-autocomplete)
4.插件优化技巧
性能优化配置( .zshrc
中添加)
# 按需加载插件(减少启动时间)zstyle \':omz:plugins\' lazy-load yes# 指定延迟加载的插件zstyle \':omz:plugins:lazy\' aliases git docker
五、其他优化技巧
1. 历史命令优化
在 ~/.zshrc
中添加:
HISTFILE=~/.zsh_historyHISTSIZE=10000SAVEHIST=10000setopt appendhistorysetopt share_historysetopt hist_ignore_all_dups
2. 别名设置
在 ~/.zshrc
中添加常用别名:
alias ll=\'ls -alF\'alias la=\'ls -A\'alias l=\'ls -CF\'alias update=\'sudo apt update && sudo apt upgrade -y\'alias cls=\'clear\'
3. 启用颜色支持
echo \'export CLICOLOR=1\' >> ~/.zshrcecho \'export LS_COLORS=\"di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43\"\' >> ~/.zshrc
六、最终生效
source ~/.zshrc
七、恢复 bash
# 如果需要切换回bash为默认终端chsh -s $(which bash)# 如果临时切换回bashbash
八、注意事项
- 插件太多可能会影响启动速度,建议按需安装
- 主题建议先选择自己喜欢的风格再安装
- 对于 Powerlevel10k 主题,使用
p10k configure
随时进行风格更换