---
title: 从零打造现代化终端环境：Ghostty + Oh My Zsh + Yazi 完整配置指南
author: 朱奕樟
date: 2026-03-23
summary: 一套完整的 macOS 终端美化与增强方案，涵盖 Ghostty、Oh My Zsh、Agnoster 主题、Yazi 文件管理器、fzf、zoxide 等全套工具链，含详细安装步骤和配置说明。
canonical: https://blog.sysu-sam.com/@zhuyizhang/terminal-setup-2026
---

# 从零打造现代化终端环境：Ghostty + Oh My Zsh + Yazi 完整配置指南

> 本文记录了一套完整的 macOS 终端美化与增强方案，涵盖终端模拟器、字体、Shell 框架、主题、文件管理器等全套工具链。所有工具均经过实测，适合日常开发与科研使用。

## 效果预览

安装完成后，你将拥有：

- **Ghostty**：现代高性能终端，支持毛玻璃背景、快速分屏
- **Agnoster 主题**：Powerline 风格的 Git 感知提示符
- **Yazi**：极速终端文件管理器，支持图片/视频/PDF 预览
- **fzf + zoxide**：模糊搜索历史与智能目录跳转

---

## 一、安装 Ghostty 终端

Ghostty 是由 HashiCorp 创始人 Mitchell Hashimoto 开发的高性能终端模拟器，原生支持 macOS 特性。

从官网 [ghostty.org](https://ghostty.org) 下载安装，或通过 Homebrew：

```bash
brew install --cask ghostty
```

### 配置文件

Ghostty 配置文件位于 `~/.config/ghostty/config`，以下是针对 Claude Code 和日常开发优化的完整配置：

```ini
# ============================================
# Bruce's Ghostty Config - 2026 Claude 极致稳定版
# 专为 Claude Code 优化，零报错、左右分屏、一键放大
# 重载快捷键：Cmd + Shift + ,
# ============================================

# --- 字体 ---
font-family = "MesloLGS Nerd Font"
font-size = 14
adjust-cell-height = 2

# --- 主题 ---
theme = Catppuccin Mocha

# --- 窗口外观 ---
background-opacity = 0.85
background-blur-radius = 30
macos-titlebar-style = transparent
window-padding-x = 10
window-padding-y = 8
window-save-state = always
window-theme = auto

# --- 光标 ---
cursor-style = bar
cursor-style-blink = true
cursor-opacity = 0.8

# --- 鼠标 ---
mouse-hide-while-typing = true
copy-on-select = clipboard

# --- Quick Terminal（下拉式终端）---
quick-terminal-position = top
quick-terminal-screen = mouse
quick-terminal-autohide = true
quick-terminal-animation-duration = 0.15

# --- 安全 ---
clipboard-paste-protection = true
clipboard-paste-bracketed-safe = true

# --- Shell 集成 ---
shell-integration = zsh

# --- 性能 ---
scrollback-limit = 25000000

# --- 分屏快捷键 ---
keybind = cmd+d=new_split:right
keybind = cmd+shift+enter=toggle_split_zoom
keybind = cmd+shift+f=toggle_split_zoom
```

**创建配置目录并写入：**

```bash
mkdir -p ~/.config/ghostty
# 将上方内容写入 ~/.config/ghostty/config
```

---

## 二、安装字体

Agnoster 主题需要 Powerline/Nerd Font 字体才能正确渲染箭头和 Git 图标。

### MesloLGS Nerd Font（Agnoster 官方推荐）

```bash
brew install --cask font-meslo-lg-nerd-font
```

### Maple Mono NF CN（可选，中文编程字体）

如果你需要在终端中显示中文，Maple Mono NF CN 是一个优秀的中文等宽编程字体：

```bash
brew install --cask font-maple-mono-nf-cn
```

安装完成后，在 Ghostty 配置中将 `font-family` 改为 `"Maple Mono NF CN"` 即可使用中文字体版本。

---

## 三、安装 Oh My Zsh

Oh My Zsh 是最流行的 Zsh 配置框架，提供丰富的插件和主题生态。

```bash
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

> 参数说明：`RUNZSH=no` 防止安装后自动切换到 zsh，`CHSH=no` 防止修改默认 Shell。

安装后，编辑 `~/.zshrc`，关键配置项：

```bash
# 使用 Agnoster 主题
ZSH_THEME="agnoster"

# 推荐插件
plugins=(git)
```

**注意**：如果你使用 starship 作为提示符，需将 `ZSH_THEME=""` 设为空，二者不可同时启用。

---

## 四、Agnoster 主题

Agnoster 是 Oh My Zsh 内置主题，无需额外安装，设置 `ZSH_THEME="agnoster"` 即可。

**特性：**
- Powerline 风格的箭头分隔符
- 显示当前 Git 分支和状态
- 显示 Python virtualenv 环境名
- 路径显示自动截断

**效果示例：**

```
[用户名@主机 ~/code/my-project] [main ✔] $
```

---

## 五、安装 fzf（模糊查找）

fzf 是一个通用的命令行模糊查找工具，极大提升命令行效率。

```bash
brew install fzf
```

在 `~/.zshrc` 中添加 Shell 集成：

```bash
# --- fzf ---
source <(fzf --zsh)
```

**核心快捷键：**

| 快捷键 | 功能 |
|--------|------|
| `Ctrl+R` | 模糊搜索命令历史 |
| `Ctrl+T` | 模糊搜索当前目录下的文件 |
| `Alt+C` | 模糊搜索并 cd 进入目录 |

---

## 六、安装 Yazi（终端文件管理器）

Yazi 是用 Rust 编写的现代终端文件管理器，支持异步操作和丰富的预览功能。

### 安装 Yazi 及全套依赖

```bash
brew install yazi ffmpeg-full sevenzip jq poppler fd ripgrep fzf zoxide resvg imagemagick-full font-symbols-only-nerd-font
```

**依赖说明：**

| 工具 | 作用 |
|------|------|
| `ffmpeg-full` | 视频缩略图预览 |
| `sevenzip` | 压缩包解压与预览 |
| `jq` | JSON 文件预览 |
| `poppler` | PDF 预览 |
| `fd` | 快速文件搜索 |
| `ripgrep` | 内容搜索 |
| `zoxide` | 智能目录跳转 |
| `resvg` | SVG 图片预览 |
| `imagemagick-full` | 多格式图片预览 |
| `font-symbols-only-nerd-font` | 图标字形支持 |

安装后需要 link full 版本：

```bash
brew link ffmpeg-full imagemagick-full -f --overwrite
```

### Shell 集成配置

在 `~/.zshrc` 中添加以下内容：

```bash
# --- zoxide（智能 cd）---
eval "$(zoxide init zsh)"

# --- yazi（退出时自动 cd 到当前目录）---
function y() {
  local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
  yazi "$@" --cwd-file="$tmp"
  if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
    builtin cd -- "$cwd"
  fi
  rm -f -- "$tmp"
}
```

使用 `y` 命令启动 Yazi，按 `q` 退出后会自动切换到浏览的目录。

### Yazi 基本操作

| 按键 | 功能 |
|------|------|
| `h/j/k/l` 或方向键 | 导航 |
| `Enter` | 进入目录 / 打开文件 |
| `Space` | 选中文件 |
| `y` | 复制 |
| `d` | 剪切 |
| `p` | 粘贴 |
| `D` | 删除到回收站 |
| `r` | 重命名 |
| `/` | 搜索 |
| `z` | 通过 zoxide 跳转 |
| `q` | 退出（并 cd 到当前目录） |

---

## 七、完整 `.zshrc` 配置

以下是整合所有工具后的完整 `~/.zshrc`：

```bash
# Oh My Zsh 配置
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="agnoster"
plugins=(git)
source $ZSH/oh-my-zsh.sh

# conda 环境
# >>> conda initialize >>>
__conda_setup="$('/Users/your-user/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
fi
unset __conda_setup
# <<< conda initialize <<<

# PATH
export PATH="$HOME/.local/bin:$PATH"

# fzf
source <(fzf --zsh)

# zoxide
eval "$(zoxide init zsh)"

# yazi 启动函数
function y() {
  local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
  yazi "$@" --cwd-file="$tmp"
  if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
    builtin cd -- "$cwd"
  fi
  rm -f -- "$tmp"
}
```

---

## 八、额外推荐工具

以下工具也一并推荐安装：

```bash
# fastfetch：系统信息展示（类似 neofetch，但更快）
brew install fastfetch

# btop：现代化系统资源监控（top 的替代品）
brew install btop

# starship：跨 Shell 的高性能提示符（可替代 agnoster）
brew install starship
```

**starship vs agnoster 如何选择：**

- **agnoster**：Oh My Zsh 生态，配置简单，开箱即用
- **starship**：跨 Shell（zsh/bash/fish 通用），配置更灵活，性能更好，推荐在多语言项目中使用

使用 starship 时，需将 `ZSH_THEME=""` 设为空，并在 `.zshrc` 末尾添加：

```bash
eval "$(starship init zsh)"
```

---

## 快速安装脚本

以下脚本可一键完成所有工具的安装：

```bash
#!/bin/bash
set -e

echo "==> 安装字体"
brew install --cask font-meslo-lg-nerd-font font-maple-mono-nf-cn font-symbols-only-nerd-font

echo "==> 安装 Oh My Zsh"
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

echo "==> 安装 CLI 工具"
brew install fzf starship fastfetch btop \
  yazi ffmpeg-full sevenzip jq poppler fd ripgrep zoxide resvg imagemagick-full

echo "==> 链接 full 版本"
brew link ffmpeg-full imagemagick-full -f --overwrite

echo "==> 完成！请重新打开终端。"
```

---

## 参考链接

- [Ghostty 官网](https://ghostty.org)
- [Oh My Zsh](https://ohmyz.sh)
- [Yazi 文档](https://yazi-rs.github.io)
- [fzf GitHub](https://github.com/junegunn/fzf)
- [starship 官网](https://starship.rs)
- [zoxide GitHub](https://github.com/ajeetdsouza/zoxide)
- [Maple Mono 字体](https://github.com/subframe7536/maple-font)
