1. 背景
长期以来,我的终端环境基于这样的分层架构:
- Shell: zsh + oh-my-zsh
- Prompt: powerlevel10k
- Terminal Emulator: Alacritty
- Multiplexer: tmux
这套方案稳定可靠,之前一直在关注Ghostty和Starship:
- Ghostty:用 Zig 开发的现代终端模拟器,强调原生 UI 整合和 GPU 加速
- Starship:用 Rust 开发的跨平台 Prompt,简洁高效
最近一直在折腾终端和AI Cli的东西,想着一起试一下Ghostty和Starship。
直接替换现有终端环境太激进了,我选择了一个渐进式混合部署策略:
- 在 macOS 上安装 Ghostty 终端模拟器
- 在 Ubuntu code-server 上安装 Starship prompt
- macOS 本地终端保持原有架构不变(zsh + oh-my-zsh + powerlevel10k + Alacritty + tmux)
- 通过 Ghostty SSH 到 code-server 时,体验 Ghostty + Starship 的组合
这样既能试用Ghostty + Starship,又不影响本地终端的稳定。
2. Ghostty:新一代终端模拟器
2.1 Ghostty 简介
Ghostty 是一个快速、功能丰富的跨平台终端模拟器,核心特点:
- GPU 加速渲染:使用平台原生 UI 和 GPU 加速,性能优秀
- 零配置启动:开箱即用,无需复杂配置即可使用
- 功能完整:内建 tabs、splits、主题系统
- 高度可定制:提供数百个配置选项
- 内置主题:自带数百个配色主题,支持明暗模式
2.2 安装 Ghostty
在 macOS 上使用 Homebrew 安装非常简单:
brew install --cask ghostty2.3 基础配置
Ghostty 在 macOS 上的配置文件位置有两个选择:
- macOS 标准位置(推荐):
~/Library/Application Support/com.mitchellh.ghostty/config - XDG 标准位置:
~/.config/ghostty/config
两个位置都支持,如果两个文件都存在,会按顺序加载,后加载的会覆盖前面的配置。
由于我已经在使用 MesloLGS NF 字体(powerlevel10k 推荐),可以直接复用。创建配置文件:
macos-icon = retro
auto-update = check
# theme = "dracula+"
theme = "TokyoNight"
title = " "
macos-titlebar-proxy-icon = "hidden"
font-family = "MesloLGS NF"
font-size = 15
font-thicken = true
adjust-cursor-thickness = 10
copy-on-select = "clipboard"
clipboard-trim-trailing-spaces = true
clipboard-paste-protection = true
clipboard-paste-bracketed-safe = trueGhostty 的一大优势是零配置即可使用,上述配置可根据个人喜好调整。
GPU 加速:Ghostty 默认启用 GPU 加速(macOS 使用 Metal,Linux 使用 OpenGL),无需额外配置。
配置重载:修改配置文件后,使用快捷键 cmd+shift+,(macOS)即可重载配置,无需重启应用。注意部分配置项可能需要新建窗口或重启应用才能生效。
主题选择:
Ghostty 提供了交互式的主题选择工具:
ghostty +list-themes运行后会打开一个交互界面:
- 左侧显示所有可用主题列表
- 右侧实时预览主题效果
- 使用上下键浏览不同主题
- 按回车后会提示应该在配置文件中添加的配置(如
theme = "dracula+")
这种可视化的主题选择方式非常直观,可以快速找到喜欢的配色方案。
2.4 分屏与标签快捷键
Ghostty 内建的分屏/标签页功能:
| 操作 | 快捷键(macOS) |
|---|---|
| 垂直分屏(左右) | ⌘ + D |
| 水平分屏(上下) | ⌘ + Shift + D |
| 关闭当前分屏 | ⌘ + W |
| 在分屏间移动焦点 | ⌘ + [ / ⌘ + ] |
| 操作 | 快捷键(macOS) |
|---|---|
| 新建标签页 | ⌘ + T |
| 关闭当前标签页 | ⌘ + W |
| 下一个/上一个标签 | ⌘ + Shift + ] / ⌘ + Shift + [ |
| 切换到第 n 个标签页 | ⌘ + 1 … ⌘ + 9 |
对比 tmux:Ghostty 的分屏/标签属于「应用级」,窗口关闭后会随之消失;tmux 提供「会话级」多路复用。我的习惯还是使用 tmux。
2.5 远端终端的 terminfo
Ghostty 会把 TERM 设为 xterm-ghostty。从 macOS Ghostty SSH 到 Ubuntu code-server 时,需把本机自带的 terminfo 推送过去,否则执行一些命令时会报 “unknown terminal type”。官方推荐的做法:
# macOS 本地(Ghostty 已安装)。TI_PATH 指向 Ghostty 自带 terminfo 目录
TI_PATH="/Applications/Ghostty.app/Contents/Resources/terminfo"
# 推送到远端用户级(无 sudo)
infocmp -x -A "$TI_PATH" xterm-ghostty | ssh user@code-server-host 'tic -x -'
# 验证(远端)
ssh user@code-server-host 'infocmp xterm-ghostty; TERM=xterm-ghostty clear'如果需要系统级安装(所有用户可用):
infocmp -x -A "$TI_PATH" xterm-ghostty | ssh user@code-server-host 'sudo tic -x -'更多内容见Ghostty - Terminfo。
3. Starship:跨平台 Prompt
3.1 Starship 简介
Starship 是一个轻量、快速、可定制的跨 shell Prompt 系统:
- 跨平台跨 Shell:支持 Bash、Zsh、Fish、PowerShell 等
- Rust 驱动:启动快速,性能优秀
- 配置简单:单个 TOML 文件管理所有配置
- 模块化设计:可自由启用/禁用各种显示模块
- 丰富的上下文信息:自动检测 Git、语言版本、k8s context 等
3.2 安装 Starship
安装方法选择:
Starship 提供了多种安装方式,Ubuntu 25.04+ 可以使用 apt 安装。但对于更低版本的 Ubuntu(如 20.04、22.04),推荐使用官方安装脚本:
curl -sS https://starship.rs/install.sh | sh -s -- -b ~/.local/bin安装脚本执行流程:
这个安装脚本会:
- 检测系统环境:自动识别操作系统和 CPU 架构(x86_64、aarch64 等)
- 下载预编译二进制:从 GitHub Releases 下载对应平台的 Starship 二进制文件
- 安装到系统路径:默认安装到
/usr/local/bin/starship - 清理临时文件:自动删除下载的压缩包
权限说明:
- 如果
/usr/local/bin目录可写,脚本无需 sudo 权限 - 如果目录不可写,脚本会自动请求 sudo 权限
- 可以通过
-b参数指定其他安装目录(如sh -s -- -b ~/.local/bin)
验证安装:
安装完成后,验证 Starship 是否正确安装:
starship --version初始化 Shell:
安装完成后,需要在 shell 配置文件中初始化。
对于 zsh(~/.zshrc), 将下面的内容加入到其最后一行:
eval "$(starship init zsh)"对于 bash(~/.bashrc), 将下面的内容加入到其最后一行:
eval "$(starship init bash)"重新加载配置:
source ~/.zshrc # 或 source ~/.bashrc注意:从 Shell (zsh + oh-my-zsh) + Prompt (powerlevel10k) + Terminal Emulator (Alacritty) + Multiplexer (tmux) 升级到 Shell (zsh + oh-my-zsh) + Prompt (Starship) + Terminal Emulator (Ghostty) + Multiplexer (tmux) 时,oh-my-zsh 依然保留。oh-my-zsh 是 zsh 的插件/主题管理框架,负责 alias、补全和插件体系;Starship 只负责提示符(prompt)渲染,二者并不冲突。
~/.zshrc 中主要变化是移除了 powerlevel10k 的主题设置,保留 oh-my-zsh 的加载和插件。示例:
export ZSH="$HOME/.oh-my-zsh"
# 插件按需开启
plugins=(
zsh-autosuggestions
# zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
eval "$(starship init zsh)"如果需要命令自动补全或提示,zsh-autosuggestions 仍可使用;zsh-syntax-highlighting 也可按需开启。Starship 与 oh-my-zsh 的分工是:Starship 负责 prompt,oh-my-zsh 负责 zsh 生态插件与配置。
升级 Starship:
如果使用官方安装脚本安装的 Starship,升级非常简单,只需重新运行安装脚本即可:
curl -sS https://starship.rs/install.sh | sh -s -- -b ~/.local/bin3.3 先从官方预设(preset)起步
Starship 官方提供了多套开箱即用的预设配置,先选一个喜欢的方案,再在此基础上微调即可。常用两套:
- Gruvbox Rainbow:暗色系,Powerline 分隔 + 渐变色块。
- Tokyo Night:暗色系,布局简洁,色彩对比鲜明。
应用命令(记得先备份当前配置):
# 覆盖当前配置(记得先备份原文件)
cp ~/.config/starship.toml ~/.config/starship.toml.bak 2>/dev/null || true
starship preset gruvbox-rainbow -o ~/.config/starship.toml # 或 tokyo-night如果想先对比或只挑部分配置,可以输出到临时文件后手动合并:
starship preset gruvbox-rainbow -o /tmp/starship-gruvbox-rainbow.toml
# 或
starship preset tokyo-night -o /tmp/starship-tokyo-night.toml将喜欢的模块/颜色段落剪贴到 ~/.config/starship.toml 即可。更多预设见 starship.rs/presets。
3.4 在预设基础上微调
Starship 的配置文件为 ~/.config/starship.toml。确保有 Nerd Font 字体后,可以在预设基础上做小改动,例如:
# ~/.config/starship.toml
# 在命令之间添加空行
add_newline = true
[os] # 关闭 OS 模块(默认会显示操作系统信息)
disabled = true上面的例子在预设上关闭 OS 模块;其他目录/Git/颜色逻辑可继续沿用预设。
4. 混合方案实践
4.1 SSH 连接体验
完成上述配置后,体验流程是:
- 在 macOS 上:启动 Ghostty 终端
- SSH 连接:
ssh user@code-server-host - 体验组合:Ghostty 渲染 + Starship 提示符
此时会看到:
- Ghostty 的流畅渲染和现代 UI
- Starship 的简洁高效提示符
- 同时保留 tmux 的会话管理能力
4.2 一些体验
字体一致性:
确保 Ghostty 使用的字体与 Starship 配置的图标兼容。使用 Nerd Font 系列(如 MesloLGS NF)可以避免图标显示问题。
颜色主题:
Ghostty 和 Starship 都支持主题自定义,可以选择配色方案保持一致:
- Ghostty:通过
theme配置项或自定义颜色 - Starship:在
starship.toml中配置模块颜色
性能:
Starship 比 powerlevel10k 更轻量,启动速度更快。在远程 SSH 环境中,这种性能优势更明显。