概述
这是一套面向 macOS 开发者的终端方案,核心理念是开箱即用、高颜值、高效率。六个工具各司其职,十分钟内完成安装配置,无需手写复杂配置文件。
工具链
| 工具 | 角色 | 核心亮点 |
|---|---|---|
| Ghostty | 终端模拟器 | GPU 加速渲染、内置 100+ 主题、零配置启动 |
| Fish | Shell | 语法高亮、自动补全、历史建议全开箱自带 |
| Starship | 提示符 | 跨平台兼容,一行命令预设主题 |
| fzf | 模糊查找器 | 命令历史/文件/目录即时模糊匹配 |
| zoxide | 智能目录跳转 | 学习访问习惯,关键词秒跳目录 |
| Raycast | 效率启动器 | 取代 Spotlight,统一开发者工作流入口 |
二、前置条件
- macOS 系统
- 已安装 Homebrew
# 如未安装 Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # 验证 brew --version三、安装步骤
1. 安装 Nerd Font
必须先装字体。Starship 和 fzf 依赖特殊图标字符(Git 分支符号、文件夹图标、箭头分隔符等),普通字体无法显示,会变成乱码方块。
brew install font-meslo-lg-nerd-font验证安装:
system_profiler SPFontsDataType | grep -i "meslo"看到MesloLGS NF即表示成功。也可在 Font Book(字体册)中搜索Meslo确认。
2. 安装 Ghostty
brew install --cask ghostty2.1 预览内置主题
ghostty +list-themes按Esc或q退出预览。
2.2 创建配置文件
配置文件路径:~/Library/Application Support/com.mitchellh.ghostty/ghostty.config
mkdir -p ~/Library/Application\ Support/com.mitchellh.ghostty vim ~/Library/Application\ Support/com.mitchellh.ghostty/config.ghostty theme = "tokyonight" font-family = "MesloLGS NF" font-size = 14 font-thicken = true background-opacity = 0.95 background-blur = true window-padding-x = 10 window-padding-y = 5 keybind = cmd+alt+right=next_tab keybind = cmd+alt+left=previous_tab配置完成后Cmd + Q 退出 Ghostty,重新打开使配置生效。
2.3 分屏快捷键
| 快捷键 | 功能 |
|---|---|
Cmd + D | 竖直分割 |
Cmd + Shift + D | 水平分割 |
Cmd + Option + 方向键 | 切换焦点窗格 |
输入exit或Ctrl + D | 关闭当前窗格 |
3. 安装 Fish Shell
brew install fish3.1 设为默认 Shell
# 确认安装路径 which fish # 加入系统合法 Shell 列表 echo /opt/homebrew/bin/fish | sudo tee -a /etc/shells # 设为默认 chsh -s /opt/homebrew/bin/fishCmd + Q 退出终端,重新打开。验证:
echo $SHELL # 输出 /opt/homebrew/bin/fish3.2 Fish 核心特性
Fish 三大核心功能均为原生自带,无需安装任何插件:
- 语法高亮:输入命令时自动对命令、参数、字符串进行着色
- 自动建议:基于历史记录给出灰色建议文本,按
→键接受 - 智能补全:Tab 补全带文字描述,信息量远超 Bash/Zsh
4. 安装 Starship
brew install starship4.1 一键生成预设主题
mkdir -p ~/.config starship preset tokyo-night -o ~/.config/starship.toml命令无输出但已自动生成配置文件。可查看:
cat ~/.config/starship.toml可选预设主题还包括:gruvbox-rainbow、catppuccin-powerline、pastel-powerline等。
4.2 创建 Fish 配置并加载 Starship
vim ~/.config/fish/config.fish if status is-interactive set -U fish_greeting starship init fish | source end
if status is-interactive是 Fish 推荐的结构,确保仅交互式会话加载配置,脚本执行时跳过以节省资源。
加载配置:
source ~/.config/fish/config.fish提示符即刻生效。Starship 会自动显示:当前目录、Git 分支、编程语言版本(Node/Python/Go 等)、命令执行状态等信息。
5. 安装 fzf
brew install fzf5.1 运行安装脚本
/opt/homebrew/opt/fzf/install所有询问选y。
5.2 处理路径问题(如需要)
# 确认安装 which fzf fzf --version5.3 追加 fzf 配置
open -t ~/.config/fish/config.fish在starship init fish | source和end之间添加:
# fzf fzf --fish | source set -gx FZF_CTRL_T_OPTS "--walker-skip .git,node_modules,target"保存后加载:
source ~/.config/fish/config.fish5.4 快捷键说明
Mac 键盘上
Alt键即Option (⌥),Ctrl键即Control (⌃),不要与Cmd (⌘)混淆。
| 快捷键 | 功能 |
|---|---|
Ctrl + R | 模糊搜索命令历史 |
Ctrl + T | 模糊搜索当前目录文件 |
Alt + C | 模糊搜索并跳转目录 |
6. 安装 zoxide
brew install zoxide6.1 追加配置
open -t ~/.config/fish/config.fish在 fzf 配置下方添加:
# zoxide zoxide init fish | source保存后加载:
source ~/.config/fish/config.fish6.2 使用方法
z keyword # 跳转到历史访问过的最佳匹配目录 z keyword1 keyword2 # 匹配包含两个关键词的目录 zi # 交互式模糊选择(需 fzf 支持) z - # 返回上一个目录zoxide 在后台自动记录访问路径和频率,无需手动维护。
7. 追加别名
open -t ~/.config/fish/config.fish在 zoxide 配置下方、end之前添加:
# 别名 alias ll "ls -lh" alias la "ls -lAh" end