韩老魔的博客0XHANNIBA1 · NOTES

一键安装 Ghostty + Starship 配置

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# 一键安装 Ghostty + Starship 配置 (适用于 macOS + zsh)

set -e

echo ">>> 检查 Homebrew"
if ! command -v brew &>/dev/null; then
echo "未检测到 Homebrew,请先安装: https://brew.sh/"
exit 1
fi

echo ">>> 安装 starship"
brew install starship

echo ">>> 安装 Nerd Font (JetBrainsMono)"
brew tap homebrew/cask-fonts
brew install --cask font-jetbrains-mono-nerd-font

echo ">>> 创建配置目录"
mkdir -p ~/.config/ghostty
mkdir -p ~/.config

echo ">>> 写入 Ghostty 配置"
cat > ~/.config/ghostty/config << 'EOF'
# ===== Ghostty: Gruvbox Rainbow + Nerd Font =====

# --- 字体 ---
font-family = "JetBrainsMono Nerd Font"
font-size = 14

# Gruvbox Rainbow 配色
background = #282828
foreground = #ebdbb2
cursor-color = #d79921
cursor-text = #282828
selection-background = #504945
selection-foreground = #ebdbb2

# ANSI 颜色表
palette = 0=#282828
palette = 1=#fb4934
palette = 2=#b8bb26
palette = 3=#fabd2f
palette = 4=#83a598
palette = 5=#d3869b
palette = 6=#8ec07c
palette = 7=#ebdbb2
palette = 8=#928374
palette = 9=#fb4934
palette = 10=#b8bb26
palette = 11=#fabd2f
palette = 12=#83a598
palette = 13=#d3869b
palette = 14=#8ec07c
palette = 15=#ebdbb2
EOF

echo ">>> 写入 Starship 配置"
mkdir -p ~/.config
cat > ~/.config/starship.toml << 'EOF'
# ===== Starship Prompt 配置 =====
add_newline = false

format = """
[](#9A348E)\
$os\
$username\
[](bg:#DA627D fg:#9A348E)\
$directory\
[](fg:#DA627D bg:#FCA17D)\
$git_branch\
$git_status\
[](fg:#FCA17D bg:#86BBD8)\
$nodejs\
[](fg:#86BBD8 bg:#06969A)\
$time\
[ ](fg:#06969A)\
"""

[os]
disabled = false
style = "bg:#9A348E fg:#ffffff"

[username]
style_user = "bg:#9A348E fg:#ffffff"
show_always = true

[directory]
style = "bg:#DA627D fg:#ffffff"
truncation_length = 3
truncate_to_repo = false

[git_branch]
style = "bg:#FCA17D fg:#000000"

[git_status]
style = "bg:#FCA17D fg:#000000"

[nodejs]
symbol = "⬢ "
style = "bg:#86BBD8 fg:#000000"

[time]
disabled = false
time_format = "%H:%M"
style = "bg:#06969A fg:#ffffff"
EOF

echo ">>> 配置 zsh 自动加载 starship"
if ! grep -q 'eval "$(starship init zsh)"' ~/.zshrc; then
echo 'eval "$(starship init zsh)"' >> ~/.zshrc
fi

echo ">>> 完成!请重启终端 (Ghostty) 查看效果 🎉"

使用方法:

1
2
chmod +x setup_ghostty_starship.sh
./setup_ghostty_starship.sh
image-20250819233320578

Tweaks