Files
ai-setup/home-configs/claude/statusline-command.sh
vitaly 6b80364344 fix: показывать реальное время до сброса лимита в статусной строке
Вместо захардкоженного "5h" теперь считается оставшееся время
из resets_at timestamp: "4ч40м:25%", "58м:80%" и т.д.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 12:47:00 +03:00

47 lines
1.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
input=$(cat)
cwd=$(echo "$input" | jq -r '.cwd')
model=$(echo "$input" | jq -r '.model.display_name // empty')
five_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
five_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
week_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
week_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
branch=$(git -C "$cwd" --no-optional-locks symbolic-ref --short HEAD 2>/dev/null)
short_cwd="${cwd/#$HOME/\~}"
printf "\033[01;34m%s\033[00m" "$short_cwd"
[ -n "$branch" ] && printf " \033[01;33m[%s]\033[00m" "$branch"
[ -n "$model" ] && printf " \033[00;36m%s\033[00m" "$model"
# Форматирует оставшееся время до сброса лимита
fmt_remaining() {
local reset_ts="$1"
local now
now=$(date +%s)
local diff=$(( reset_ts - now ))
[ "$diff" -le 0 ] && echo "скоро" && return
local h=$(( diff / 3600 ))
local m=$(( (diff % 3600) / 60 ))
if [ "$h" -gt 0 ]; then
echo "${h}ч${m}м"
else
echo "${m}м"
fi
}
if [[ "$model" == *[Dd]eep[Ss]eek* ]]; then
cache_file="$HOME/.cache/ai-setup/deepseek_balance"
if [ -f "$cache_file" ]; then
balance=$(head -1 "$cache_file")
[ -n "$balance" ] && printf " \033[00;35m\$%s\033[00m" "$balance"
fi
elif [ -n "$five_pct" ] && [ -n "$five_reset" ]; then
remaining=$(fmt_remaining "$five_reset")
printf " \033[00;35m%s:$(printf '%.0f' "$five_pct")%%\033[00m" "$remaining"
elif [ -n "$week_pct" ] && [ -n "$week_reset" ]; then
remaining=$(fmt_remaining "$week_reset")
printf " \033[00;35m%s:$(printf '%.0f' "$week_pct")%%\033[00m" "$remaining"
fi