diff --git a/claude/.claude/.gitignore b/claude/.claude/.gitignore index fc0b753..6484d7d 100644 --- a/claude/.claude/.gitignore +++ b/claude/.claude/.gitignore @@ -3,3 +3,4 @@ !skills !.gitignore !settings.local.json +!statusline-command.sh diff --git a/claude/.claude/statusline-command.sh b/claude/.claude/statusline-command.sh new file mode 100644 index 0000000..736c1b7 --- /dev/null +++ b/claude/.claude/statusline-command.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# Читаем и парсим JSON одним вызовом jq +IFS=$'\t' read -r cwd display_name ctx_pct rate5h rate7d < <(jq -r '[ + (.workspace.current_dir // ""), + (.model.display_name // ""), + (.context_window.used_percentage // ""), + (.rate_limits.five_hour.used_percentage // ""), + (.rate_limits.seven_day.used_percentage // "") +] | @tsv') + +# Путь: $HOME → ~, длинные пути → .../ +path="$cwd" +home="$HOME" +if [[ "$path" == "$home" ]]; then + path="~" +elif [[ "$path" == "$home"/* ]]; then + path="~${path#$home}" +fi + +# Считаем сегменты (кроме ведущего ~) +IFS='/' read -ra segs <<< "${path#\~}" +segs=("${segs[@]/#/}") # убираем пустые +real_segs=() +for s in "${segs[@]}"; do [[ -n "$s" ]] && real_segs+=("$s"); done + +if (( ${#real_segs[@]} > 2 )); then + last="${real_segs[-1]}" + if [[ "$path" == ~* ]]; then + path="~/.../$last" + else + path=".../$last" + fi +fi + +# Git branch +branch="" +if [[ -n "$cwd" ]]; then + branch=$(git -C "$cwd" rev-parse --abbrev-ref HEAD 2>/dev/null) +fi + +# Модель: убрать префикс "Claude " +model="${display_name#Claude }" + +# ANSI цвета +GREEN='\033[32m' +YELLOW='\033[33m' +PURPLE='\033[35m' +CYAN='\033[36m' +RESET='\033[0m' + +# user@hostname +user_host="${GREEN}${USER}@$(hostname -s)${RESET}" + +# путь +colored_path="${YELLOW}${path}${RESET}" + +# ветка +colored_branch="" +if [[ -n "$branch" ]]; then + colored_branch=" ${PURPLE}(${branch})${RESET}" +fi + +# модель +colored_model="${CYAN}${model}${RESET}" + +# Собираем секции +out="${user_host}:${colored_path}${colored_branch} | ${colored_model}" + +# ctx: только если не пустое и не null +if [[ -n "$ctx_pct" && "$ctx_pct" != "null" ]]; then + out+=" ctx:${ctx_pct}%" +fi + +# rate limits: только если не пустые и не null +rates="" +if [[ -n "$rate5h" && "$rate5h" != "null" ]]; then + rates+=" 5h:${rate5h}%" +fi +if [[ -n "$rate7d" && "$rate7d" != "null" ]]; then + rates+=" 7d:${rate7d}%" +fi +if [[ -n "$rates" ]]; then + out+=" |${rates}" +fi + +printf '%b\n' "$out"