mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
909 字
3 分钟
Ghostty + Fish + Starship 终端美化方案
2025-04-15

Ghostty + Fish + Starship 终端美化方案#

这三个工具是什么?#

Ghostty — 终端模拟器#

Ghostty 是由 HashiCorp 创始人 Mitchell Hashimoto 开发的现代化终端模拟器。它是你看到的那个”窗口”,负责显示所有终端内容。

特点:

  • 原生 macOS 应用,使用 Metal 渲染,速度快
  • 支持 GPU 加速
  • 支持标签页、分屏
  • 配置简单,纯文本配置文件
  • 支持图片显示(Kitty 图片协议)

类比: 如果终端是一辆车,Ghostty 就是车身和挡风玻璃——你看到的一切界面都是它提供的。


Fish — Shell(命令行解释器)#

Fish(Friendly Interactive Shell)是一个现代化的 shell,替代默认的 zsh/bash。它是处理你输入的命令的那个程序。

特点:

  • 开箱即用的语法高亮(输入命令时自动变色)
  • 自动补全建议(灰色提示,按右箭头接受)
  • 无需额外配置就有很好体验
  • 基于 POSIX 但不完全兼容 bash 语法

类比: Fish 是发动机——你输入什么命令、命令怎么执行,都是它在处理。


Starship — 命令行提示符#

Starship 是一个跨 shell 的提示符(prompt)美化工具。它显示在你输入命令之前的那一行,提供 git 分支、目录、语言版本等信息。

特点:

  • 显示 git 状态(分支、修改数)
  • 显示当前目录
  • 显示 Node.js/Python/Go 等语言版本
  • 支持自定义模块
  • 跨 shell 通用(zsh、fish、bash 都能用)

类比: Starship 是仪表盘——它告诉你当前的状态信息(在哪个目录、git 什么分支、用的什么语言版本)。


它们怎么配合#

┌─────────────────────────────────────────────┐
│ Ghostty(终端窗口) │
│ ┌─────────────────────────────────────────┐ │
│ │ Starship 提示符 │ │
│ │ ~/project on main via 🐹 v1.21 │ │
│ │ │ │
│ │ Fish 处理命令 │ │
│ │ ❯ git status │ │
│ │ ❯ npm run dev │ │
│ └─────────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
  • Ghostty 提供窗口和渲染
  • Fish 在窗口里运行,处理你的命令
  • Starship 被 Fish 加载,美化提示符

安装过程#

1. 安装 Ghostty#

# 方式一:官网下载
# 访问 https://ghostty.org 下载 macOS 版本
# 方式二:Homebrew(如果有的话)
brew install --cask ghostty

安装后打开 Ghostty 即可使用。

2. 安装 Nerd Font(重要)#

Starship 的图标(如 git 分支的 、Node.js 的 )需要 Nerd Font 才能正确显示。推荐安装 JetBrains Mono Nerd Font:

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

安装完成后需要在 Ghostty 配置中指定使用该字体(见下方配置部分)。

2. 安装 Fish#

brew install fish

安装完成后,可以将 Fish 设为默认 shell:

# 将 fish 加入允许的 shell 列表
echo /opt/homebrew/bin/fish | sudo tee -a /etc/shells
# 设为默认 shell
chsh -s /opt/homebrew/bin/fish

3. 安装 Starship#

brew install starship

配置 shell 集成:

zsh(~/.zshrc):

echo 'eval "$(starship init zsh)"' >> ~/.zshrc

fish(~/.config/fish/config.fish):

mkdir -p ~/.config/fish
echo 'starship init fish | source' >> ~/.config/fish/config.fish

配置#

Ghostty 配置#

配置文件位置:~/.config/ghostty/config

# 创建配置目录
mkdir -p ~/.config/ghostty
# 写入配置
cat > ~/.config/ghostty/config << 'EOF'
# === 字体 ===
font-family = "JetBrainsMono Nerd Font"
font-size = 14
font-thicken = true
# === 主题 ===
theme = catppuccin-macchiato
# === 窗口 ===
window-padding-x = 10
window-padding-y = 6
background-opacity = 0.92
background-blur-radius = 20
window-decoration = auto
macos-titlebar-style = transparent
# === Shell ===
command = /opt/homebrew/bin/fish
# === 光标 ===
cursor-style = block
cursor-style-blink = true
# === 滚动 ===
scrollback-limit = 10000
# === 鼠标 ===
copy-on-select = true
mouse-hide-while-typing = true
# === 快捷键 ===
# 新建标签页
keybind = super+t=new_tab
# 关闭标签页
keybind = super+w=close_surface
# 水平分屏
keybind = super+d=new_split:right
# 垂直分屏
keybind = super+shift+d=new_split:down
# 切换分屏
keybind = super+alt+left=goto_split:left
keybind = super+alt+right=goto_split:right
keybind = super+alt+up=goto_split:up
keybind = super+alt+down=goto_split:down
# 全屏
keybind = super+enter=toggle_fullscreen
# 增大/减小字号
keybind = super+equal=increase_font_size:1
keybind = super+minus=decrease_font_size:1
keybind = super+zero=reset_font_size
EOF

配置说明:

  • font-family = "JetBrainsMono Nerd Font" — 使用 Nerd Font 版本以支持图标
  • command = /opt/homebrew/bin/fish — 默认使用 Fish shell
  • background-opacity = 0.92 — 轻微透明效果
  • background-blur-radius = 20 — 背景模糊(毛玻璃效果)
  • macos-titlebar-style = transparent — 透明标题栏

Starship 配置#

配置文件位置:~/.config/starship.toml

mkdir -p ~/.config
cat > ~/.config/starship.toml << 'EOF'
# 提示符格式
format = """
$username\
$hostname\
$directory\
$git_branch\
$git_status\
$nodejs\
$python\
$golang\
$rust\
$cmd_duration\
$line_break\
$character"""
# 字符模块(提示符符号)
[character]
success_symbol = "[❯](bold green)"
error_symbol = "[❯](bold red)"
# 目录
[directory]
truncation_length = 3
style = "bold cyan"
# Git
[git_branch]
symbol = " "
style = "bold purple"
[git_status]
style = "bold red"
# 命令耗时
[cmd_duration]
min_time = 2000
format = "took [$duration]($style) "
EOF

Fish 配置#

Fish 的配置在 ~/.config/fish/config.fish,一般不需要太多配置,开箱即用。如果需要自定义:

Terminal window
# 设置 greeting(启动时的欢迎语)
set -g fish_greeting ""
# 常用缩写
abbr -a gs git status
abbr -a gc git commit
abbr -a gp git push
abbr -a ll ls -la

使用技巧#

Ghostty 常用快捷键#

快捷键功能
Cmd + T新建标签页
Cmd + D水平分屏
Cmd + Shift + D垂直分屏
Cmd + Enter全屏切换
Cmd + 数字切换到第 N 个标签页

Fish 常用功能#

  • 自动补全: 输入命令时按 Tab 触发补全
  • 建议接受: 灰色建议文字按 →(右箭头)接受
  • 语法高亮: 有效命令绿色,无效命令红色

Starship 信息解读#

~/project on main via 🐹 v1.21 [!] is 📦 v1.0.0
  • ~/project — 当前目录
  • on main — git 分支
  • via 🐹 v1.21 — Go 版本
  • [!] — 有未提交的修改
  • is 📦 v1.0.0 — 项目版本

版本信息#

本次安装的版本:

  • Ghostty 1.1.3
  • Fish 4.0.2
  • Starship 1.23.0
  • JetBrains Mono Nerd Font 3.4.0

参考链接#

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Ghostty + Fish + Starship 终端美化方案
https://www.403bug.top/posts/ghostty-fish-starship/
作者
ma
发布于
2025-04-15
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录