Add current status line script
This commit is contained in:
commit
ac549e8a07
1 changed files with 89 additions and 0 deletions
89
status-line/statusline-command.sh
Executable file
89
status-line/statusline-command.sh
Executable file
|
|
@ -0,0 +1,89 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Claude Code status line
|
||||||
|
# Reads the status line JSON payload from stdin and prints:
|
||||||
|
# 1. Working directory
|
||||||
|
# 2. Model display name
|
||||||
|
# 3. Git branch (omitted if not in a git repo)
|
||||||
|
# 4. Context window usage as a block bar graph + token count in thousands
|
||||||
|
|
||||||
|
input=$(cat)
|
||||||
|
|
||||||
|
# --- Colors (kept dim-friendly for the status line) ---
|
||||||
|
RESET='\033[0m'
|
||||||
|
DIM='\033[2m'
|
||||||
|
CYAN='\033[36m'
|
||||||
|
GREEN='\033[32m'
|
||||||
|
MAGENTA='\033[35m'
|
||||||
|
YELLOW='\033[33m'
|
||||||
|
GREEN='\033[32m'
|
||||||
|
RED='\033[31m'
|
||||||
|
|
||||||
|
# --- Working directory ---
|
||||||
|
cwd=$(printf '%s' "$input" | jq -r '.workspace.current_dir // .cwd // empty')
|
||||||
|
if [ -n "$cwd" ]; then
|
||||||
|
dir_display=$(printf '%s' "$cwd" | sed "s|^$HOME|~|")
|
||||||
|
else
|
||||||
|
dir_display="?"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Model ---
|
||||||
|
model_name=$(printf '%s' "$input" | jq -r '.model.display_name // "unknown"')
|
||||||
|
|
||||||
|
# --- Git branch (omit gracefully if not in a repo) ---
|
||||||
|
git_branch=""
|
||||||
|
if [ -n "$cwd" ] && [ -d "$cwd" ]; then
|
||||||
|
git_branch=$(git --no-optional-locks -C "$cwd" rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Context window usage: block bar graph + token count in thousands ---
|
||||||
|
used_pct=$(printf '%s' "$input" | jq -r '.context_window.used_percentage // empty')
|
||||||
|
total_tokens=$(printf '%s' "$input" | jq -r '.context_window.total_input_tokens // empty')
|
||||||
|
|
||||||
|
context_display=""
|
||||||
|
if [ -n "$used_pct" ]; then
|
||||||
|
filled=$(awk -v p="$used_pct" 'BEGIN {
|
||||||
|
f = int((p / 10) + 0.5);
|
||||||
|
if (f > 10) f = 10;
|
||||||
|
if (f < 0) f = 0;
|
||||||
|
print f;
|
||||||
|
}')
|
||||||
|
empty=$((10 - filled))
|
||||||
|
bar=""
|
||||||
|
for ((i = 0; i < filled; i++)); do bar="${bar}█"; done
|
||||||
|
for ((i = 0; i < empty; i++)); do bar="${bar}░"; done
|
||||||
|
|
||||||
|
bar_color=$(awk -v p="$used_pct" 'BEGIN {
|
||||||
|
if (p > 80) print "RED";
|
||||||
|
else if (p >= 50) print "YELLOW";
|
||||||
|
else print "GREEN";
|
||||||
|
}')
|
||||||
|
case "$bar_color" in
|
||||||
|
RED) BAR_COLOR="$RED" ;;
|
||||||
|
YELLOW) BAR_COLOR="$YELLOW" ;;
|
||||||
|
*) BAR_COLOR="$GREEN" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -n "$total_tokens" ]; then
|
||||||
|
tokens_display=$(awk -v t="$total_tokens" 'BEGIN { printf "%.1fk", t / 1000 }')
|
||||||
|
context_display="${bar} ${tokens_display}"
|
||||||
|
else
|
||||||
|
context_display="${bar}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Assemble status line ---
|
||||||
|
line=$(printf "${CYAN}%s${RESET}" "$dir_display")
|
||||||
|
line="${line} $(printf "${DIM}|${RESET}")"
|
||||||
|
line="${line} $(printf "${GREEN}%s${RESET}" "$model_name")"
|
||||||
|
|
||||||
|
if [ -n "$git_branch" ]; then
|
||||||
|
line="${line} $(printf "${DIM}|${RESET}")"
|
||||||
|
line="${line} $(printf "${MAGENTA}%s${RESET}" "$git_branch")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$context_display" ]; then
|
||||||
|
line="${line} $(printf "${DIM}|${RESET}")"
|
||||||
|
line="${line} $(printf "${BAR_COLOR}%s${RESET}" "$context_display")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%b\n' "$line"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue