Fedora安装ZSH与配置主题
第一步:安装 Zsh 和 基础工具
首先,我们需要确保系统里有 Zsh 以及配合插件所需的 Git。
更新系统并安装:
Bash
1
2sudo dnf update
sudo dnf install zsh git -y切换默认 Shell:
执行以下命令,然后输入你的密码:
Bash
1
chsh -s $(which zsh)
注意: 切换后需要注销并重新登录(或者重启终端)才能生效。
第二步:安装 Oh My Zsh
Oh My Zsh 是管理 Zsh 配置的最强框架。
Bash
1 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
第三步:安装 Powerlevel10k 主题
这是目前最受欢迎的 Zsh 主题,速度极快且高度可定制。
克隆仓库:
Bash
1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
在配置文件中启用:
使用编辑器打开 ~/.zshrc:
Bash
1
nano ~/.zshrc
找到 ZSH_THEME=”robbyrussell” 这一行,修改为:
ZSH_THEME=”powerlevel10k/powerlevel10k”
第四步:安装“三剑客”增强插件
这是你要求的:快速查找、自动提示、语法高亮。
zsh-autosuggestions (自动提示)
Bash
1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
zsh-syntax-highlighting (语法高亮)
Bash
1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
z (快速目录跳转 - 内置)
这个插件 Oh My Zsh 自带,不需要额外下载,只需要在配置中开启。
第五步:激活配置
我们需要在 ~/.zshrc 中把这些插件“拼”起来。
再次编辑配置文件: nano ~/.zshrc
找到 plugins=(git) 这一行,修改为:
Bash
1
2
3
4
5
6plugins=(
git
z
zsh-autosuggestions
zsh-syntax-highlighting
)保存退出并应用:
Bash
1
source ~/.zshrc
在终端里,漂亮的图标全靠 Nerd Fonts(补丁字体)支撑。如果没装它,你的 Powerlevel10k 就会到处是 [?] 乱码。
在 Fedora 上,最稳妥且专业的方法是手动下载并存放到系统的字体目录。我为你准备了最受欢迎的 JetBrainsMono 安装步骤:
1. 创建字体目录
首先,为你的用户创建一个存放私有字体的文件夹:
Bash
1 | mkdir -p ~/.local/share/fonts |
2. 下载并解压 JetBrainsMono Nerd Font
我们将直接从官方 GitHub 下载最新版本:
Bash
1 | # 进入目录 |
3. 刷新系统字体缓存
让 Fedora 识别到你刚刚添加的新字体:
Bash
1 | fc-cache -fv |
4. 最关键的一步:在终端软件中设置
安装完字体不代表终端会自动使用它。你需要手动修改终端的设置:
- 打开你的 Fedora Terminal (GNOME Terminal)。
- 点击右上角的 汉堡菜单 (≡) -> 首选项 (Preferences)。
- 在左侧选择你的配置方案(通常是 未命名 或 Default)。
- 勾选 自定义字体 (Custom font)。
- 在列表里搜索并选择 JetBrainsMono Nerd Font Regular。
5. 重新配置主题
字体生效后,建议运行一次 p10k 的配置向导,以确保所有图标(如 Apple 图标、文件夹图标)都能完美对齐:
Bash
1 | p10k configure |
进阶小技巧:
如果你是在 Windows 上通过 SSH 连接到 Fedora,你需要把这个字体安装在 Windows 本机上,并在你的 SSH 客户端(如 Tabby, MobaXterm 或 Windows Terminal)里设置该字体,图标才能显示出来。
