文章目录
-
- 一、整体架构
- 二、安装必要软件
- [三、Ghostty 配置](#三、Ghostty 配置)
- [四、`.zshrc` 配置](#四、
.zshrc配置) - [五、Starship 配置(核心:Catppuccin Powerline)](#五、Starship 配置(核心:Catppuccin Powerline))
- 六、把字体设置给所有终端
- 七、验证(一键自检脚本)
- 八、常见问题速查
- [九、迁移到新 Mac(5 分钟复刻)](#九、迁移到新 Mac(5 分钟复刻))
- 十、最终效果
目标效果:彩色胶囊提示符 🍎 路径 分支 语言版本 时钟 in 耗时,支持历史建议 + 语法高亮 + Tab 菜单补全。
一、整体架构
┌──────────────────────────────────────────┐
│ Ghostty (终端模拟器) │ ← 控制字体/窗口/主题
│ ┌────────────────────────────────────┐ │
│ │ Zsh + Oh My Zsh (Shell) │ │ ← 控制补全/别名/插件
│ │ ┌──────────────────────────────┐ │ │
│ │ │ Starship (提示符) │ │ │ ← 控制胶囊样式
│ │ └──────────────────────────────┘ │ │
│ └────────────────────────────────────┘ │
└──────────────────────────────────────────┘
三层各司其职,配置分别放在:
| 层 | 配置文件 |
|---|---|
| Ghostty | ~/.config/ghostty/config |
| Zsh / 插件 | ~/.zshrc |
| Starship | ~/.config/starship.toml |
二、安装必要软件
bash
# 1. Homebrew(已装跳过)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 2. 终端 + 提示符
brew install --cask ghostty
brew install starship
# 3. Nerd Font(必装,否则图标全是方框)
brew install --cask font-meslo-lg-nerd-font
brew install --cask font-fira-code-nerd-font
# 4. Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# 5. 三大 Zsh 插件
ZSH_CUSTOM=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-completions $ZSH_CUSTOM/plugins/zsh-completions
三、Ghostty 配置
编辑 ~/.config/ghostty/config:
ini
# ===== 字体(必须用 Nerd Font,否则图标乱码) =====
font-family = MesloLGS Nerd Font Mono
font-size = 14
# ===== 主题 =====
# 使用内置 Catppuccin Mocha(名字大小写和空格要一字不差)
theme = Catppuccin Mocha
background = #282c34
foreground = #ffffff
# ===== 窗口美化 =====
background-opacity = 0.95
background-blur = true
window-padding-x = 12
window-padding-y = 12
macos-titlebar-style = tabs
# ===== 光标 =====
cursor-style = block
cursor-style-blink = true
应用:Ghostty 内按 ⌘ + Shift + , 重载,或完全退出重开。
查所有可用主题:
ghostty +list-themes查当前实际生效的背景色:
ghostty +show-config --default=true | grep -i background
四、.zshrc 配置
编辑 ~/.zshrc,完整模板:
bash
# ===== Oh My Zsh =====
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="" # 清空,交给 Starship
# 插件(zsh-syntax-highlighting 必须放最后)
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
# 额外补全定义必须在 OMZ 加载前加入 fpath
fpath+=${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-completions/src
source $ZSH/oh-my-zsh.sh
# ===== 语言环境(避免中文乱码) =====
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# ===== 补全体验优化 =====
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select
zstyle ':completion:*:descriptions' format '%F{yellow}%B%d%b%f'
# ===== Homebrew (Apple Silicon) =====
eval "$(/opt/homebrew/bin/brew shellenv)"
# ===== Starship 提示符 =====
eval "$(starship init zsh)"
# ===== 本地私有配置(token 等) =====
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
应用:
bash
source ~/.zshrc
# 或新开一个终端窗口
五、Starship 配置(核心:Catppuccin Powerline)
创建 ~/.config/starship.toml,完整内容:
toml
"$schema" = 'https://starship.rs/config-schema.json'
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\
$java\
$kotlin\
$haskell\
$python\
[](fg:green bg:sapphire)\
$conda\
[](fg:sapphire bg:lavender)\
$time\
[ ](fg:lavender)\
$cmd_duration\
$line_break\
$character"""
palette = 'catppuccin_mocha'
# ========== OS 图标(最左边的苹果) ==========
[os]
disabled = false
style = "bg:red fg:crust"
[os.symbols]
Macos = "" # Font Awesome 苹果,兼容最好
# Macos = "" # MDI 苹果,需较新 Nerd Font
Windows = ""
Ubuntu = ""
Linux = ""
Arch = ""
Debian = ""
Fedora = ""
CentOS = ""
Alpine = ""
Android = ""
# ========== 隐藏用户名 ==========
[username]
disabled = true
[hostname]
disabled = true
# ========== 目录 ==========
[directory]
style = "bg:peach fg:crust"
format = "[ $path ]($style)"
truncation_length = 3
truncation_symbol = ".../"
[directory.substitutions]
"Documents" = " "
"Downloads" = " "
"Music" = " "
"Pictures" = " "
"Developer" = " "
# ========== Git ==========
[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)'
[c]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[rust]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[golang]
disabled = true
[php]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[java]
symbol = " "
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[kotlin]
symbol = ""
style = "bg:green"
format = '[[ $symbol( $version) ](fg:crust bg:green)]($style)'
[haskell]
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)'
[conda]
symbol = " "
style = "fg:crust bg:sapphire"
format = '[$symbol$environment ]($style)'
ignore_base = false
[docker_context]
symbol = ""
style = "bg:sapphire"
format = '[[ $symbol( $context) ](fg:crust bg:sapphire)]($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"
disabled = false
show_notifications = true
min_time_to_notify = 45000
# ========== 换行 & 命令符 ==========
[line_break]
disabled = true
[character]
disabled = false
success_symbol = '[❯](bold fg:green)'
error_symbol = '[❯](bold fg:red)'
vimcmd_symbol = '[❮](bold fg:green)'
vimcmd_replace_one_symbol = '[❮](bold fg:lavender)'
vimcmd_replace_symbol = '[❮](bold fg:lavender)'
vimcmd_visual_symbol = '[❮](bold fg:yellow)'
# ========== Catppuccin 调色板(四套任选,改上面 palette = 的值即可切换) ==========
[palettes.catppuccin_mocha]
rosewater = "#f5e0dc"
flamingo = "#f2cdcd"
pink = "#f5c2e7"
mauve = "#cba6f7"
red = "#f38ba8"
maroon = "#eba0ac"
peach = "#fab387"
yellow = "#f9e2af"
green = "#a6e3a1"
teal = "#94e2d5"
sky = "#89dceb"
sapphire = "#74c7ec"
blue = "#89b4fa"
lavender = "#b4befe"
text = "#cdd6f4"
subtext1 = "#bac2de"
subtext0 = "#a6adc8"
overlay2 = "#9399b2"
overlay1 = "#7f849c"
overlay0 = "#6c7086"
surface2 = "#585b70"
surface1 = "#45475a"
surface0 = "#313244"
base = "#1e1e2e"
mantle = "#181825"
crust = "#11111b"
[palettes.catppuccin_frappe]
rosewater = "#f2d5cf"
flamingo = "#eebebe"
pink = "#f4b8e4"
mauve = "#ca9ee6"
red = "#e78284"
maroon = "#ea999c"
peach = "#ef9f76"
yellow = "#e5c890"
green = "#a6d189"
teal = "#81c8be"
sky = "#99d1db"
sapphire = "#85c1dc"
blue = "#8caaee"
lavender = "#babbf1"
text = "#c6d0f5"
subtext1 = "#b5bfe2"
subtext0 = "#a5adce"
overlay2 = "#949cbb"
overlay1 = "#838ba7"
overlay0 = "#737994"
surface2 = "#626880"
surface1 = "#51576d"
surface0 = "#414559"
base = "#303446"
mantle = "#292c3c"
crust = "#232634"
[palettes.catppuccin_latte]
rosewater = "#dc8a78"
flamingo = "#dd7878"
pink = "#ea76cb"
mauve = "#8839ef"
red = "#d20f39"
maroon = "#e64553"
peach = "#fe640b"
yellow = "#df8e1d"
green = "#40a02b"
teal = "#179299"
sky = "#04a5e5"
sapphire = "#209fb5"
blue = "#1e66f5"
lavender = "#7287fd"
text = "#4c4f69"
subtext1 = "#5c5f77"
subtext0 = "#6c6f85"
overlay2 = "#7c7f93"
overlay1 = "#8c8fa1"
overlay0 = "#9ca0b0"
surface2 = "#acb0be"
surface1 = "#bcc0cc"
surface0 = "#ccd0da"
base = "#eff1f5"
mantle = "#e6e9ef"
crust = "#dce0e8"
[palettes.catppuccin_macchiato]
rosewater = "#f4dbd6"
flamingo = "#f0c6c6"
pink = "#f5bde6"
mauve = "#c6a0f6"
red = "#ed8796"
maroon = "#ee99a0"
peach = "#f5a97f"
yellow = "#eed49f"
green = "#a6da95"
teal = "#8bd5ca"
sky = "#91d7e3"
sapphire = "#7dc4e4"
blue = "#8aadf4"
lavender = "#b7bdf8"
text = "#cad3f5"
subtext1 = "#b8c0e0"
subtext0 = "#a5adcb"
overlay2 = "#939ab7"
overlay1 = "#8087a2"
overlay0 = "#6e738d"
surface2 = "#5b6078"
surface1 = "#494d64"
surface0 = "#363a4f"
base = "#24273a"
mantle = "#1e2030"
crust = "#181926"
切换 Catppuccin 子主题 :改顶部 palette = 'catppuccin_mocha' 为:
catppuccin_latte(浅色)catppuccin_frappe(偏蓝灰深色)catppuccin_macchiato(中度深色)catppuccin_mocha(最深,默认)
六、把字体设置给所有终端
Ghostty
已在 ~/.config/ghostty/config 设置 font-family = MesloLGS Nerd Font Mono。
macOS 自带 Terminal.app
- 菜单栏 Terminal → Settings (
⌘ ,) - 左侧选中当前 Profile → 右侧 Text 标签
- Font → Change... → 搜
nerd→ 选 MesloLGS Nerd Font Mono(14pt) - Advanced 标签:
Unicode (UTF-8)✅,取消 "East Asian ambiguous characters are wide" ⌘ Q完全退出后重新打开
iTerm2
Preferences → Profiles → Text → Font 选 Nerd Font,非 ASCII 字体也选同一个。
VS Code 集成终端
settings.json:
json
"terminal.integrated.fontFamily": "MesloLGS Nerd Font Mono"
七、验证(一键自检脚本)
bash
cat <<'EOF' > /tmp/check_term.sh
echo "===== 1. Nerd Font 已安装 ====="
fc-list | grep -i "nerd font" | awk -F: '{print " -", $2}' | sort -u | head
echo ""
echo "===== 2. 图标渲染测试(看到符号 = OK,方框 = 字体问题) ====="
printf " FontAwesome apple (U+F179): \uF179\n"
printf " MDI apple (U+F0035): \U000F0035\n"
printf " Git branch (U+E0A0): \uE0A0\n"
printf " Folder (U+F07B): \uF07B\n"
printf " Powerline arrow (U+E0B0): \uE0B0\n"
echo ""
echo "===== 3. 工具版本 ====="
starship --version
zsh --version
ghostty --version 2>/dev/null
echo ""
echo "===== 4. 配置文件存在性 ====="
for f in ~/.zshrc ~/.config/starship.toml ~/.config/ghostty/config; do
[ -f "$f" ] && echo " ✓ $f" || echo " ✗ $f (缺失)"
done
echo ""
echo "===== 5. 环境变量 ====="
echo " TERM=$TERM"
echo " LANG=$LANG"
EOF
bash /tmp/check_term.sh
八、常见问题速查
| 现象 | 原因 | 解决 |
|---|---|---|
胶囊中图标显示方框 □ |
字体不是 Nerd Font | 终端字体改 MesloLGS NF |
只有 方框,其他图标正常 |
Nerd Font 版本太旧,缺 MDI | 把 Macos = "" 改成 Macos = "",或重装最新 Nerd Font |
Ghostty 报 theme not found |
主题名拼写 / 大小写错误 | ghostty +list-themes 查正确名字,含空格,如 Catppuccin Mocha |
| 胶囊之间拼不起来 | 字体版本旧或不是 Mono 版 | 用 MesloLGS Nerd Font Mono 最稳 |
| 历史灰字建议不出现 | 插件顺序错 | zsh-syntax-highlighting 必须是 plugins 里最后一个 |
| 中文在 Terminal.app 宽度错乱 | 勾了 East Asian ambiguous wide | 设置里取消勾选 |
compinit 报 insecure directories |
权限 | 跑 `compaudit |
Apple Silicon 找不到 starship |
Homebrew 路径未加载 | .zshrc 开头加 eval "$(/opt/homebrew/bin/brew shellenv)" |
九、迁移到新 Mac(5 分钟复刻)
bash
# 旧 Mac 上打包
cd ~
tar -czvf term.tgz \
.zshrc \
.config/ghostty/config \
.config/starship.toml \
.oh-my-zsh
# 新 Mac 上
tar -xzvf term.tgz
brew install starship
brew install --cask ghostty font-meslo-lg-nerd-font
# Oh My Zsh 插件(.oh-my-zsh 已在 tar 里,直接能用)
source ~/.zshrc
更优雅的方式:把 ~/.zshrc、~/.config/ghostty/、~/.config/starship.toml 三个文件用 Git 管理 ,配合 GNU Stow 建立软链,换机一条 git clone + stow 即可恢复。
十、最终效果
提示符长这样(每个胶囊一段颜色,自动切换内容):
~/Desktop/毕业论文/小论文 1 main ? v3.12.0 20:07 in 5s714ms
❯
- 🍎(红) → 苹果图标
- 路径(橙) → 自动缩短为最后 3 级
- git(黄) → 分支名 + 状态
- 语言(绿) → 自动按目录识别 python/node/rust 等
- 时间(紫) → 24h 格式
- 耗时(紫) → 命令超过阈值才显示
❯成功绿色,失败红色
至此,一个美观、实用、跨机可迁移的 macOS 终端环境就搭好了。