美化终端
约 900 字大约 3 分钟
2025-03-14
https://my.oschina.net/emacs_8896228/blog/17532060
📦 安装 Oh My Zsh
Oh My Zsh 是一个开源的、社区驱动的框架,用于管理 Zsh 配置。它提供了海量主题和插件,能让您的终端既美观又高效。
安装前提
- 确保已安装 Zsh:
sudo apt install zsh # Ubuntu/Debian sudo yum install zsh # CentOS/RHEL brew install zsh # macOS
- 设置 Zsh 为默认 shell:
chsh -s $(which zsh)
安装方法
# 使用 curl 安装
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 使用 wget 安装
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
🎨 主题配置
Oh My Zsh 提供了 200+ 主题,存放于 ~/.oh-my-zsh/themes/
配置主题
编辑 ~/.zshrc
文件:
ZSH_THEME="主题名" # 例如:agnoster, powerlevel10k, spaceship
热门主题推荐
主题名称 | 特点 | 预览 |
---|---|---|
powerlevel10k | 高度可定制,极快速度 | ![]() |
spaceship | 现代化,多功能提示符 | ![]() |
agnoster | 经典简约,需安装 Powerline 字体 | ![]() |
robbyrussell | 默认主题,简洁实用 | ![]() |
dracula | 深色主题,护眼美观 | ![]() |
安装 Powerline 字体(部分主题需)
# 克隆字体库
git clone https://github.com/powerline/fonts.git --depth=1
# 安装字体
cd fonts
./install.sh
# 清理
cd ..
rm -rf fonts
在终端设置中修改字体为:
Meslo LG S Regular for Powerline
- 或其他 Powerline 字体
🧩 插件增强
Oh My Zsh 拥有 300+ 插件,提升终端功能和体验
常用插件推荐
zsh-autosuggestions(命令自动建议)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
zsh-syntax-highlighting(语法高亮)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git(Git 集成)
docker(Docker 支持)
sudo(按两次 ESC 添加 sudo)
启用插件
编辑 ~/.zshrc
:
plugins=(
git
docker
zsh-autosuggestions
zsh-syntax-highlighting
sudo
)
🔧 进阶配置
安装 Powerlevel10k 主题
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
然后设置:
ZSH_THEME="powerlevel10k/powerlevel10k"
运行配置向导:
p10k configure
常用别名设置(~/.zshrc)
# 便捷操作
alias ls="lsd" # 替代 ls 使用 lsd
alias cat="bat" # 替代 cat 使用 bat
alias find="fd" # 替代 find 使用 fd
alias grep="rg" # 替代 grep 使用 ripgrep
# Git 简化
alias gs="git status"
alias ga="git add"
alias gc="git commit"
alias gp="git push"
alias gl="git pull"
# 快速编辑
alias zshconfig="nano ~/.zshrc"
alias ohmyzsh="nano ~/.oh-my-zsh"
安装现代化工具
# exa (现代替代 ls)
sudo apt install exa # Ubuntu/Debian
brew install exa # macOS
# bat (现代替代 cat)
sudo apt install bat # Ubuntu/Debian
brew install bat # macOS
# lsd (更友好的颜色和图标)
sudo snap install lsd # Snap
brew install lsd # macOS
💻 主题效果示例(Powerlevel10k)
一个完整的配置效果:
[user@host ~]
> git status
➜ master ± ❯ gs # 使用简写命令
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
➜ master ✔ ❯ cd projects/ # 自动建议显示历史命令
➜ projects master ✔ ❯ ls # 丰富的颜色和图标
📂 backend 📂 frontend 📄 README.md
➜ projects master ✔ ❯ # 整洁的提示符显示当前路径和Git状态
🔌 推荐插件列表
插件 | 功能 | 安装命令 |
---|---|---|
zsh-autosuggestions | 命令自动建议 | git clone https://github.com/zsh-users/zsh-autosuggestions |
zsh-syntax-highlighting | 命令语法高亮 | git clone https://github.com/zsh-users/zsh-syntax-highlighting |
docker | Docker 自动补全 | 内置 |
kubectl | Kubernetes 支持 | 内置 |
asdf | 多语言版本管理器 | 内置 |
web-search | 直接从终端搜索 | 内置 |
copypath | 复制当前路径 | 内置 |
💾 更新与维护
# 手动更新 Oh My Zsh
omz update
# 禁用自动更新
DISABLE_AUTO_UPDATE="true" # 添加到 ~/.zshrc
# 重置 Zsh 配置
exec zsh # 或 source ~/.zshrc
🚫 卸载 Oh My Zsh
uninstall_oh_my_zsh
💡 美化小贴士:
- 结合使用 iTerm2 (macOS) 或 Windows Terminal (Windows) 获得最佳体验
- 搭配 nerdfonts 获得更丰富的图标支持
- 使用 Fig 添加IDE风格的自动完成
更新日志
2025/6/24 14:28
查看所有更新日志
6e52d
-Merge branch 'master' into github-master于