Repository navigation
Expand file tree
/
Copy pathstatusline-command.sh
More file actions
executable file
·300 lines (258 loc) · 9.38 KB
/
Copy pathstatusline-command.sh
File metadata and controls
executable file
·300 lines (258 loc) · 9.38 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
# Claude Code StatusLine - mirrors Powerlevel10k prompt
# Based on ~/.dotfiles/zsh/p10k.customizations.zsh
input=$(cat)
cwd=$(echo "$input" | jq -r '.workspace.current_dir')
project_dir=$(echo "$input" | jq -r '.workspace.project_dir')
# Change to cwd for git commands
cd "$cwd" 2>/dev/null || cd ~
# Initialize segments (two lines: line1 = dir/branch/context/cost, line2 = model)
line1=()
line2=()
# Directory (relative to project if in project)
if [[ "$cwd" == "$project_dir"* ]] && [[ -n "$project_dir" ]]; then
rel_path="${cwd#$project_dir}"
rel_path="${rel_path#/}"
if [[ -z "$rel_path" ]]; then
dir_display="$(basename "$project_dir")"
else
dir_display="$(basename "$project_dir")/$rel_path"
fi
else
dir_display="${cwd/#$HOME/~}"
fi
folder_icon=$'\xEF\x81\xBB' # U+F07B nerd font folder
line1+=("$(printf '\033[34m%s %s\033[0m' "$folder_icon" "$dir_display")")
# Git status & branch
if git rev-parse --is-inside-work-tree &>/dev/null; then
branch=$(git branch --show-current 2>/dev/null)
# Branch & status indicators
if [[ -n "$branch" ]]; then
status=$(git --no-optional-locks status --porcelain 2>/dev/null)
# Count status indicators
staged=0
modified=0
untracked=0
deleted=0
while IFS= read -r line; do
[[ -z "$line" ]] && continue
x="${line:0:1}"
y="${line:1:1}"
# Staged changes (index)
[[ "$x" =~ [MADRC] ]] && ((staged++))
# Unstaged modifications
[[ "$y" == "M" ]] && ((modified++))
# Deleted files
[[ "$y" == "D" ]] && ((deleted++))
# Untracked files
[[ "$x" == "?" ]] && ((untracked++))
done <<< "$status"
# Build branch segment with icon (U+E0A0 = \356\202\240)
if [[ -n "$status" ]]; then
# Modified (cyan)
branch_seg="$(printf '\033[36m\356\202\240 %s\033[0m' "$branch")"
else
# Clean (green)
branch_seg="$(printf '\033[32m\356\202\240 %s\033[0m' "$branch")"
fi
# Add status indicators
indicators=""
# Commits ahead/behind upstream (first)
upstream=$(git rev-parse --abbrev-ref "@{upstream}" 2>/dev/null)
if [[ -n "$upstream" ]]; then
ahead=$(git rev-list --count "@{upstream}..HEAD" 2>/dev/null)
behind=$(git rev-list --count "HEAD..@{upstream}" 2>/dev/null)
[[ $behind -gt 0 ]] && indicators+="$(printf '\033[36m↓%d\033[0m ' "$behind")"
[[ $ahead -gt 0 ]] && indicators+="$(printf '\033[36m↑%d\033[0m ' "$ahead")"
fi
# File status indicators
[[ $staged -gt 0 ]] && indicators+="$(printf '\033[32m+%d\033[0m ' "$staged")"
[[ $modified -gt 0 ]] && indicators+="$(printf '\033[33m!%d\033[0m ' "$modified")"
[[ $deleted -gt 0 ]] && indicators+="$(printf '\033[31m-%d\033[0m ' "$deleted")"
[[ $untracked -gt 0 ]] && indicators+="$(printf '\033[31m?%d\033[0m ' "$untracked")"
# Trim trailing space
indicators="${indicators% }"
# Combine branch and indicators
if [[ -n "$indicators" ]]; then
line1+=("$(printf '%b %s' "$branch_seg" "$indicators")")
else
line1+=("$branch_seg")
fi
fi
fi
# Model name (with effort level if model supports it)
model_name=$(echo "$input" | jq -r '.model.display_name')
model_name="${model_name%% (*}" # Strip context suffix, e.g. " (1M context)"
effort=$(echo "$input" | jq -r '.effort.level // empty')
if [[ -n "$model_name" ]] && [[ "$model_name" != "null" ]]; then
if [[ -n "$effort" ]]; then
line2+=("$(printf '\033[35m%s\033[0m \033[2m%s\033[0m' "$model_name" "$effort")")
else
line2+=("$(printf '\033[35m%s\033[0m' "$model_name")")
fi
fi
# Rate limits (Claude.ai Pro/Max only; absent otherwise). Shows remaining % + reset countdown.
now=$(date +%s)
format_reset() {
local remaining=$(( $1 - now ))
(( remaining < 0 )) && remaining=0
local d=$(( remaining / 86400 ))
local h=$(( (remaining % 86400) / 3600 ))
local m=$(( (remaining % 3600) / 60 ))
if (( d > 0 )); then
printf '%dd%dh' "$d" "$h"
elif (( h > 0 )); then
printf '%dh%dm' "$h" "$m"
else
printf '%dm' "$m"
fi
}
limit_color() {
# Color by usage: green low, yellow high, red critical
if (( $1 >= 90 )); then printf '\033[31m'
elif (( $1 >= 75 )); then printf '\033[33m'
else printf '\033[32m'; fi
}
build_limit_seg() {
local label=$1 used=$2 resets=$3
local used_int=${used%.*}
printf '%b%s %d%%\033[0m \033[2m↻%s\033[0m' \
"$(limit_color "$used_int")" "$label" "$used_int" "$(format_reset "$resets")"
}
five_used=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
five_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
seven_used=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
seven_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
[[ -n "$five_used" ]] && line2+=("$(build_limit_seg "5h" "$five_used" "$five_reset")")
# Weekly window only surfaces once it's worth watching (>50% used)
[[ -n "$seven_used" ]] && (( ${seven_used%.*} > 50 )) && line2+=("$(build_limit_seg "7d" "$seven_used" "$seven_reset")")
# Context window with gradient bar
# Auto-compact buffer (33K) from Claude Code source
_ctx_tokens=$(echo "$input" | jq -r '.context_window.current_usage | .input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
_ctx_size=$(echo "$input" | jq -r '.context_window.context_window_size')
_ctx_effective=$(( _ctx_size - 33000 ))
pct=$(( _ctx_tokens * 100 / _ctx_effective )) 2>/dev/null
if [[ -n "$pct" && "$pct" -gt 0 ]] 2>/dev/null; then
# Heatmap colors for positions 0-9 (green → yellow → red)
# True color RGB values interpolated by position
heatmap_color() {
local pos=$1
local r g b
if [[ $pos -lt 5 ]]; then
# Green (0,180,0) → Yellow (220,180,0)
r=$((pos * 220 / 5))
g=180
b=0
else
# Yellow (220,180,0) → Red (220,60,0)
r=220
g=$((180 - (pos - 5) * 120 / 5))
b=0
fi
printf '\033[38;2;%d;%d;%dm' "$r" "$g" "$b"
}
# Build 10-char bar with 40-step precision (4 gradient levels per char)
steps=$((pct * 40 / 100))
[[ $steps -gt 40 ]] && steps=40
full=$((steps / 4))
partial=$((steps % 4))
empty=$((10 - full - (partial > 0 ? 1 : 0)))
# Colors
dim=$'\033[38;5;238m'
reset=$'\033[0m'
# Rounded caps (powerline round separators)
left_cap=$'\xEE\x82\xB6' # U+E0B6 round left
right_cap=$'\xEE\x82\xB4' # U+E0B4 round right
# Build bar with per-segment heatmap colors
bar=""
pos=0
for ((i=0; i<full; i++)); do
bar+="$(heatmap_color $pos)█"
((pos++))
done
# Partial segment: progressively dimmed based on fill level
# ▓ (75%) = 80% bright, ▒ (50%) = 55% bright, ░ (25%) = 35% bright
heatmap_color_partial() {
local pos=$1 brightness=$2
local r g b
if [[ $pos -lt 5 ]]; then
r=$((pos * 220 / 5 * brightness / 100))
g=$((180 * brightness / 100))
b=0
else
r=$((220 * brightness / 100))
g=$(((180 - (pos - 5) * 120 / 5) * brightness / 100))
b=0
fi
printf '\033[38;2;%d;%d;%dm' "$r" "$g" "$b"
}
if [[ $partial -gt 0 ]]; then
dim_pos=$((pos > 0 ? pos - 1 : 0))
case $partial in
1) bar+="$(heatmap_color_partial $dim_pos 35)░" ;;
2) bar+="$(heatmap_color_partial $dim_pos 55)▒" ;;
3) bar+="$(heatmap_color_partial $dim_pos 80)▓" ;;
esac
fi
# Build track (empty portion) - dim
track=""
for ((i=0; i<empty; i++)); do track+="░"; done
# Left cap color (first segment color or dim)
if [[ $full -gt 0 || $partial -gt 0 ]]; then
left="$(heatmap_color 0)${left_cap}"
else
left="${dim}${left_cap}"
fi
# Right cap - matches last filled segment or dim
dim_cap=$'\033[38;2;40;40;40m'
if [[ $empty -eq 0 && $partial -eq 0 ]]; then
# Full bar: right cap matches last segment (position 9)
output="${left}${bar}$(heatmap_color 9)${right_cap}${reset}"
else
# Partial bar: track dim, cap darker
output="${left}${bar}${dim}${track}${dim_cap}${right_cap}${reset}"
fi
# Percentage colored by last filled position
last_pos=$((full + (partial > 0 ? 1 : 0) - 1))
[[ $last_pos -lt 0 ]] && last_pos=0
pct_color=$(heatmap_color $last_pos)
tokens_k=$(( _ctx_tokens / 1000 ))
line1+=("${output} ${pct_color}${tokens_k}k${reset}")
fi
# Session cost & duration
cost=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
duration_ms=$(echo "$input" | jq -r '.cost.total_duration_ms // 0')
if [[ "$cost" != "0" ]] && [[ "$cost" != "null" ]]; then
cost_str=$(printf '$%.2f' "$cost")
if [[ "$duration_ms" != "0" ]] && [[ "$duration_ms" != "null" ]]; then
duration_sec=$((duration_ms / 1000))
if [[ $duration_sec -ge 60 ]]; then
mins=$((duration_sec / 60))
secs=$((duration_sec % 60))
duration_str="${mins}m${secs}s"
else
duration_str="${duration_sec}s"
fi
line1+=("$(printf '\033[90m%s %s\033[0m' "$cost_str" "$duration_str")")
else
line1+=("$(printf '\033[90m%s\033[0m' "$cost_str")")
fi
fi
# Join a segment array with the separator
sep=" \033[2m│\033[0m "
join_segments() {
local out="" i=0 seg
for seg in "$@"; do
[[ $i -gt 0 ]] && out+="$sep"
out+="$seg"
((i++))
done
printf '%s' "$out"
}
out1="$(join_segments "${line1[@]}")"
out2="$(join_segments "${line2[@]}")"
if [[ -n "$out2" ]]; then
printf "%b\n%b\n" "$out1" "$out2"
else
printf "%b\n" "$out1"
fi