Mac 终端 — iTerm2 vs WezTerm vs Ghostty + zsh + Starship
替代默认 Terminal.app 的三种选择,以及搭建稳定 zsh + Starship 环境的最快路径。
macOS 内置的 Terminal.app 可以用,但在分割窗格、搜索、渲染和可配置性上落后于替代品。本指南对比 iTerm2 · WezTerm · Ghostty 三种方案,并搭建最快速稳定的环境(WezTerm + zsh + Starship + 四个模块)。
我认为终端选择的关键不在于功能清单,而在于配置的可复现性。以前很多人用 iTerm2 因为它功能最多;如今 WezTerm 的 Lua 配置文件可以直接纳入 dotfiles 管理,由于那个代码化的配置,新机器恢复只需一条命令。
TL;DR
| 选项 | 优势 | 劣势 | 适合人群 |
|---|---|---|---|
| WezTerm(推荐) | Lua 配置 / GPU 加速 / 跨平台 | Lua 学习曲线 | 喜欢将配置代码化的独立开发者 |
| iTerm2 | 最成熟 / 强大的搜索/分割/会话功能 | 设置 GUI 繁复 | 功能优先 |
| Ghostty | 快速 / 简洁 / 1.0 稳定版 | 较新,部分功能缺失 | 极简主义者 / 追求最新 |
1. 选项对比
iTerm2
最老牌的仅限 macOS 的终端。分割窗格(⌘D)、即时回放、搜索、触发器(文本匹配动作)、会话自动恢复 — 功能丰富。
WezTerm
用 Rust 编写,Lua 配置,GPU 加速,跨平台(Mac/Linux/Win)。键位绑定、主题、多路复用 — 全部在一个 Lua 文件中。可复现。
Ghostty
2024 年发布 1.0 稳定版。快速、GPU 加速、配置简洁。功能不如 iTerm2/WezTerm 丰富,但日常使用足够。
推荐:WezTerm
对于"将配置代码化、新机器一键恢复"的场景,WezTerm 是明显的赢家。与 dotfiles 管理 天然集成。本指南以 WezTerm 为基础。
2. 安装 WezTerm
brew install --cask wezterm首次启动 → 默认 shell 为 zsh(macOS 默认)。屏幕正常渲染即成功。
3. WezTerm 配置 — ~/.config/wezterm/wezterm.lua
mkdir -p ~/.config/wezterm && nvim ~/.config/wezterm/wezterm.lua:
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
-- 字体
config.font = wezterm.font_with_fallback({
'JetBrainsMono Nerd Font',
'Hiragino Sans', -- 韩文 / 日文回退
})
config.font_size = 13.0
-- 配色方案
config.color_scheme = 'Catppuccin Mocha' -- 或 'Tokyo Night'、'Dracula'
-- 窗口
config.window_decorations = 'RESIZE' -- 隐藏标题栏,保留可调整大小
config.window_padding = { left = 8, right = 8, top = 8, bottom = 8 }
config.window_background_opacity = 0.95
config.macos_window_background_blur = 20
-- 标签页
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = true
config.hide_tab_bar_if_only_one_tab = true
-- Shell
config.default_prog = { '/opt/homebrew/bin/zsh', '-l' } -- brew zsh(比 macOS 默认更新)
-- 键位绑定
config.keys = {
-- 分割窗格
{ key = 'd', mods = 'CMD', action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' } },
{ key = 'D', mods = 'CMD|SHIFT', action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' } },
-- 窗格导航
{ key = 'LeftArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection 'Left' },
{ key = 'RightArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection 'Right' },
{ key = 'UpArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection 'Up' },
{ key = 'DownArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection 'Down' },
-- 关闭窗格
{ key = 'w', mods = 'CMD', action = wezterm.action.CloseCurrentPane { confirm = true } },
}
return config保存后 WezTerm 自动重载。按 ⌘D 确认分割窗格是否正常工作。
4. 升级 zsh
macOS 自带较旧的 zsh,brew 有更新版本:
brew install zsh
which -a zsh
# /opt/homebrew/bin/zsh
# /bin/zsh
# 更改默认 shell
sudo sh -c "echo /opt/homebrew/bin/zsh >> /etc/shells"
chsh -s /opt/homebrew/bin/zsh新终端 → echo $ZSH_VERSION → 显示 5.9+ 即确认。
5. Starship 提示符
比 oh-my-zsh 更轻量更快速。Rust 单一二进制:
brew install starship追加到 ~/.zshrc:
eval "$(starship init zsh)"~/.config/starship.toml:
# 快速默认激活
add_newline = true
format = """
$directory\
$git_branch\
$git_status\
$nodejs\
$python\
$rust\
$cmd_duration\
$line_break\
$character"""
[directory]
truncation_length = 3
truncate_to_repo = true
[git_status]
disabled = false
ahead = "↑${count} "
behind = "↓${count} "
[cmd_duration]
min_time = 2000 # 仅显示超过 2 秒的命令
[character]
success_symbol = "[➜](bold green)"
error_symbol = "[➜](bold red)"用 . ~/.zshrc 重新加载,或打开新终端。
6. 四个 zsh 模块
6.1 zsh-autosuggestions
基于历史的灰色提示:
brew install zsh-autosuggestions~/.zshrc:
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh按 → 接受。
6.2 zsh-syntax-highlighting
命令着色(无效命令显示红色):
brew install zsh-syntax-highlightingsource /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh⚠️ 在
.zshrc中最后引入 syntax-highlighting 以保证正确行为。
6.3 fzf — 模糊搜索
brew install fzf
$(brew --prefix)/opt/fzf/install
# 所有提示选 yes在新终端中:
Ctrl+R— 历史记录搜索Ctrl+T— 文件搜索Alt+C— 目录跳转
6.4 zoxide — 更智能的 cd
brew install zoxide~/.zshrc:
eval "$(zoxide init zsh)"z proj # 跳转到常访问的项目路径
zi # 交互式选择器7. 完整 .zshrc 示例
# 历史记录
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY HIST_IGNORE_DUPS HIST_IGNORE_SPACE
# 自动补全
autoload -Uz compinit && compinit
# Brew
eval "$(/opt/homebrew/bin/brew shellenv)"
# 模块
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
eval "$(zoxide init zsh)"
# 别名
alias ll='ls -lah'
alias gs='git status -sb'
alias gd='git diff'
alias ..='cd ..'
# 工具
eval "$(starship init zsh)"
# (必须最后引入)
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh8. iTerm2 快速配置(替代方案)
如果你偏好 iTerm2 而非 WezTerm:
brew install --cask iterm2- 偏好设置 → 配置文件 → 默认 → 文本 → 字体 = JetBrainsMono Nerd Font 13pt
- 窗口 → 透明度 5%,开启模糊
- 按键 → 热键窗口 — 绑定全局快捷键如
⌥ Space用于浮动窗口
iTerm2 的杀手功能是热键窗口(从任意位置切换浮动终端)。WezTerm 可以配置出类似效果,但 iTerm2 开箱即有。
验证
- 新终端 → Starship 提示符显示(带彩色 cwd / git 分支)
Ctrl+R→ fzf 交互式历史搜索ls→ zsh-syntax-highlighting 为命令着色- 输入之前命令的一部分 → 灰色自动建议 → 按
→ z proj→ 跳转到之前访问过的项目文件夹- WezTerm
⌘D→ 分割窗格 →⌘⌥←导航
故障排除
语法高亮不显示颜色
- 在
.zshrc中未最后引入(必须在其他模块之后) - WezTerm 配色方案颜色数少于 256 — 可能性低,优先选用 Catppuccin / Tokyo Night
Starship 显示乱码字形
缺少 Nerd Font。检查 WezTerm 字体配置 + 确认实际安装了字体(brew install --cask font-jetbrains-mono-nerd-font)。
z 没有反应
.zshrc中缺少 zoxide init,或.zshrc未重新加载- 初始数据库为空 — 先执行几次
cd来训练它
WezTerm 默认在 $HOME 打开
在配置中设置:config.default_cwd = wezterm.home_dir .. '/work',或为常用文件夹设置别名。
chsh 未更改 shell
- 新 shell 未添加到
/etc/shells→ chsh 失败 - 退出登录再重新登录,或重启
参考资料
- Mac 初始配置 — Homebrew 前置条件
- Dotfiles 管理 — 推荐将
.zshrc、wezterm.lua、starship.toml存入 chezmoi - WezTerm(官方)
- Starship 配置
- iTerm2
- Ghostty
更新日志
- 2026-05-12:首次发布。三种终端对比 + WezTerm + zsh + Starship + 四个模块 + 五个故障排除案例。