Created
January 10, 2026 09:36
-
-
Save m4rkw/cf4c2ade3d4b22f7b2f7e9e96c915e08 to your computer and use it in GitHub Desktop.
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) | |
| # Extract working directory | |
| workdir=$(echo "$input" | jq -r '.workspace.current_dir') | |
| # Extract context window data | |
| usage=$(echo "$input" | jq '.context_window.current_usage') | |
| context_window_size=$(echo "$input" | jq '.context_window.context_window_size') | |
| # Initialize display variables | |
| bar="" | |
| pct_display="" | |
| tokens_display="" | |
| updown_display="" | |
| if [ "$usage" != "null" ]; then | |
| # Calculate current context tokens (input + cache creation + cache read) | |
| current_tokens=$(echo "$usage" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens') | |
| output_tokens=$(echo "$usage" | jq '.output_tokens') | |
| # Calculate percentage | |
| pct=$((current_tokens * 100 / context_window_size)) | |
| # Create bar visualization (20 characters wide) | |
| bar_width=20 | |
| filled=$((pct * bar_width / 100)) | |
| empty=$((bar_width - filled)) | |
| bar="[" | |
| for ((i=0; i<filled; i++)); do bar+="="; done | |
| for ((i=0; i<empty; i++)); do bar+=" "; done | |
| bar+="]" | |
| # Format token counts with K suffix | |
| if [ $current_tokens -ge 1000 ]; then | |
| current_k=$((current_tokens / 1000)) | |
| tokens_display="${current_k}K" | |
| else | |
| tokens_display="${current_tokens}" | |
| fi | |
| pct_display="${pct}%" | |
| # Tokens up/down (input/output) | |
| if [ $output_tokens -ge 1000 ]; then | |
| output_k=$((output_tokens / 1000)) | |
| updown_display="↑${current_k}K ↓${output_k}K" | |
| else | |
| updown_display="↑${tokens_display} ↓${output_tokens}" | |
| fi | |
| else | |
| bar="[ ]" | |
| pct_display="0%" | |
| tokens_display="0" | |
| updown_display="↑0 ↓0" | |
| fi | |
| # Calculate lines +/- from transcript | |
| transcript_path=$(echo "$input" | jq -r '.transcript_path') | |
| lines_display="+0/-0" | |
| if [ -f "$transcript_path" ]; then | |
| # Count lines added and removed from the transcript | |
| # We'll count tool_use blocks with Edit operations | |
| lines_added=$(grep -o '"new_string"' "$transcript_path" 2>/dev/null | wc -l | tr -d ' ') | |
| lines_removed=$(grep -o '"old_string"' "$transcript_path" 2>/dev/null | wc -l | tr -d ' ') | |
| lines_display="+${lines_added}/-${lines_removed}" | |
| fi | |
| # Output the statusline | |
| printf "%s | %s %s %s | %s | Lines: %s" "$workdir" "$bar" "$tokens_display" "$pct_display" "$updown_display" "$lines_display" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment