Skip to content

Commit 8d5700d

Browse files
committed
improve statusline to contain context bar
1 parent 3a3bb93 commit 8d5700d

File tree

1 file changed

+83
-6
lines changed

1 file changed

+83
-6
lines changed

scripts/statusline.sh

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,63 @@ get_fast_color() {
261261

262262
FAST_COLOR=$(get_fast_color "$FAST_MODE")
263263

264+
# Build context usage progress bar
265+
# Format: [###60%###| 40% ]
266+
# Color: remaining >70% green, 30-70% yellow, <30% red
267+
build_context_bar() {
268+
local used_pct=${1:-0}
269+
local remaining_pct=$((100 - used_pct))
270+
local bar_width=20
271+
272+
# Color for remaining portion based on remaining percentage
273+
local remain_color
274+
if [[ $remaining_pct -gt 70 ]]; then
275+
remain_color="\e[32m" # Green
276+
elif [[ $remaining_pct -ge 30 ]]; then
277+
remain_color="\e[33m" # Yellow
278+
else
279+
remain_color="\e[31m" # Red
280+
fi
281+
282+
# Used portion: white background + black foreground
283+
local used_style="\e[47;30m"
284+
local reset="\e[0m"
285+
286+
local used_width=$(( (used_pct * bar_width + 50) / 100 ))
287+
local remain_width=$(( bar_width - used_width ))
288+
289+
# Build used portion: spaces with white bg, percentage label centered
290+
local used_label="${used_pct}%"
291+
local used_str=""
292+
local i
293+
for (( i = 0; i < used_width; i++ )); do
294+
used_str+=" "
295+
done
296+
if [[ $used_width -ge ${#used_label} ]]; then
297+
local offset=$(( (used_width - ${#used_label}) / 2 ))
298+
used_str="${used_str:0:offset}${used_label}${used_str:offset+${#used_label}}"
299+
fi
300+
301+
# Build remaining portion: spaces, percentage label centered
302+
local remain_label="${remaining_pct}%"
303+
local remain_str=""
304+
for (( i = 0; i < remain_width; i++ )); do
305+
remain_str+=" "
306+
done
307+
if [[ $remain_width -ge ${#remain_label} ]]; then
308+
local offset=$(( (remain_width - ${#remain_label}) / 2 ))
309+
remain_str="${remain_str:0:offset}${remain_label}${remain_str:offset+${#remain_label}}"
310+
fi
311+
312+
printf "[%b%s%b|%b%s%b]" "$used_style" "$used_str" "$reset" "$remain_color" "$remain_str" "$reset"
313+
}
314+
315+
CONTEXT_USED=$(get_value '.context_window.used_percentage')
316+
CONTEXT_USED=${CONTEXT_USED:-0}
317+
# Round to integer
318+
CONTEXT_USED=$(printf "%.0f" "$CONTEXT_USED")
319+
CONTEXT_BAR=$(build_context_bar "$CONTEXT_USED")
320+
264321
# Define colors
265322
CORAL="\e[38;5;173m" # Claude branding - for MODEL
266323
CYAN="\e[36m" # Info - for CWD
@@ -271,15 +328,35 @@ BLUE="\e[34m" # Label - for Session
271328
MAGENTA="\e[35m" # Label - for RLCR and Fast
272329
RESET="\e[0m"
273330

274-
# Output with colors
275-
printf "%b%s%b [%b%s%b] %b%s%b | %b\$%s%b @ %s | lines: %b+%s%b, %b-%s%b | %bSession:%b %b%s%b | %bFast:%b %b%s%b | %bRLCR:%b %b%s%b\n" \
331+
# Auto-rename tmux window to session customTitle if inside tmux
332+
if [[ -n "$TMUX" && -n "$SESSION_DISPLAY" ]]; then
333+
# UUID pattern: 8-4-4-4-12 hex chars
334+
if [[ ! "$SESSION_DISPLAY" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]]; then
335+
tmux rename-window "$SESSION_DISPLAY" 2>/dev/null
336+
fi
337+
fi
338+
339+
# Shorten CWD: replace $HOME with ~
340+
CWD_SHORT="${CWD/#$HOME/\~}"
341+
342+
# Line 1: model | cost @ duration
343+
printf "%b%s%b | %b\$%s%b @ %s\n" \
276344
"$CORAL" "${MODEL:-?}" "$RESET" \
277-
"$CYAN" "${CWD:-?}" "$RESET" \
278-
"$YELLOW" "$BRANCH" "$RESET" \
279345
"$GREEN" "$COST_STR" "$RESET" \
280-
"$DURATION_STR" \
346+
"$DURATION_STR"
347+
348+
# Line 2: context bar
349+
printf "%b\n" "$CONTEXT_BAR"
350+
351+
# Line 3: cwd [branch] | lines
352+
printf "%b%s%b [%b%s%b] | lines: %b+%s%b, %b-%s%b\n" \
353+
"$CYAN" "${CWD_SHORT:-?}" "$RESET" \
354+
"$YELLOW" "$BRANCH" "$RESET" \
281355
"$GREEN" "$LINES_ADDED" "$RESET" \
282-
"$RED" "$LINES_REMOVED" "$RESET" \
356+
"$RED" "$LINES_REMOVED" "$RESET"
357+
358+
# Line 3: session | fast | rlcr
359+
printf "%bSession:%b %b%s%b | %bFast:%b %b%s%b | %bRLCR:%b %b%s%b\n" \
283360
"$BLUE" "$RESET" \
284361
"$CYAN" "${SESSION_DISPLAY:-?}" "$RESET" \
285362
"$MAGENTA" "$RESET" \

0 commit comments

Comments
 (0)