Starship - 高颜值终端提示符工具安装与配置

本文最后更新于:2026年7月24日 晚上

前言

Starship 是一个用 Rust 编写的跨平台终端提示符工具,以轻量、快速、高度可定制著称。相比 oh-my-zsh 的主题,Starship 不依赖 zsh 框架,支持 Bash/Zsh/Fish/PowerShell 等所有主流 Shell,真正做到了「一次配置,处处生效」。

GitHub:starship/starship

安装

前置要求:Nerd Font

Starship 显示图标依赖 Nerd Font,推荐安装 FiraCode Nerd Font

1
brew install --cask font-firacode-nerd-font

安装后需在终端设置中将字体切换为 FiraCode Nerd Font。

macOS 安装(Homebrew)

1
brew install starship

一键安装脚本(Linux/macOS/Windows)

1
curl -sS https://starship.rs/install.sh | sh

其他包管理器

系统 命令
Arch pacman -S starship
Debian/Ubuntu apt install starship
Fedora dnf copr enable atim/starship && dnf install starship
Conda conda install -c conda-forge starship
Cargo cargo install starship --locked

初始化配置

Zsh(最常见)

~/.zshrc 末尾添加:

1
eval "$(starship init zsh)"

Bash

~/.bashrc 末尾添加:

1
eval "$(starship init bash)"

Fish

~/.config/fish/config.fish 末尾添加:

1
starship init fish | source

PowerShell

$PROFILE 末尾添加:

1
Invoke-Expression (&starship init powershell)

配置文件

Starship 的配置文件位于 ~/.config/starship.toml(需先创建目录):

1
mkdir -p ~/.config && touch ~/.config/starship.toml

配置文件为 TOML 格式,所有可配置项可在 官方配置文档 查看。

常用配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# ~/.config/starship.toml

# 启用 JSON Schema 方便编辑器补全
"$schema" = 'https://starship.rs/config-schema.json'

# 提示符换行
add_newline = true

# 命令提示符符号
[character]
success_symbol = "[❯](bold green)"
error_symbol = "[❯](bold red)"
vimcmd_symbol = "[❮](bold green)"

# 当前目录
[directory]
truncation_length = 3
truncate_to_repo = true
style = "bold cyan"
home_symbol = "~"

# Git 分支
[git_branch]
symbol = " "
style = "bold purple"

# Git 状态
[git_status]
style = "bold red"
conflicted = "⚔️ "
ahead = "⇡${count}"
behind = "⇣${count}"
untracked = "?${count}"
modified = "!${count}"
stashed = "\\$${count}"
staged = "+[${count}]"

# 编程语言版本(按需启用)
[nodejs]
symbol = " "
style = "bold green"

[python]
symbol = " "
style = "bold yellow"

[rust]
symbol = " "
style = "bold red"

[golang]
symbol = " "
style = "bold cyan"

# 命令执行耗时(超过 2s 才显示)
[CmdDur]
min_time = 2000
style = "bold yellow"

预设主题

不想自己配置?Starship 提供了大量预设,直接应用即可:

1
2
3
4
starship preset catppuccin-mocha   # Catppuccin Mocha 配色
starship preset tokyo-night # Tokyo Night 配色
starship preset nerd-font-compat # 兼容 Nerd Font 图标
starship preset plain-text # 无图标纯文本

查看所有预设:starship.rs/presets

常用命令

1
2
3
4
5
starship config              # 编辑配置(打开 starship.toml)
starship init zsh # 重新初始化
starship prompt # 预览当前提示符样式
starship module --list # 列出所有可用模块
starship version # 查看版本

与 p10k (Powerlevel10k) 的对比

特性 Starship Powerlevel10k
Shell 依赖 无(跨平台) 依赖 oh-my-zsh
性能 Rust 实现,极快 Zsh 内置,较快
配置方式 TOML 文件 Zsh 变量
图标支持 Nerd Font,原生 亦需 Nerd Font
预设生态 丰富 需手动配置

我的选择:Starship,因为它更轻量、配置更简洁,且不绑定特定 Shell。


📝 待发布审稿 — 草稿状态,需确认内容准确性后再发布。


Starship - 高颜值终端提示符工具安装与配置
https://kingjem.github.io/2026/03/21/Starship-高颜值终端提示符工具安装与配置/
作者
Ruhai
发布于
2026年3月21日
许可协议