Files
claude-workflow/dotfiles/statusline-command.sh
T
martinandClaude Sonnet 4.6 5fb36d032a statusline-command.sh: Effizienz und Korrektheit verbessern
- Alle 7 jq-Aufrufe zu einem einzigen zusammengefasst (Process Substitution + read)
- Zwei separate awk-Aufrufe zur Kostenformatierung auf einen reduziert
- Fehlerhafte if-Bedingung für git-Branch korrigiert (falsche Operator-Präzedenz)
- Unnötige Kommentare für offensichtlichen Code entfernt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 11:23:34 +02:00

44 lines
1.4 KiB
Bash

#!/bin/bash
input=$(cat)
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 "BEGIN {
cents = int($cost_usd * 100 + 0.5)
if (cents < 100) printf \"%d¢\", cents
else printf \"\$%.2f\", $cost_usd
}")
user=$(whoami)
host=$(hostname -s)
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" ] && git_branch=" \033[33m($branch)\033[00m"
fi
chroot_prefix=""
if [ -r /etc/debian_chroot ]; then
chroot_prefix="($(cat /etc/debian_chroot))"
fi
printf "${chroot_prefix}\033[32m${user}@${host}\033[00m:\033[34m${current_dir}\033[00m${git_branch}"
printf " \033[90m|\033[00m \033[36m${model}\033[00m"
printf " \033[90m|\033[00m \033[35m${total_tokens}K/${context_limit_k}K (${used_percent}%%)\033[00m"
printf " \033[90m|\033[00m \033[33m${cost_formatted}\033[00m"