summaryrefslogtreecommitdiff
path: root/ar/.config/claude
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-01-18 01:23:22 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-01-18 01:23:22 +0900
commit752de21c8d40f934b1b582f2eeda83de15d44e18 (patch)
tree13515847b650031aef0475e34ef204d79d1d71b5 /ar/.config/claude
parent49dd31237bbf12d6cbbf83b7a9e781b6b2d9e722 (diff)
modified statuslines/statusline.sh
Diffstat (limited to 'ar/.config/claude')
-rwxr-xr-xar/.config/claude/statuslines/statusline.sh46
1 files changed, 41 insertions, 5 deletions
diff --git a/ar/.config/claude/statuslines/statusline.sh b/ar/.config/claude/statuslines/statusline.sh
index 609c412..0b28a2b 100755
--- a/ar/.config/claude/statuslines/statusline.sh
+++ b/ar/.config/claude/statuslines/statusline.sh
@@ -2,10 +2,10 @@
set -euo pipefail 2>/dev/null || set -eu
# ============================================================
-# STATUSLINE v2.1.0 - Claude Code Status Line
+# STATUSLINE v2.2.0 - Claude Code Status Line
# ============================================================
-readonly STATUSLINE_VERSION="2.1.0"
+readonly STATUSLINE_VERSION="2.2.0"
# ============================================================
# CONFIGURATION
@@ -189,12 +189,14 @@ detect_language_info() {
}
# ============================================================
-# CCUSAGE DATA FETCHING
+# CCUSAGE DATA FETCHING (with caching)
# ============================================================
-get_ccusage_data() {
- local session_id="$1"
+readonly CCUSAGE_CACHE_FILE="${SCRIPT_DIR}/.ccusage_cache"
+readonly CCUSAGE_CACHE_TTL=60 # seconds
+# Fetch fresh ccusage data (internal)
+_fetch_ccusage_data() {
# Check if npx is available
command -v npx >/dev/null 2>&1 || return 1
@@ -221,6 +223,40 @@ get_ccusage_data() {
echo "${daily_cost:-0}|${remaining_minutes:-0}|${projected_cost:-0}|${block_cost:-0}|${burn_rate:-0}"
}
+# Get ccusage data with caching
+get_ccusage_data() {
+ local session_id="$1"
+ local now
+ now=$(date +%s)
+
+ # Check if cache exists and is valid
+ if [[ -f "$CCUSAGE_CACHE_FILE" ]]; then
+ local cache_line
+ cache_line=$(head -1 "$CCUSAGE_CACHE_FILE" 2>/dev/null)
+ local cache_time="${cache_line%%|*}"
+ local cache_data="${cache_line#*|}"
+
+ if [[ -n "$cache_time" && "$cache_time" =~ ^[0-9]+$ ]]; then
+ local age=$((now - cache_time))
+ if [[ "$age" -lt "$CCUSAGE_CACHE_TTL" ]]; then
+ log_debug "Using cached ccusage data (age: ${age}s)"
+ echo "$cache_data"
+ return 0
+ fi
+ fi
+ fi
+
+ # Cache miss or expired - fetch fresh data
+ log_debug "Fetching fresh ccusage data"
+ local fresh_data
+ fresh_data=$(_fetch_ccusage_data) || return 1
+
+ # Save to cache
+ echo "${now}|${fresh_data}" > "$CCUSAGE_CACHE_FILE" 2>/dev/null
+
+ echo "$fresh_data"
+}
+
# ============================================================
# JSON PARSING
# ============================================================