ghostty conf
font-family = "ZedMono NFM Extd"
font-style-bold = "Medium"
font-style-bold-italic = "Medium Italic"
font-size = 13.4
font-thicken = true
grapheme-width-method = "unicode"
adjust-cell-width = -5%
palette = 0=#212733
palette = 1=#f08778
palette = 2=#53bf97
palette = 3=#fdcc60
palette = 4=#60b8d6
palette = 5=#ec7171
palette = 6=#98e6ca
palette = 7=#fafafa
palette = 8=#686868
palette = 9=#f58c7d
palette = 10=#58c49c
palette = 11=#ffd165
palette = 12=#65bddb
palette = 13=#f17676
palette = 14=#9debcf
palette = 15=#ffffff
background = #1f2430
foreground = #cbccc6
selection-invert-fg-bg = true
cursor-style = "bar"
cursor-style-blink = true
scrollback-limit = 100000
window-padding-x = 20
window-padding-y = 2,10
window-save-state = "always"
2.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 = true
Ghostty 的一大优势是零配置即可使用,上述配置可根据个人喜好调整。
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。