repos
/ taproot main

taproot

mirror

The dotfiles and containers I use to set up a machine for development, one container to write code in and another that runs a local coding model on the desktop's GPU.

alpine-linuxcaddydevelopment-environmentdockerdotfileshomelabinfrastructureneovimserver-configurationtmux

3.3 KB · 87 lines · Bash Raw History
 1#!/bin/bash
 2# Claude Code status line. Requires bash, jq, git and date.
 3#
 4#   usg ▓▓▓▓▓░░░░░ 52% · resets 2h 14m | ctx ▓▓░░░░░░░░ 18% | ~/code/finance  main | 3:45 PM ET
 5#
 6# Reads the status-line JSON on stdin. Every optional field uses `// empty`, so
 7# missing data degrades instead of erroring: context_window only appears once a
 8# turn has run, and rate_limits is Pro/Max only, after the first API response.
 9
10input=$(cat)
11
12cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // empty')
13[ -z "$cwd" ] && cwd="$PWD"
14
15YELLOW=$'\033[93m'
16GREEN=$'\033[92m'
17BLUE=$'\033[96m'
18RED=$'\033[91m'
19DIM=$'\033[90m'
20RESET=$'\033[0m'
21
22make_bar() {  # <int-pct> -> a 10-cell ▓/░ bar, one filled cell per 10%
23    local p="$1" filled empty i out=""
24    [ "$p" -lt 0 ] && p=0
25    filled=$(( p / 10 )); [ "$filled" -gt 10 ] && filled=10
26    empty=$(( 10 - filled ))
27    i=0; while [ $i -lt $filled ]; do out="${out}▓"; i=$(( i + 1 )); done
28    i=0; while [ $i -lt $empty ]; do out="${out}░"; i=$(( i + 1 )); done
29    printf '%s' "$out"
30}
31sev_color() {  # <int-pct> -> green under 50%, yellow under 80%, red above
32    local p="$1"
33    if   [ "$p" -ge 80 ]; then printf '%s' "$RED"
34    elif [ "$p" -ge 50 ]; then printf '%s' "$YELLOW"
35    else printf '%s' "$GREEN"; fi
36}
37
38used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
39if [ -n "$used_pct" ]; then
40    pct_int=$(printf "%.0f" "$used_pct")
41    context_part="${DIM}ctx${RESET} ${YELLOW}$(make_bar "$pct_int") ${pct_int}%${RESET}"
42else
43    context_part="${DIM}ctx${RESET} ${YELLOW}░░░░░░░░░░ 0%${RESET}"
44fi
45
46display_dir=$(echo "$cwd" | sed "s|^$HOME|~|")
47
48# -c core.fsmonitor= skips the optional fsmonitor lock, so the status line
49# never contends with a git operation already running in that repo.
50branch_part=""
51if git -C "$cwd" -c core.fsmonitor= rev-parse --git-dir >/dev/null 2>&1; then
52    branch=$(git -C "$cwd" -c core.fsmonitor= symbolic-ref --short HEAD 2>/dev/null \
53             || git -C "$cwd" -c core.fsmonitor= rev-parse --short HEAD 2>/dev/null)
54    if [ -n "$branch" ]; then
55        branch_icon='⎇'  # U+2387, which renders without a Nerd Font
56        branch_part=" ${BLUE}${branch_icon} ${branch}${RESET}"
57    fi
58fi
59
60# The 5-hour rate-limit usage, the same number /usage reports.
61quota_part=""
62h5=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
63if [ -n "$h5" ]; then
64    h5_int=$(printf '%.0f' "$h5")
65    qc=$(sev_color "$h5_int")
66    quota_part="${DIM}usg${RESET} ${qc}$(make_bar "$h5_int") ${h5_int}%${RESET}"
67    # resets_at is Unix epoch seconds.
68    reset_at=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
69    if [ -n "$reset_at" ]; then
70        left=$(( reset_at - $(date +%s) ))
71        [ "$left" -lt 0 ] && left=0
72        h=$(( left / 3600 )); m=$(( (left % 3600) / 60 ))
73        if [ "$h" -gt 0 ]; then eta="${h}h ${m}m"; else eta="${m}m"; fi
74        quota_part="${quota_part} ${DIM}· resets ${eta}${RESET}"
75    fi
76fi
77
78# Forced to Eastern whatever the system clock is, and America/New_York tracks
79# EST and EDT on its own.
80clock=$(TZ="America/New_York" date '+%-I:%M %p')
81
82dir_part="${GREEN}${display_dir}${RESET}${branch_part}"
83SEP=" ${DIM}|${RESET} "
84line="${context_part}${SEP}${dir_part}${SEP}${clock} ET"
85[ -n "$quota_part" ] && line="${quota_part}${SEP}${line}"
86echo "$line"