- Replace fixed "5h"/"7d" window labels with hours/days remaining until the rate-limit window resets, derived from rate_limits.*.resets_at. - Wire up the previously-captured-but-unused $thinking variable as a fallback marker when no explicit effort.level is present. - Color-grade all three percentages (context, 5h, 7d): yellow >=80%, red >=90%. Uses \e[39m to restore default fg without losing the surrounding dim attribute. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
2.4 KiB
Bash
Executable file
67 lines
2.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
input=$(cat)
|
|
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd')
|
|
dir=$(basename "$cwd")
|
|
model=$(echo "$input" | jq -r '.model.display_name // ""')
|
|
|
|
# Git branch (skip optional locks)
|
|
branch=$(git -C "$cwd" symbolic-ref --quiet --short HEAD 2>/dev/null)
|
|
|
|
# Context usage
|
|
used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
|
|
|
|
# Rate limits
|
|
rl_5h=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
|
|
rl_5h_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
|
|
rl_7d=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
|
|
rl_7d_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
|
|
|
|
# Whole hours until a unix-epoch timestamp, ceiling-rounded; falls back to label on past/empty
|
|
hours_until() {
|
|
local ts="$1" fallback="$2"
|
|
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
|
|
local diff=$(( ts - $(date +%s) ))
|
|
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
|
|
printf '%dh' "$(( (diff + 3599) / 3600 ))"
|
|
}
|
|
|
|
# Same idea, days
|
|
days_until() {
|
|
local ts="$1" fallback="$2"
|
|
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
|
|
local diff=$(( ts - $(date +%s) ))
|
|
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
|
|
printf '%dd' "$(( (diff + 86399) / 86400 ))"
|
|
}
|
|
|
|
# Render a percentage with optional suffix; yellow >=80, red >=90. \e[39m restores default fg without dropping the surrounding dim.
|
|
pct_color() {
|
|
local val="$1" suffix="$2" int color=''
|
|
int=${val%.*}
|
|
(( int >= 90 )) && color=$'\e[31m'
|
|
(( int >= 80 && int < 90 )) && color=$'\e[33m'
|
|
if [[ -n "$color" ]]; then
|
|
printf '%s%.0f%%%s\e[39m' "$color" "$val" "$suffix"
|
|
else
|
|
printf '%.0f%%%s' "$val" "$suffix"
|
|
fi
|
|
}
|
|
|
|
# Thinking / effort
|
|
thinking=$(echo "$input" | jq -r '.thinking.enabled // empty')
|
|
effort=$(echo "$input" | jq -r '.effort.level // empty')
|
|
|
|
# Build dim suffix
|
|
dim=""
|
|
[[ -n "$branch" ]] && dim="$dim ($branch)"
|
|
[[ -n "$model" ]] && dim="$dim $model"
|
|
[[ -n "$effort" ]] && dim="$dim $effort"
|
|
[[ -z "$effort" && -n "$thinking" ]] && dim="$dim thinking"
|
|
[[ -n "$used" ]] && dim="$dim $(pct_color "$used")"
|
|
|
|
usage=""
|
|
[[ -n "$rl_5h" ]] && usage="$usage $(pct_color "$rl_5h" "/$(hours_until "$rl_5h_reset" 5h)")"
|
|
[[ -n "$rl_7d" ]] && usage="$usage $(pct_color "$rl_7d" "/$(days_until "$rl_7d_reset" 7d)")"
|
|
[[ -n "$usage" ]] && dim="$dim -$usage"
|
|
|
|
printf '\033[1m%s\033[0m\033[2m%s\033[0m\n' "$dir" "$dim"
|