Variablen wurden bisher in den printf-Format-String interpoliert.
Pfade mit % konnten dadurch als Format-Direktive interpretiert werden
und den TUI-Renderer von claude-code aus dem Tritt bringen.
Zusätzlich werden Pfade über 25 Zeichen gekürzt, damit die Statusline
auf schmalen Terminals nicht umbricht — die zusätzliche Zeile war
der wahrscheinliche Auslöser des Render-Drifts ("Ausgabe scrollt nach
oben aus dem sichtbaren Bereich").
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
51 lines
1.8 KiB
Bash
51 lines
1.8 KiB
Bash
#!/bin/bash
|
|
set -eo pipefail
|
|
|
|
input=$(cat)
|
|
|
|
IFS=$'\t' read -r current_dir model total_input total_output context_size used_percent cost_usd < <(
|
|
echo "$input" | jq -r '[
|
|
.workspace.current_dir // "",
|
|
.model.display_name // "?",
|
|
(.context_window.total_input_tokens // 0),
|
|
(.context_window.total_output_tokens // 0),
|
|
(.context_window.context_window_size // 200000),
|
|
((.context_window.used_percentage // 0) | floor),
|
|
(.cost.total_cost_usd // 0)
|
|
] | @tsv'
|
|
)
|
|
|
|
total_tokens=$(( (total_input + total_output) / 1000 ))
|
|
context_limit_k=$(( context_size / 1000 ))
|
|
|
|
cost_formatted=$(LC_NUMERIC=C awk -v cost="$cost_usd" 'BEGIN {
|
|
cents = int(cost * 100 + 0.5)
|
|
if (cents < 100) printf "%d¢", cents
|
|
else printf "$%.2f", cost
|
|
}')
|
|
|
|
user=$(whoami)
|
|
host=$(hostname -s)
|
|
|
|
# Lange Pfade kürzen, damit die Statusline nie umbricht (sonst gerät der
|
|
# claude-code-Renderer aus dem Tritt, weil er 1 Zeile am unteren Rand erwartet).
|
|
display_dir=$current_dir
|
|
if [ ${#display_dir} -gt 25 ]; then
|
|
display_dir=".../$(basename "$(dirname "$current_dir")")/$(basename "$current_dir")"
|
|
fi
|
|
|
|
git_branch=""
|
|
if [ -n "$current_dir" ] && git -C "$current_dir" rev-parse --git-dir > /dev/null 2>&1; then
|
|
branch=$(git -C "$current_dir" branch --show-current 2>/dev/null)
|
|
[ -n "$branch" ] && printf -v git_branch ' \033[33m(%s)\033[00m' "$branch"
|
|
fi
|
|
|
|
chroot_prefix=""
|
|
if [ -r /etc/debian_chroot ]; then
|
|
chroot_prefix="($(cat /etc/debian_chroot))"
|
|
fi
|
|
|
|
printf '%s\033[32m%s@%s\033[00m:\033[34m%s\033[00m%s \033[90m|\033[00m \033[36m%s\033[00m \033[90m|\033[00m \033[35m%dK/%dK (%d%%)\033[00m \033[90m|\033[00m \033[33m%s\033[00m' \
|
|
"$chroot_prefix" "$user" "$host" "$display_dir" "$git_branch" \
|
|
"$model" "$total_tokens" "$context_limit_k" "$used_percent" "$cost_formatted"
|