Last active
March 26, 2026 15:17
-
-
Save hansamlin/a22ec8d6bc4813985c415698013a054b 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/bash | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| echo "$input" >> /tmp/statusline_debug.log | |
| # Extract values using jq | |
| MODEL=$(echo "$input" | jq -r '.model.display_name') | |
| # Get git branch if in a git repo | |
| GIT_BRANCH="" | |
| if git -c core.worktrees= rev-parse --git-dir > /dev/null 2>&1; then | |
| BRANCH=$(git branch --show-current 2>/dev/null) | |
| if [ -n "$BRANCH" ]; then | |
| GIT_BRANCH="$BRANCH" | |
| else | |
| # Detached HEAD state | |
| GIT_BRANCH=$(git rev-parse --short HEAD 2>/dev/null) | |
| fi | |
| fi | |
| # Get current directory | |
| CURRENT_PATH=$(pwd) | |
| # Build first line: path + git branch | |
| if [ -n "$GIT_BRANCH" ]; then | |
| FIRST_LINE="$CURRENT_PATH ($GIT_BRANCH)" | |
| else | |
| FIRST_LINE="$CURRENT_PATH" | |
| fi | |
| # Build second line: model + 5-hour rate limit as bar | |
| FIVE_HOUR_PCT=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') | |
| if [ -n "$FIVE_HOUR_PCT" ]; then | |
| # Calculate filled blocks (0-10), rounding to nearest integer | |
| FILLED=$(printf "%.0f" "$(echo "$FIVE_HOUR_PCT / 10" | bc -l)") | |
| # Clamp to 0-10 | |
| [ "$FILLED" -lt 0 ] && FILLED=0 | |
| [ "$FILLED" -gt 10 ] && FILLED=10 | |
| EMPTY=$((10 - FILLED)) | |
| # Choose color based on percentage | |
| PCT_INT=$(printf "%.0f" "$FIVE_HOUR_PCT") | |
| if [ "$PCT_INT" -ge 90 ]; then | |
| BAR_COLOR=$'\e[38;2;210;70;30m' | |
| elif [ "$PCT_INT" -ge 80 ]; then | |
| BAR_COLOR=$'\e[38;2;220;144;0m' | |
| else | |
| BAR_COLOR=$'\e[38;2;34;168;89m' | |
| fi | |
| DIM_COLOR=$'\e[38;2;80;80;80m' | |
| RESET=$'\e[0m' | |
| # Build filled and empty bar strings | |
| FILLED_STR="" | |
| i=0 | |
| while [ "$i" -lt "$FILLED" ]; do | |
| FILLED_STR="${FILLED_STR}█" | |
| i=$((i + 1)) | |
| done | |
| EMPTY_STR="" | |
| i=0 | |
| while [ "$i" -lt "$EMPTY" ]; do | |
| EMPTY_STR="${EMPTY_STR}░" | |
| i=$((i + 1)) | |
| done | |
| else | |
| FILLED_STR="" | |
| EMPTY_STR="" | |
| BAR_COLOR="" | |
| DIM_COLOR="" | |
| RESET="" | |
| fi | |
| if [ -n "$FIVE_HOUR_PCT" ]; then | |
| SECOND_LINE="[$MODEL] | 5h: ${BAR_COLOR}${FILLED_STR}${DIM_COLOR}${EMPTY_STR}${RESET} ${BAR_COLOR}${PCT_INT}%${RESET}" | |
| printf "%s\n%s" "$FIRST_LINE" "$SECOND_LINE" | |
| else | |
| printf "%s\n%s" "$FIRST_LINE" "[$MODEL]" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment