这是一套偏日常开发使用的 macOS 终端配置:使用 Ghostty 作为终端模拟器,使用 Oh My Zsh 管理 Zsh 配置和插件,最后用 Starship 接管命令行提示符。

目标

  • Ghostty:终端应用,启动快,默认配置已经足够可用。
  • Oh My Zsh:管理 Zsh 配置、插件和常用别名。
  • Oh My Zsh plugins:补全、建议、高亮、Git、sudo 等效率插件。
  • Starship:跨 shell 的命令行提示符,替代 Oh My Zsh 主题。

准备

确认当前 shell 是 Zsh:

echo $SHELL
zsh --version

如果当前不是 Zsh,可以切换为 macOS 自带的 Zsh:

chsh -s /bin/zsh

安装 Homebrew 后,后续工具都可以统一用 brew 管理:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update

安装 Ghostty

Ghostty 的 macOS 版本可以直接下载安装,也可以通过 Homebrew Cask 安装:

brew install --cask ghostty

启动 Ghostty:

open -a Ghostty

Ghostty 不强制要求配置文件。需要自定义时,推荐使用 XDG 路径:

mkdir -p ~/.config/ghostty
touch ~/.config/ghostty/config.ghostty

一个简单配置示例:

# 列出内置主题
ghostty +list-themes
# ~/.config/ghostty/config.ghostty

# --- Theme and Color ---
#theme = Dracula
#theme = Catppuccin Mocha
theme = Catppuccin Frappe
#font-family = JetBrainsMono Nerd Font
font-family = Maple Mono NF CN

# --- Window ---
background-opacity = 0.9
background-blur-radius = 20
window-save-state = always
confirm-close-surface = false
quit-after-last-window-closed = true
unfocused-split-opacity = 0.5
split-divider-color=white

# --- keybind ---
keybind = cmd+r=clear_screen

# --- Copy ---
clipboard-trim-trailing-spaces = true

# --- Mouse ---
mouse-hide-while-typing = true
#copy-on-select = clipboard

# --- Security ---
clipboard-paste-protection = true
clipboard-paste-bracketed-safe = true

# 自动将本地的 Ghostty terminfo 文件同步到远程主机,解决终端报错和按键异常
shell-integration-features = ssh-terminfo

# 自动将远程终端的环境变量 TERM 设为 xterm-256color 以最大化兼容性
#shell-integration-features = ssh-env

如果字体图标显示异常,安装 Nerd Font:

brew install --cask font-jetbrains-mono-nerd-font

修改配置后,Ghostty 在 macOS 下可以用 Command + Shift + , 重新加载配置。

Ghostty 常用快捷键

Ghostty 的快捷键可以通过命令查看:

ghostty +list-keybinds --default

macOS 下常用默认快捷键:

快捷键作用
Command + ,打开配置文件
Command + Shift + ,重新加载配置
Command + Shift + P打开命令面板
Command + N新建窗口
Command + T新建标签页
Command + Shift + [上一个标签页
Command + Shift + ]下一个标签页
Command + 1Command + 8跳转到指定标签页
Command + 9跳转到最后一个标签页
Command + W关闭当前 surface
Command + Option + W关闭当前标签页
Command + D向右分屏
Command + Shift + D向下分屏
Command + [切换到上一个分屏
Command + ]切换到下一个分屏
Command + Option + 方向键按方向切换分屏
Command + Control + 方向键调整分屏大小
Command + Control + =平均分配分屏大小
Command + Shift + Enter当前分屏最大化 / 还原
Command + Enter全屏 / 退出全屏
Command + F搜索
Command + G下一个搜索结果
Command + Shift + G上一个搜索结果
Command + K清屏
Command + =放大字体
Command + -缩小字体
Command + 0重置字体大小
Command + C复制
Command + V粘贴

在 Ghostty 配置文件里,Command 对应 supercmdOption 对应 altopt。自定义快捷键使用 keybind = trigger=action

# ~/.config/ghostty/config.ghostty

# 取消某个默认快捷键
keybind = super+shift+t=unbind

# 使用 Command + R 重新加载配置
keybind = super+r=reload_config

# 使用 Command + \ 向右分屏
keybind = super+backslash=new_split:right

修改快捷键后,使用 Command + Shift + , 重新加载配置。

安装 Oh My Zsh

执行官方安装脚本:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装完成后,主要配置文件是:

~/.zshrc

确认 Oh My Zsh 路径:

echo $ZSH

通常会输出:

/Users/yourname/.oh-my-zsh

安装常用插件

Oh My Zsh 自带很多插件,不需要额外安装,只要写进 plugins=(...) 即可。

常用内置插件:

plugins=(
  extract
  colored-man-pages
  command-not-found
  git
  docker
  z
  zsh-autosuggestions
  zsh-syntax-highlighting
  you-should-use
  wd
)

# linux 可以添加 sudo 插件
# `zsh-syntax-highlighting` 建议放在插件列表最后,避免被其他插件覆盖高亮逻辑。

另外推荐安装两个外部插件:

git clone https://github.com/zsh-users/zsh-autosuggestions \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone https://github.com/MichaelAquilina/zsh-you-should-use.git \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use

重新加载配置:

source ~/.zshrc

安装 Starship

Starship 用来显示当前目录、Git 分支、Node.js、Python、Docker、Kubernetes 等上下文信息。它负责提示符,所以不再使用 Oh My Zsh 的主题。

安装:

brew install starship

编辑 ~/.zshrc,把 Oh My Zsh 主题关掉:

ZSH_THEME=""

~/.zshrc 文件末尾加入:

eval "$(starship init zsh)"

重新加载:

source ~/.zshrc

查看 Starship 生效情况:

starship --version
starship explain

Starship 基础配置

starship preset catppuccin-powerline -o ~/.config/starship.toml

starship preset jetpack -o ~/.config/starship.toml

更新

更新 Homebrew 安装的软件:

brew update
brew upgrade
brew upgrade --cask ghostty

更新 Oh My Zsh:

omz update

更新外部插件:

git -C ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions pull
git -C ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting pull
git -C ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/you-should-use pull

排查

Starship 没有显示

确认 ~/.zshrc 末尾有:

eval "$(starship init zsh)"

并确认 starship 在 PATH 中:

which starship

图标乱码

安装 Nerd Font,并在 Ghostty 配置里指定字体:

brew install --cask font-jetbrains-mono-nerd-font
brew install --cask font-maple-mono-nf-cn
font-family = JetBrainsMono Nerd Font
font-family = Maple Mono NF CN

插件没有生效

确认插件目录存在:

ls ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins

确认 ~/.zshrc 里已经写入插件名,并重新加载:

source ~/.zshrc

参考