-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusline.sh
More file actions
executable file
·36 lines (29 loc) · 1.21 KB
/
statusline.sh
File metadata and controls
executable file
·36 lines (29 loc) · 1.21 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
#!/bin/bash
# Claude Code statusline script
# Receives JSON on stdin with session info
# Find jq: prefer system jq, fall back to ~/.local/bin
JQ=$(command -v jq 2>/dev/null || echo "$HOME/.local/bin/jq")
if [ ! -x "$JQ" ]; then
echo "jq not found"
exit 0
fi
DATA=$(cat)
CWD=$(echo "$DATA" | "$JQ" -r '.cwd // ""')
MODEL=$(echo "$DATA" | "$JQ" -r '.model.display_name // ""')
COST=$(echo "$DATA" | "$JQ" -r '.cost.total_cost_usd // 0' | xargs printf "%.3f")
CTX=$(echo "$DATA" | "$JQ" -r '.context_window.used_percentage // 0' | xargs printf "%.0f")
ADDED=$(echo "$DATA" | "$JQ" -r '.cost.total_lines_added // 0')
REMOVED=$(echo "$DATA" | "$JQ" -r '.cost.total_lines_removed // 0')
# Shorten home directory to ~
CWD="${CWD/#$HOME/~}"
# Git branch (from the cwd)
BRANCH=$(git -C "$(echo "$DATA" | "$JQ" -r '.cwd // "."')" rev-parse --abbrev-ref HEAD 2>/dev/null)
# Build the line
LINE=""
[ -n "$MODEL" ] && LINE="${LINE}\033[36m${MODEL}\033[0m"
[ -n "$CWD" ] && LINE="${LINE} \033[33m${CWD}\033[0m"
[ -n "$BRANCH" ] && LINE="${LINE} \033[35m${BRANCH}\033[0m"
LINE="${LINE} \033[32m\$${COST}\033[0m"
LINE="${LINE} \033[32m+${ADDED}\033[0m \033[31m-${REMOVED}\033[0m"
LINE="${LINE} \033[90mctx:${CTX}%\033[0m"
echo -e "$LINE"