【GIT】https://gitee.com/luojinzhi0108/Glean.git
【视频演示】 【【拾零】0 - 开箱即用的现代风终端】 https://www.bilibili.com/video/BV1YhoQBGEj6/?share_source=copy_web&vd_source=c6e72a4705f5de2407182db1367836d0

开箱即用的现代风:不用深度折腾,也能有顶级的效率和审美。

一、概述

这是一套面向 macOS 开发者的终端方案,核心理念是开箱即用、高颜值、高效率。六个工具各司其职,十分钟内完成安装配置,无需手写复杂配置文件。

工具链

工具 角色 核心亮点
Ghostty 终端模拟器 GPU 加速渲染、内置 100+ 主题、零配置启动
Fish Shell 语法高亮、自动补全、历史建议全开箱自带
Starship 提示符 跨平台兼容,一行命令预设主题
fzf 模糊查找器 命令历史/文件/目录即时模糊匹配
zoxide 智能目录跳转 学习访问习惯,关键词秒跳目录
Raycast 效率启动器 取代 Spotlight,统一开发者工作流入口

二、前置条件

# 如未安装 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 ghostty

2.1 预览内置主题

ghostty +list-themes

Escq 退出预览。

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 + 方向键 切换焦点窗格
输入 exitCtrl + D 关闭当前窗格

3. 安装 Fish Shell

brew install fish

3.1 设为默认 Shell

# 确认安装路径
which fish

# 加入系统合法 Shell 列表
echo /opt/homebrew/bin/fish | sudo tee -a /etc/shells

# 设为默认
chsh -s /opt/homebrew/bin/fish

Cmd + Q 退出终端,重新打开。验证:

echo $SHELL
# 输出 /opt/homebrew/bin/fish

3.2 Fish 核心特性

Fish 三大核心功能均为原生自带,无需安装任何插件:

  • 语法高亮:输入命令时自动对命令、参数、字符串进行着色
  • 自动建议:基于历史记录给出灰色建议文本,按 键接受
  • 智能补全:Tab 补全带文字描述,信息量远超 Bash/Zsh

4. 安装 Starship

brew install starship

4.1 一键生成预设主题

mkdir -p ~/.config
starship preset tokyo-night -o ~/.config/starship.toml

命令无输出但已自动生成配置文件。可查看:

cat ~/.config/starship.toml

可选预设主题还包括:gruvbox-rainbowcatppuccin-powerlinepastel-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 fzf

5.1 运行安装脚本

/opt/homebrew/opt/fzf/install

所有询问选 y

5.2 处理路径问题(如需要)

# 确认安装
which fzf
fzf --version

5.3 追加 fzf 配置

open -t ~/.config/fish/config.fish

starship init fish | sourceend 之间添加:

    # fzf
    fzf --fish | source
    set -gx FZF_CTRL_T_OPTS "--walker-skip .git,node_modules,target"

保存后加载:

source ~/.config/fish/config.fish

5.4 快捷键说明

Mac 键盘上 Alt 键即 Option (⌥)Ctrl 键即 Control (⌃),不要与 Cmd (⌘) 混淆。

快捷键 功能
Ctrl + R 模糊搜索命令历史
Ctrl + T 模糊搜索当前目录文件
Alt + C 模糊搜索并跳转目录

6. 安装 zoxide

brew install zoxide

6.1 追加配置

open -t ~/.config/fish/config.fish

在 fzf 配置下方添加:

    # zoxide
    zoxide init fish | source

保存后加载:

source ~/.config/fish/config.fish

6.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

四、最终配置文件

Ghostty 配置

路径~/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

Fish 配置

路径~/.config/fish/config.fish

if status is-interactive
    set -U fish_greeting
    starship init fish | source

    # fzf
    fzf --fish | source
    set -gx FZF_CTRL_T_OPTS "--walker-skip .git,node_modules,target"

    # zoxide
    zoxide init fish | source

    # 别名
    alias ll "ls -lh"
    alias la "ls -lAh"
end

Starship 配置

路径~/.config/starship.toml

starship preset tokyo-night 自动生成,无需手动编辑。


五、Raycast(可选)

raycast.com 下载安装,将快捷键设为 Cmd + Space 以取代 Spotlight。

推荐扩展

在 Raycast(Cmd + Space)中输入 Store 进入扩展商店:

  • Brew — 管理 Homebrew 包(安装、升级、清理)
  • GitHub — 查看 Issues、PRs、通知
  • Clipboard History — 剪贴板历史管理

六、进阶彩蛋

eza(现代 ls 替代)

brew install eza

# 添加到 config.fish 别名区,替换原有 ls 别名
alias ls "eza"
alias ll "eza -lh --git"
alias tree "eza --tree"

恢复 Ghostty 默认配置

rm -f ~/Library/Application\ Support/com.mitchellh.ghostty/config.ghostty
# Cmd + Q 退出 Ghostty 重新打开即恢复出厂设置

常用命令速查

功能 命令
预览所有主题 ghostty +list-themes --preview
查看当前主题 ghostty +show-theme
搜索文件 fzf
搜索历史 history | fzf
搜索目录 cd (find . -type d | fzf)
智能跳转 z <关键词>
交互式跳转 zi
返回上一目录 z -

七、安装顺序总结

Nerd Font → Ghostty → Fish → Starship → fzf → zoxide → 别名
    ↓          ↓        ↓        ↓       ↓       ↓
  先装字体   Cmd+Q退出  临时进入  生成配置  装完    装完
  后面引用   重开生效   演示完    再写配置  再追加  再追加
                      再改默认   source   source  source

原则:装一个工具 → 验证安装成功 → 追加配置 → source 加载 → 再装下一个。