ohmyzsh-p10k
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOh My Zsh + Powerlevel10k 安装配置指南
Oh My Zsh + Powerlevel10k 安装配置指南
在 macOS 上安装 Oh My Zsh 并配置 Powerlevel10k 主题,包括字体安装和终端美化。
在 macOS 上安装 Oh My Zsh 并配置 Powerlevel10k 主题,包括字体安装和终端美化。
前置条件
前置条件
- macOS 系统
- 已安装 Homebrew
- 已安装 Git
- 使用 zsh 作为默认 shell(macOS 默认)
- macOS 系统
- 已安装 Homebrew
- 已安装 Git
- 使用 zsh 作为默认 shell(macOS 默认)
安装流程
安装流程
按以下顺序执行安装,可使用 一键完成,也可手动逐步操作。
scripts/install.sh按以下顺序执行安装,可使用 一键完成,也可手动逐步操作。
scripts/install.sh一键安装
一键安装
运行 skill 自带的安装脚本:
bash
scripts/install.sh脚本会自动完成以下所有步骤。如需手动安装,参照下方步骤。
运行 skill 自带的安装脚本:
bash
scripts/install.sh脚本会自动完成以下所有步骤。如需手动安装,参照下方步骤。
手动安装步骤
手动安装步骤
步骤 1:备份 .zshrc
步骤 1:备份 .zshrc
bash
cp ~/.zshrc ~/.zshrc.backup.$(date +%Y%m%d%H%M%S)bash
cp ~/.zshrc ~/.zshrc.backup.$(date +%Y%m%d%H%M%S)步骤 2:安装 Oh My Zsh
步骤 2:安装 Oh My Zsh
bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc关键:使用避免覆盖已有的--keep-zshrc配置。.zshrc
bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc关键:使用避免覆盖已有的--keep-zshrc配置。.zshrc
步骤 3:安装 MesloLGS Nerd Font 字体
步骤 3:安装 MesloLGS Nerd Font 字体
Powerlevel10k 主题需要 Nerd Font 字体来正确显示特殊图标和符号。
bash
brew install --cask font-meslo-lg-nerd-font安装完成后需要在终端中设置字体为 MesloLGS Nerd Font(简称 MesloLGS NF)。
iTerm2 设置方法:
Preferences → Profiles → Text- 取消勾选 "Use built-in font"
- 选择 "MesloLGS NF"
macOS 自带 Terminal 设置方法:
偏好设置 → 配置文件 → 文本- 点击"字体",选择 "MesloLGS NF"
Powerlevel10k 主题需要 Nerd Font 字体来正确显示特殊图标和符号。
bash
brew install --cask font-meslo-lg-nerd-font安装完成后需要在终端中设置字体为 MesloLGS Nerd Font(简称 MesloLGS NF)。
iTerm2 设置方法:
Preferences → Profiles → Text- 取消勾选 "Use built-in font"
- 选择 "MesloLGS NF"
macOS 自带 Terminal 设置方法:
偏好设置 → 配置文件 → 文本- 点击"字体",选择 "MesloLGS NF"
步骤 4:安装 Powerlevel10k 主题
步骤 4:安装 Powerlevel10k 主题
bash
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10kbash
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k步骤 5:安装插件所需的二进制工具
步骤 5:安装插件所需的二进制工具
bash
brew install eza # 现代化的 ls 替代工具
brew install zoxide # 智能 cd 替代工具bash
brew install eza # 现代化的 ls 替代工具
brew install zoxide # 智能 cd 替代工具步骤 6:安装第三方 zsh 插件
步骤 6:安装第三方 zsh 插件
bash
undefinedbash
undefined命令自动建议
命令自动建议
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
命令输入实时语法高亮
命令输入实时语法高亮
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/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
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
按片段搜索历史命令
按片段搜索历史命令
git clone --depth=1 https://github.com/zsh-users/zsh-history-substring-search
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
undefinedgit clone --depth=1 https://github.com/zsh-users/zsh-history-substring-search
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
undefined步骤 7:配置 .zshrc
步骤 7:配置 .zshrc
确保 中包含 环境变量(需在 之前):
.zshrcZSHsourcebash
export ZSH="$HOME/.oh-my-zsh"将 修改为 Powerlevel10k:
ZSH_THEMEbash
sed -i '' 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc将 中的 替换为:
.zshrcplugins=(...)bash
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
eza
history-substring-search
jsontools
history
copyfile
copybuffer
copypath
extract
command-not-found
zoxide
)在 配置之后,添加 命令以加载 Oh My Zsh:
pluginssourcebash
source $ZSH/oh-my-zsh.sh注意:必须放在source $ZSH/oh-my-zsh.sh之后,因为 Oh My Zsh 在加载时会读取 plugins 变量来决定启用哪些插件。plugins=(...)
确保 中包含 环境变量(需在 之前):
.zshrcZSHsourcebash
export ZSH="$HOME/.oh-my-zsh"将 修改为 Powerlevel10k:
ZSH_THEMEbash
sed -i '' 's/^ZSH_THEME=.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc将 中的 替换为:
.zshrcplugins=(...)bash
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
eza
history-substring-search
jsontools
history
copyfile
copybuffer
copypath
extract
command-not-found
zoxide
)在 配置之后,添加 命令以加载 Oh My Zsh:
pluginssourcebash
source $ZSH/oh-my-zsh.sh注意:必须放在source $ZSH/oh-my-zsh.sh之后,因为 Oh My Zsh 在加载时会读取 plugins 变量来决定启用哪些插件。plugins=(...)
步骤 8:重启终端并配置 p10k
步骤 8:重启终端并配置 p10k
重启终端后会自动进入 Powerlevel10k 配置向导。如需重新配置:
bash
p10k configure重启终端后会自动进入 Powerlevel10k 配置向导。如需重新配置:
bash
p10k configure插件功能说明
插件功能说明
| 插件 | 类型 | 功能 |
|---|---|---|
| git | 内置 | Git 命令别名和补全 |
| zsh-autosuggestions | 第三方 | 根据历史记录自动建议命令 |
| zsh-syntax-highlighting | 第三方 | 命令输入实时语法高亮 |
| history-substring-search | 第三方 | 按↑↓键基于片段搜索历史命令 |
| eza | 内置 | 为 eza(现代 ls)提供别名 |
| zoxide | 内置 | 为 zoxide(智能 cd)提供集成 |
| jsontools | 内置 | JSON 格式化工具(pp_json 等) |
| history | 内置 | 历史命令管理别名 |
| copyfile | 内置 | 复制文件内容到剪贴板 |
| copybuffer | 内置 | Ctrl+O 复制当前命令行到剪贴板 |
| copypath | 内置 | 复制当前路径到剪贴板 |
| extract | 内置 | 智能解压各种压缩格式 |
| command-not-found | 内置 | 命令未找到时提示安装方式 |
| 插件 | 类型 | 功能 |
|---|---|---|
| git | 内置 | Git 命令别名和补全 |
| zsh-autosuggestions | 第三方 | 根据历史记录自动建议命令 |
| zsh-syntax-highlighting | 第三方 | 命令输入实时语法高亮 |
| history-substring-search | 第三方 | 按↑↓键基于片段搜索历史命令 |
| eza | 内置 | 为 eza(现代 ls)提供别名 |
| zoxide | 内置 | 为 zoxide(智能 cd)提供集成 |
| jsontools | 内置 | JSON 格式化工具(pp_json 等) |
| history | 内置 | 历史命令管理别名 |
| copyfile | 内置 | 复制文件内容到剪贴板 |
| copybuffer | 内置 | Ctrl+O 复制当前命令行到剪贴板 |
| copypath | 内置 | 复制当前路径到剪贴板 |
| extract | 内置 | 智能解压各种压缩格式 |
| command-not-found | 内置 | 命令未找到时提示安装方式 |
可选:安装 iTerm2 颜色主题
可选:安装 iTerm2 颜色主题
bash
git clone --depth=1 https://github.com/mbadolato/iTerm2-Color-Schemes.git ~/iTerm2-Color-Schemes推荐主题:Solarized、Gruvbox、One Dark / One Light、Ayu、Snazzy。
在 iTerm2 中导入:,选择 目录下的 文件。
Preferences → Profiles → Colors → Color Presets → Import~/iTerm2-Color-Schemes/schemes/.itermcolorsbash
git clone --depth=1 https://github.com/mbadolato/iTerm2-Color-Schemes.git ~/iTerm2-Color-Schemes推荐主题:Solarized、Gruvbox、One Dark / One Light、Ayu、Snazzy。
在 iTerm2 中导入:,选择 目录下的 文件。
Preferences → Profiles → Colors → Color Presets → Import~/iTerm2-Color-Schemes/schemes/.itermcolors可选:安装 Powerline 字体(仅在使用 agnoster 等旧主题时需要)
可选:安装 Powerline 字体(仅在使用 agnoster 等旧主题时需要)
bash
git clone https://github.com/powerline/fonts.git --depth=1 /tmp/powerline-fonts
cd /tmp/powerline-fonts && ./install.sh
rm -rf /tmp/powerline-fontsbash
git clone https://github.com/powerline/fonts.git --depth=1 /tmp/powerline-fonts
cd /tmp/powerline-fonts && ./install.sh
rm -rf /tmp/powerline-fonts常见问题排查
常见问题排查
特殊字符显示为乱码:确认已安装 MesloLGS Nerd Font 字体,并且终端字体已设置为 "MesloLGS NF"。
验证字体是否安装成功:
bash
brew install fontconfig # 如果 fc-list 命令不存在
fc-list | grep -i meslop10k 配置向导未自动启动:手动运行 。
p10k configure特殊字符显示为乱码:确认已安装 MesloLGS Nerd Font 字体,并且终端字体已设置为 "MesloLGS NF"。
验证字体是否安装成功:
bash
brew install fontconfig # 如果 fc-list 命令不存在
fc-list | grep -i meslop10k 配置向导未自动启动:手动运行 。
p10k configure