|
#!/bin/sh |
|
input=$(cat) |
|
model=$(echo "$input" | jq -r '.model.display_name // "Claude"') |
|
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""') |
|
used=$(echo "$input" | jq -r '.context_window.used_percentage // empty') |
|
cost_usd=$(echo "$input" | jq -r '.cost.total_cost_usd // empty') |
|
lines_added=$(echo "$input" | jq -r '.cost.total_lines_added // empty') |
|
lines_removed=$(echo "$input" | jq -r '.cost.total_lines_removed // empty') |
|
five_hour=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') |
|
five_hour_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty') |
|
seven_day=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') |
|
seven_day_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty') |
|
|
|
now=$(date +%s) |
|
|
|
# Format seconds as "2d4h" / "3h12m" / "45m" / "30s" |
|
fmt_duration() { |
|
secs=$1 |
|
if [ "$secs" -le 0 ]; then |
|
echo "now" |
|
return |
|
fi |
|
days=$(( secs / 86400 )) |
|
hours=$(( (secs % 86400) / 3600 )) |
|
mins=$(( (secs % 3600) / 60 )) |
|
if [ "$days" -gt 0 ]; then |
|
echo "${days}d${hours}h" |
|
elif [ "$hours" -gt 0 ]; then |
|
echo "${hours}h${mins}m" |
|
elif [ "$mins" -gt 0 ]; then |
|
echo "${mins}m" |
|
else |
|
echo "${secs}s" |
|
fi |
|
} |
|
|
|
# Git branch |
|
branch="" |
|
if [ -n "$cwd" ]; then |
|
branch=$(git -C "$cwd" --no-optional-locks symbolic-ref --short HEAD 2>/dev/null) |
|
fi |
|
|
|
# Context progress bar |
|
if [ -n "$used" ]; then |
|
used_int=$(printf '%.0f' "$used") |
|
filled=$(( used_int * 10 / 100 )) |
|
empty=$(( 10 - filled )) |
|
bar="" |
|
i=0 |
|
while [ $i -lt $filled ]; do |
|
bar="${bar}█" |
|
i=$(( i + 1 )) |
|
done |
|
i=0 |
|
while [ $i -lt $empty ]; do |
|
bar="${bar}░" |
|
i=$(( i + 1 )) |
|
done |
|
ctx_part="[${bar}] ${used_int}%" |
|
else |
|
ctx_part="[░░░░░░░░░░] -" |
|
fi |
|
|
|
# Line 1: model + branch + context |
|
if [ -n "$branch" ]; then |
|
line1="${model} | ${branch} ${ctx_part}" |
|
else |
|
line1="${model} | ${ctx_part}" |
|
fi |
|
|
|
# Line 2: cost + lines changed |
|
line2="" |
|
if [ -n "$cost_usd" ]; then |
|
line2=$(printf '$%.2f' "$cost_usd") |
|
fi |
|
if [ -n "$lines_added" ] || [ -n "$lines_removed" ]; then |
|
added=${lines_added:-0} |
|
removed=${lines_removed:-0} |
|
diff_part="+${added}/-${removed}" |
|
if [ -n "$line2" ]; then |
|
line2="${line2} ${diff_part}" |
|
else |
|
line2="${diff_part}" |
|
fi |
|
fi |
|
|
|
# Line 3: rate limits with time-until-reset |
|
line3="" |
|
if [ -n "$five_hour" ]; then |
|
five_int=$(printf '%.0f' "$five_hour") |
|
part="5h: ${five_int}%" |
|
if [ -n "$five_hour_reset" ]; then |
|
remaining=$(( five_hour_reset - now )) |
|
part="${part} ($(fmt_duration $remaining))" |
|
fi |
|
line3="$part" |
|
fi |
|
if [ -n "$seven_day" ]; then |
|
week_int=$(printf '%.0f' "$seven_day") |
|
part="7d: ${week_int}%" |
|
if [ -n "$seven_day_reset" ]; then |
|
remaining=$(( seven_day_reset - now )) |
|
part="${part} ($(fmt_duration $remaining))" |
|
fi |
|
if [ -n "$line3" ]; then |
|
line3="${line3} | ${part}" |
|
else |
|
line3="$part" |
|
fi |
|
fi |
|
|
|
# Assemble output, skipping empty lines |
|
out="$line1" |
|
[ -n "$line2" ] && out="${out} |
|
${line2}" |
|
[ -n "$line3" ] && out="${out} |
|
${line3}" |
|
|
|
printf "%s" "$out" |