- 3줄 레이아웃 (스타일/컨텍스트/비용 | 모델/세션 | 디렉토리/MCP/시계) - 이모지 라벨 + rawValue로 깔끔한 표시 - ctx-bar.sh: 컨텍스트 사용량 progress bar (█░ 스타일) - ctx-debug.sh: 디버그용 raw 데이터 출력
35 lines
1.0 KiB
Bash
Executable File
35 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Context percentage progress bar for ccstatusline custom-command widget
|
|
# Receives Claude Code JSON via stdin
|
|
|
|
input=$(cat)
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
echo "Ctx: ?"
|
|
exit 0
|
|
fi
|
|
|
|
# Extract context window info
|
|
CTX_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size // 200000')
|
|
USAGE=$(echo "$input" | jq '.context_window.current_usage // null')
|
|
|
|
if [ "$USAGE" = "null" ] || [ -z "$USAGE" ]; then
|
|
echo "Ctx: --"
|
|
exit 0
|
|
fi
|
|
|
|
CURRENT=$(echo "$USAGE" | jq '(.input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0)')
|
|
|
|
# Usable = 80% of max (auto-compact threshold)
|
|
USABLE=$(( CTX_SIZE * 80 / 100 ))
|
|
USED_PCT=$(( CURRENT * 100 / USABLE ))
|
|
[ "$USED_PCT" -lt 0 ] && USED_PCT=0
|
|
[ "$USED_PCT" -gt 100 ] && USED_PCT=100
|
|
|
|
# Build progress bar (width=12) - fills up as usage increases
|
|
W=12
|
|
FILLED=$(( USED_PCT * W / 100 ))
|
|
EMPTY=$(( W - FILLED ))
|
|
BAR=$(printf '%*s' "$FILLED" '' | tr ' ' '█')$(printf '%*s' "$EMPTY" '' | tr ' ' '░')
|
|
|
|
printf '%s %s%%' "[$BAR]" "$USED_PCT"
|