简介
Starship 是一个用 Rust 编写的跨平台终端提示符(prompt),毫秒级启动,开箱即用,支持 Bash、Zsh、Fish、PowerShell 等多种 Shell。
特点:
- 快:启动 < 10ms,几乎无感知
- 跨平台:macOS、Linux、Windows 统一体验
- 配置即代码:一个
starship.toml接管所有 - 智能检测:自动显示 Git、Node.js、Python、Docker 等环境信息
macOS 安装
1. 安装 Starship
brew install starship
2. 初始化到 Shell
Zsh(~/.zshrc):
eval "$(starship init zsh)"
Bash(~/.bashrc):
eval "$(starship init bash)"
Fish(~/.config/fish/config.fish):
starship init fish | source
3. 验证
重启终端,运行:
starship --version
预期输出:starship 1.x.x
4. 卸载
brew uninstall starship
然后从 Shell 配置文件中删掉 eval "$(starship init ...)" 那一行。
Windows 安装
方法一:Scoop(推荐)
scoop install starship
方法二:winget
winget install --id Starship.Starship
方法三:手动安装
从 GitHub Releases 下载 starship-x86_64-pc-windows-msvc.zip,解压到 C:\Program Files\starship\,然后将其添加到系统 PATH。
初始化到 PowerShell
编辑 $PROFILE:
Invoke-Expression (&starship init powershell)
验证
starship --version
Linux 安装
curl -sS https://starship.rs/install.sh | sh
脚本会自动检测架构并安装到 ~/.local/bin/。确保该目录在 PATH 中,然后同样在 ~/.zshrc 或 ~/.bashrc 中添加 eval "$(starship init zsh)"。
字体配置(Nerd Font)
Starship 使用 Nerd Font 图标,必须先装字体。
macOS
brew install --cask font-fira-code-nerd-font
brew install --cask font-jetbrains-mono-nerd-font
Windows
从 Nerd Fonts Releases 下载安装 JetBrains Mono Nerd Font 或 Fira Code Nerd Font。
配置终端
在各终端的字体设置中选择刚安装的 Nerd Font 即可。
基本配置
配置文件位置:
- macOS / Linux:
~/.config/starship.toml - Windows:
%USERPROFILE%\.config\starship.toml
最小配置
mkdir -p ~/.config && touch ~/.config/starship.toml
# starship.toml
add_newline = false
[character]
success_symbol = "[➜](bold green)"
error_symbol = "[➜](bold red)"
常用模块配置
[directory]
style = "bold cyan"
truncation_length = 3
truncation_symbol = "…/"
[git_branch]
symbol = "🌱 "
[git_status]
ahead = "⇡${count}"
behind = "⇣${count}"
[nodejs]
symbol = "⬢ "
style = "bold green"
[python]
symbol = "🐍 "
style = "bold yellow"
使用预设
Starship 提供多个官方预设:
# 预览所有预设
starship preset --list
# 应用一个预设
starship preset tokyo-night > ~/.config/starship.toml
常用预设:tokyo-night、gruvbox-rainbow、pastel-powerline、pure-preset。
常见问题
提示符显示乱码
原因:未安装 Nerd Font。按上面的字体配置章节操作即可。
模块不显示
starship explain # 检查当前配置
starship print # 打印当前提示符
启动慢
starship timings # 查看各模块耗时
禁用不常用的模块来优化:
[package]
disabled = true
[python]
disabled = true
颜色显示不对
确保终端支持真彩色:
echo $COLORTERM
# 期望输出:truecolor 或 256color
参考资料
🔗 原文链接
分享让更多人看到