我无法再忍受 Oh My Zsh 的速度了。 这是我决定切换到 Starship 的根本原因。

终端是开发者每天打交道最多的工具。一个快速、美观、高效的终端环境,能让开发体验提升好几个档次。这篇文章记录了我从 Oh My Zsh 到 Starship 的迁移过程,以及 Ghostty 终端的选择理由。

为什么放弃 Oh My Zsh?

用了五年 Oh My Zsh,它的生态和插件确实强大,但性能问题一直是个痛点:

痛点 具体表现
启动慢 新终端窗口打开需要 1-2 秒,甚至更久
延迟明显 输入命令时有可感知的卡顿
插件膨胀 装了 20+ 插件,很多只是”可能用到”
配置臃肿 .zshrc 超过 200 行,维护成本高

测试对比(我的 MacBook Pro M3 Pro):

1
2
3
4
5
6
7
# Oh My Zsh 启动时间
time zsh -i -c exit
# 0.85s - 1.2s

# Starship 启动时间
time zsh -i -c exit
# 0.15s - 0.25s

5-8 倍的性能提升,这就是切换的最好理由。

最终方案:Ghostty + ZSH + Starship

整体架构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
┌─────────────────────────────────────────────┐
│ Ghostty │
│ (终端模拟器,渲染层) │
│ - GPU 加速渲染 │
│ - 透明背景 + 毛玻璃效果 │
│ - 现代字体渲染 │
└────────────────┬────────────────────────────┘

┌────────────────┴────────────────────────────┐
│ ZSH │
│ (Shell,基础层) │
│ - 极简配置 (~80 行) │
│ - 只加载必要工具 │
│ - 无框架,原生体验 │
└────────────────┬────────────────────────────┘

┌────────────────┴────────────────────────────┐
│ Starship │
│ (Prompt,展示层) │
│ - Rust 编写,极速渲染 │
│ - 跨 Shell 兼容 │
│ - 高度可配置 │
└─────────────────────────────────────────────┘

为什么是 Ghostty?

之前用过 iTerm2、Alacritty、Kitty、Warp,最终选择 Ghostty 的原因:

特性 Ghostty iTerm2 Alacritty Kitty
启动速度 ⚡ 极快 ⚡ 极快
渲染性能 GPU CPU GPU GPU
内存占用 ~30MB ~200MB ~25MB ~40MB
配置方式 文件 GUI + 文件 文件 文件
macOS 集成 原生 原生 一般 一般
中文支持 完美 完美 需配置 需配置

Ghostty 由 HashiCorp 创始人 Mitchell Hashimoto 开发,追求开箱即用的最佳实践,配置简单但功能强大。

为什么是 Starship?

对比了 Powerlevel10k、Pure、Spaceship 后选择 Starship:

  • 极速:Rust 编写,渲染时间 < 10ms
  • 🔧 配置简单:一个 TOML 文件搞定
  • 🌍 跨平台:支持 Bash、Zsh、Fish、PowerShell
  • 📦 开箱即用:无需复杂配置就能很好看
  • 🎨 高度可定制:想怎么改就怎么改

我的配置分享

Ghostty 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# ~/Library/Application Support/com.mitchellh.ghostty/config

# 主题与字体
theme = Aura
font-family = Maple Mono NF CN
font-size = 15
font-thicken = true
font-feature = calt, cv01, cv03, ss01, ss02, ss03

# 窗口设置
window-height = 20
window-width = 100
window-padding-balance = true
window-save-state = always

# 透明效果
background-opacity = 0.97
background-blur = true

# macOS 集成
macos-titlebar-style = tabs
macos-option-as-alt = true
macos-icon = xray

# Shell 集成
shell-integration = zsh
shell-integration-features = cursor,sudo,title

# 性能优化
scrollback-limit = 4200
window-vsync = true

关键配置说明

  1. 字体选择:Maple Mono NF CN - 支持 Nerd Font 图标和中文
  2. 透明度 0.97:微透明,既能看到背景又不影响阅读
  3. macos-titlebar-style = tabs:紧凑的标签栏样式
  4. shell-integration:启用 Ghostty 的 Shell 集成功能

ZSH 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ~/.zshrc - 极简配置

# 补全系统(无框架)
if type brew &>/dev/null; then
FPATH="$(brew --prefix)/share/zsh-completions:$FPATH"
fi
autoload -Uz compinit && compinit -C

# 环境变量
export LANG=en_US.UTF-8
export EDITOR="code --wait"

# PATH 配置
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
export PNPM_HOME="$HOME/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"

# 工具初始化(按需加载)
eval "$(zoxide init zsh)" # 智能目录跳转
eval "$(fnm env --use-on-cd)" # Node.js 版本管理
eval "$(starship init zsh)" # Starship prompt

# FZF 配置
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
source <(fzf --zsh)

# 实用别名
alias cat='bat --paging=never'
alias l='lsd -l'
alias la='lsd -a'
alias lt='lsd --tree'

# Yazi 文件管理器(退出时 cd)
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
command yazi "$@" --cwd-file="$tmp"
IFS= read -r -d '' cwd < "$tmp"
[ "$cwd" != "$PWD" ] && [ -d "$cwd" ] && builtin cd -- "$cwd"
rm -f -- "$tmp"
}

设计原则

  1. 无框架:不用 Oh My Zsh、Prezto 等,保持轻量
  2. 按需加载:只初始化真正需要的工具
  3. 现代替代品
    • lslsd(现代 ls,支持图标和颜色)
    • catbat(语法高亮)
    • cdzoxide(智能跳转)
    • findfd(更快的查找)

Starship 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# ~/.config/starship.toml

format = """
[ ](red)\
$os\
$username\
[ ](bg:peach fg:red)\
$directory\
[ ](bg:yellow fg:peach)\
$git_branch\
$git_status\
[ ](fg:yellow bg:green)\
$c\
$rust\
$golang\
$nodejs\
$php\
$python\
[ ](fg:green bg:sapphire)\
$conda\
[ ](fg:sapphire bg:lavender)\
$time\
[ ](fg:lavender)\
$cmd_duration\
$line_break\
$character"""

palette = 'catppuccin_mocha'

[os]
disabled = false
style = "bg:red fg:crust"

[os.symbols]
Macos = " "

[username]
show_always = true
style_user = "bg:red fg:crust"
format = '[ $user]($style)'

[directory]
style = "bg:peach fg:crust"
format = "[ $path ]($style)"
truncation_length = 3

[git_branch]
symbol = " "
style = "bg:yellow"
format = '[[ $symbol $branch ](fg:crust bg:yellow)]($style)'

[git_status]
style = "bg:yellow"
format = '[[($all_status$ahead_behind )](fg:crust bg:yellow)]($style)'

[nodejs]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'

[golang]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'

[python]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version)(\(#$virtualenv\)) ](fg:crust bg:green)]($style)'

[time]
disabled = false
time_format = "%R"
style = "bg:lavender"
format = '[[ $time ](fg:crust bg:lavender)]($style)'

[cmd_duration]
show_milliseconds = true
format = " in $duration "
style = "bg:lavender"
show_notifications = true
min_time_to_notify = 45000

[character]
success_symbol = '[❯](bold fg:green)'
error_symbol = '[❯](bold fg:red)'

效果展示

1
2
󰀵 wangningkai   ~/Workplace/private/blog   main ≡   1.24   3.13  14:23 

配置亮点

  1. Catppuccin Mocha 配色:统一美观的深色主题
  2. 操作系统图标:一眼识别系统类型
  3. 语言版本显示:自动检测当前目录使用的语言
  4. 时间显示:方便追踪命令执行时间
  5. 命令耗时通知:超过 45 秒自动弹出通知

迁移步骤

如果你也想从 Oh My Zsh 迁移,这是我推荐的步骤:

1. 备份现有配置

1
2
cp ~/.zshrc ~/.zshrc.oh-my-zsh.backup
cp -r ~/.oh-my-zsh/custom ~/.oh-my-zsh-custom.backup

2. 安装依赖工具

1
2
3
4
5
6
7
8
# 安装 Starship
brew install starship

# 安装现代工具替代品
brew install zoxide lsd bat fd fzf

# 安装 Nerd Font 字体
brew install --cask font-maple-mono-nf-cn

3. 创建新的 ZSH 配置

1
2
3
4
5
6
7
8
9
# 备份旧配置
mv ~/.zshrc ~/.zshrc.backup

# 创建新配置
# 将上面的配置保存到 ~/.zshrc

# 创建 Starship 配置目录
mkdir -p ~/.config
# 将 Starship 配置保存到 ~/.config/starship.toml

4. 迁移自定义别名和函数

从备份中提取你常用的别名和函数,按需添加到新配置。

5. 测试并调整

1
2
3
4
5
# 重新加载配置
source ~/.zshrc

# 测试启动速度
time zsh -i -c exit

性能对比总结

指标 Oh My Zsh Starship 提升
启动时间 ~1.0s ~0.2s 5x
配置文件大小 200+ 行 ~80 行 2.5x
内存占用 ~50MB ~10MB 5x
输入延迟 可感知 无感知
可维护性

实用工具推荐

这套终端环境的其他实用工具:

工具 用途 替代
zoxide 智能目录跳转 autojump
lsd 现代文件列表 ls
bat 语法高亮查看 cat
fd 快速文件查找 find
fzf 模糊搜索 -
yazi 终端文件管理器 ranger
ripgrep 快速文本搜索 grep
dust 磁盘占用分析 du

常见问题

Q: Oh My Zsh 的插件怎么办?

大部分常用插件都有替代方案:

Oh My Zsh 插件 替代方案
zsh-autosuggestions 原生支持不完善,可用 fig 或接受现实
zsh-syntax-highlighting 可单独安装:brew install zsh-syntax-highlighting
z / autojump zoxide(更快更智能)
git 使用别名或 git-extras
docker / kubectl 各工具自带补全

Q: Powerlevel10k 也很快,为什么不选它?

Powerlevel10k 确实很快,但:

  • 配置复杂,需要交互式向导
  • Zsh 专用,不跨平台
  • 配置文件是大量条件判断,可读性差

Starship 配置更直观,一个 TOML 文件搞定。

Q: 主题配色怎么统一?

我使用 Catppuccin 主题统一所有工具:

  • Ghostty: theme = Aura(基于 Catppuccin)
  • Starship: palette = 'catppuccin_mocha'
  • VSCode: Catppuccin 扩展
  • Browser: Catppuccin 主题

一套配色,视觉一致。

总结

这次终端环境重构的核心收获:

  1. 性能优先:终端是高频工具,启动速度和响应延迟直接影响体验
  2. 极简主义:只保留必要的,去掉”可能用到”的
  3. 现代工具:用 Rust/Go 写的现代工具替代老旧 Unix 工具
  4. 配置即代码:所有配置都可以版本控制,随时恢复

从 Oh My Zsh 到 Starship,从 iTerm2 到 Ghostty,不只是工具的更换,更是设计理念的转变:从”功能堆砌”到”性能优先”,从”开箱即用”到”按需配置”。

终端环境没有银弹,适合自己的才是最好的。希望我的经验能给你一些参考。


💡 相关文章