Created
September 22, 2026 21:18
-
-
Save themorgantown/6d08f2b69186c601df6cc84c85aa7603 to your computer and use it in GitHub Desktop.
statusline.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| input=$(cat) | |
| model=$(echo "$input" | jq -r '.model.display_name // "Unknown Model"') | |
| used=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| worktree=$(echo "$input" | jq -r '.worktree.name // empty') | |
| total_cost=$(echo "$input" | jq -r '.cost.total_cost_usd // empty') | |
| current_dir=$(echo "$input" | jq -r '.worktree.original_cwd // empty') | |
| rl_5h_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty' | awk '{printf "%.0f", $1}') | |
| rl_5h_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty') | |
| rl_7d_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty' | awk '{printf "%.0f", $1}') | |
| pr_number=$(echo "$input" | jq -r '.pr.number // empty') | |
| if [ -n "$used" ]; then | |
| used_display=$(printf "%.0f" "$used") | |
| usage_str="${used_display}%" | |
| else | |
| usage_str="0%" | |
| fi | |
| if [ -n "$worktree" ]; then | |
| worktree_str="${worktree}" | |
| else | |
| worktree_str="no worktree" | |
| fi | |
| GREEN='\033[32m' | |
| YELLOW='\033[33m' | |
| RED='\033[31m' | |
| RESET='\033[0m' | |
| git_str="" | |
| if git --no-optional-locks rev-parse --git-dir > /dev/null 2>&1; then | |
| branch=$(git --no-optional-locks branch --show-current 2>/dev/null) | |
| [ -z "$branch" ] && branch=$(git --no-optional-locks rev-parse --abbrev-ref HEAD 2>/dev/null) | |
| staged=$(git --no-optional-locks diff --cached --numstat 2>/dev/null | wc -l | tr -d ' ') | |
| modified=$(git --no-optional-locks diff --numstat 2>/dev/null | wc -l | tr -d ' ') | |
| ahead_behind=$(git --no-optional-locks rev-list --left-right --count '@{u}...HEAD' 2>/dev/null) | |
| git_str="$branch" | |
| [ "$staged" -gt 0 ] && git_str="${git_str} $(printf "${GREEN}+${staged}${RESET}")" | |
| [ "$modified" -gt 0 ] && git_str="${git_str} $(printf "${YELLOW}~${modified}${RESET}")" | |
| if [ -n "$ahead_behind" ]; then | |
| behind=$(echo "$ahead_behind" | awk '{print $1}') | |
| ahead=$(echo "$ahead_behind" | awk '{print $2}') | |
| [ "$ahead" -gt 0 ] && git_str="${git_str} $(printf "${YELLOW}↑${ahead}${RESET}")" | |
| [ "$behind" -gt 0 ] && git_str="${git_str} $(printf "${RED}↓${behind}${RESET}")" | |
| fi | |
| else | |
| git_str="no branch" | |
| fi | |
| if [ -n "$total_cost" ]; then | |
| cost_display=$(awk "BEGIN { printf \"%.2f\", $total_cost }") | |
| block_str="\$${cost_display}" | |
| else | |
| block_str="\$0.00" | |
| fi | |
| make_bar() { | |
| pct="$1" | |
| width=10 | |
| filled=$(( pct * width / 100 )) | |
| bar="" | |
| i=0 | |
| while [ $i -lt $filled ]; do bar="${bar}█"; i=$(( i + 1 )); done | |
| while [ $i -lt $width ]; do bar="${bar}░"; i=$(( i + 1 )); done | |
| printf "%s" "$bar" | |
| } | |
| format_rl() { | |
| pct="$1" | |
| reset_ts="$2" | |
| label="$3" | |
| [ -z "$pct" ] && return | |
| if [ "$pct" -ge 90 ]; then color="$RED" | |
| elif [ "$pct" -ge 70 ]; then color="$YELLOW" | |
| else color="$GREEN" | |
| fi | |
| reset_time=$(date -r "$reset_ts" "+%-I:%M%p" 2>/dev/null || date -d "@$reset_ts" "+%-I:%M%p" 2>/dev/null) | |
| bar=$(make_bar "$pct") | |
| printf "${color}${label} ${bar} ${pct}%% resets ${reset_time}${RESET}" | |
| } | |
| format_rl_compact() { | |
| pct="$1" | |
| label="$2" | |
| [ -z "$pct" ] && return | |
| if [ "$pct" -ge 90 ]; then color="$RED" | |
| elif [ "$pct" -ge 70 ]; then color="$YELLOW" | |
| else color="$GREEN" | |
| fi | |
| printf "${color}${label} ${pct}%%${RESET}" | |
| } | |
| rate_limit_str="$(format_rl "$rl_5h_pct" "$rl_5h_reset" "5h")" | |
| rl_7d_str="$(format_rl_compact "$rl_7d_pct" "7d")" | |
| [ -n "$rl_7d_str" ] && rate_limit_str="${rate_limit_str} ${rl_7d_str}" | |
| if [ -n "$pr_number" ]; then | |
| pr_state=$(echo "$input" | jq -r '.pr.review_state // "open"') | |
| pr_kind=$(echo "$input" | jq -r '.pr.kind // empty') | |
| if [ "$pr_kind" = "mr" ]; then pr_label="MR!${pr_number}"; else pr_label="PR#${pr_number}"; fi | |
| pr_str="${pr_label}(${pr_state})" | |
| fi | |
| repo_root=$(cd "$current_dir" 2>/dev/null && git --no-optional-locks rev-parse --show-toplevel 2>/dev/null || echo "$current_dir") | |
| dir_display=$(basename "$repo_root") | |
| cwd_display=$(basename "$current_dir") | |
| line1=$(printf "🤖 %s | 🧠 %s | 💰 %s | ⏱️ %s" "$model" "$usage_str" "$block_str" "$rate_limit_str") | |
| line2=$(printf "📁 %s | 🌳 %s | 🌿 %s | 📂 %s" "$dir_display" "$worktree_str" "$git_str" "$cwd_display") | |
| [ -n "$pr_str" ] && line2="${line2} | ${pr_str}" | |
| printf "%s\n%s" "$line1" "$line2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment