skill-statusline 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +929 -929
- package/bin/cli.js.bak +837 -0
- package/bin/statusline.sh +139 -121
- package/lib/core.sh +408 -382
- package/lib/helpers.sh +119 -81
- package/package.json +52 -52
package/lib/helpers.sh
CHANGED
|
@@ -1,81 +1,119 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# skill-statusline v2 — Shared helpers
|
|
3
|
-
|
|
4
|
-
# Convert any path to forward slashes (safe on all OS)
|
|
5
|
-
to_fwd() {
|
|
6
|
-
echo "$1" | tr '\\' '/' | sed 's|//\+|/|g'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
# Right-pad a colored string to a visible width
|
|
10
|
-
rpad() {
|
|
11
|
-
local str="$1" w="$2"
|
|
12
|
-
local plain
|
|
13
|
-
plain=$(printf '%b' "$str" | sed $'s/\033\\[[0-9;]*m//g')
|
|
14
|
-
local vlen=${#plain}
|
|
15
|
-
local need=$(( w - vlen ))
|
|
16
|
-
printf '%b' "$str"
|
|
17
|
-
[ "$need" -gt 0 ] && printf "%${need}s" ""
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
# Format token count with k/M suffixes
|
|
21
|
-
fmt_tok() {
|
|
22
|
-
awk -v t="$1" 'BEGIN {
|
|
23
|
-
if (t >= 1000000) printf "%.1fM", t/1000000
|
|
24
|
-
else if (t >= 1000) printf "%.0fk", t/1000
|
|
25
|
-
else printf "%d", t
|
|
26
|
-
}'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
# Format duration from milliseconds to human-readable
|
|
30
|
-
fmt_duration() {
|
|
31
|
-
awk -v ms="$1" 'BEGIN {
|
|
32
|
-
s = int(ms / 1000)
|
|
33
|
-
if (s < 60) printf "%ds", s
|
|
34
|
-
else if (s < 3600) printf "%dm%ds", int(s/60), s%60
|
|
35
|
-
else printf "%dh%dm", int(s/3600), int((s%3600)/60)
|
|
36
|
-
}'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
# ──
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# skill-statusline v2 — Shared helpers
|
|
3
|
+
|
|
4
|
+
# Convert any path to forward slashes (safe on all OS)
|
|
5
|
+
to_fwd() {
|
|
6
|
+
echo "$1" | tr '\\' '/' | sed 's|//\+|/|g'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
# Right-pad a colored string to a visible width
|
|
10
|
+
rpad() {
|
|
11
|
+
local str="$1" w="$2"
|
|
12
|
+
local plain
|
|
13
|
+
plain=$(printf '%b' "$str" | sed $'s/\033\\[[0-9;]*m//g')
|
|
14
|
+
local vlen=${#plain}
|
|
15
|
+
local need=$(( w - vlen ))
|
|
16
|
+
printf '%b' "$str"
|
|
17
|
+
[ "$need" -gt 0 ] && printf "%${need}s" ""
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
# Format token count with k/M suffixes
|
|
21
|
+
fmt_tok() {
|
|
22
|
+
awk -v t="$1" 'BEGIN {
|
|
23
|
+
if (t >= 1000000) printf "%.1fM", t/1000000
|
|
24
|
+
else if (t >= 1000) printf "%.0fk", t/1000
|
|
25
|
+
else printf "%d", t
|
|
26
|
+
}'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# Format duration from milliseconds to human-readable
|
|
30
|
+
fmt_duration() {
|
|
31
|
+
awk -v ms="$1" 'BEGIN {
|
|
32
|
+
s = int(ms / 1000)
|
|
33
|
+
if (s < 60) printf "%ds", s
|
|
34
|
+
else if (s < 3600) printf "%dm%ds", int(s/60), s%60
|
|
35
|
+
else printf "%dh%dm", int(s/3600), int((s%3600)/60)
|
|
36
|
+
}'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# ── Run a command with a timeout (seconds) ──
|
|
40
|
+
# Usage: run_with_timeout <seconds> <command...>
|
|
41
|
+
# Returns empty string if timeout exceeded
|
|
42
|
+
run_with_timeout() {
|
|
43
|
+
local secs="$1"; shift
|
|
44
|
+
if command -v timeout >/dev/null 2>&1; then
|
|
45
|
+
timeout "$secs" "$@" 2>/dev/null
|
|
46
|
+
else
|
|
47
|
+
# Fallback: background + wait (POSIX-ish)
|
|
48
|
+
"$@" 2>/dev/null &
|
|
49
|
+
local pid=$!
|
|
50
|
+
local i=0
|
|
51
|
+
while [ $i -lt $(( secs * 10 )) ]; do
|
|
52
|
+
if ! kill -0 "$pid" 2>/dev/null; then
|
|
53
|
+
wait "$pid" 2>/dev/null
|
|
54
|
+
return $?
|
|
55
|
+
fi
|
|
56
|
+
sleep 0.1
|
|
57
|
+
i=$((i + 1))
|
|
58
|
+
done
|
|
59
|
+
kill "$pid" 2>/dev/null
|
|
60
|
+
wait "$pid" 2>/dev/null
|
|
61
|
+
return 124
|
|
62
|
+
fi
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# ── Filesystem caching with TTL ──
|
|
66
|
+
|
|
67
|
+
CACHE_DIR="/tmp/sl-cache-${USER:-unknown}"
|
|
68
|
+
CACHE_TTL="${SL_CACHE_TTL:-5}"
|
|
69
|
+
|
|
70
|
+
# Detect stat flavor once (not on every cache check)
|
|
71
|
+
_SL_STAT_GNU=""
|
|
72
|
+
_sl_cache_init() {
|
|
73
|
+
[ -d "$CACHE_DIR" ] || mkdir -p "$CACHE_DIR" 2>/dev/null
|
|
74
|
+
# Detect stat syntax once and cache the result
|
|
75
|
+
if stat -c %Y "$CACHE_DIR" >/dev/null 2>&1; then
|
|
76
|
+
_SL_STAT_GNU="yes"
|
|
77
|
+
else
|
|
78
|
+
_SL_STAT_GNU="no"
|
|
79
|
+
fi
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# Get file mtime using cached stat detection
|
|
83
|
+
_sl_file_mtime() {
|
|
84
|
+
if [ "$_SL_STAT_GNU" = "yes" ]; then
|
|
85
|
+
stat -c %Y "$1" 2>/dev/null
|
|
86
|
+
else
|
|
87
|
+
stat -f %m "$1" 2>/dev/null
|
|
88
|
+
fi
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# cache_get "key" "command" [ttl_seconds]
|
|
92
|
+
# Returns cached result if fresh, otherwise runs command and caches
|
|
93
|
+
cache_get() {
|
|
94
|
+
local key="$1" cmd="$2" ttl="${3:-$CACHE_TTL}"
|
|
95
|
+
local f="${CACHE_DIR}/${key}"
|
|
96
|
+
|
|
97
|
+
if [ -f "$f" ]; then
|
|
98
|
+
local now mtime age
|
|
99
|
+
now=$(date +%s)
|
|
100
|
+
mtime=$(_sl_file_mtime "$f")
|
|
101
|
+
if [ -n "$mtime" ]; then
|
|
102
|
+
age=$(( now - mtime ))
|
|
103
|
+
if [ "$age" -lt "$ttl" ]; then
|
|
104
|
+
cat "$f"
|
|
105
|
+
return 0
|
|
106
|
+
fi
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
local result
|
|
111
|
+
result=$(eval "$cmd" 2>/dev/null)
|
|
112
|
+
printf '%s' "$result" > "$f" 2>/dev/null
|
|
113
|
+
printf '%s' "$result"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Clear all cached data
|
|
117
|
+
cache_clear() {
|
|
118
|
+
[ -d "$CACHE_DIR" ] && rm -f "${CACHE_DIR}"/* 2>/dev/null
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "skill-statusline",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Rich, themeable statusline for Claude Code — accurate context tracking, 5 themes, 3 layouts, token/cost/GitHub/skill display. Pure bash, zero deps.",
|
|
5
|
-
"bin": {
|
|
6
|
-
"skill-statusline": "bin/cli.js",
|
|
7
|
-
"ccsl": "bin/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"bin/",
|
|
11
|
-
"lib/",
|
|
12
|
-
"themes/",
|
|
13
|
-
"layouts/",
|
|
14
|
-
"commands/",
|
|
15
|
-
"README.md",
|
|
16
|
-
"LICENSE"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"test": "bash test/run-all.sh"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [
|
|
22
|
-
"claude-code",
|
|
23
|
-
"statusline",
|
|
24
|
-
"status-bar",
|
|
25
|
-
"cli",
|
|
26
|
-
"claude",
|
|
27
|
-
"anthropic",
|
|
28
|
-
"ai-coding",
|
|
29
|
-
"developer-tools",
|
|
30
|
-
"terminal",
|
|
31
|
-
"prompt",
|
|
32
|
-
"themes",
|
|
33
|
-
"context-window",
|
|
34
|
-
"token-tracking"
|
|
35
|
-
],
|
|
36
|
-
"author": {
|
|
37
|
-
"name": "Anit Chaudhary",
|
|
38
|
-
"url": "https://github.com/AnitChaudhry"
|
|
39
|
-
},
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/AnitChaudhry/skill-statusline.git"
|
|
44
|
-
},
|
|
45
|
-
"homepage": "https://skills.thinqmesh.com",
|
|
46
|
-
"bugs": {
|
|
47
|
-
"url": "https://github.com/AnitChaudhry/skill-statusline/issues"
|
|
48
|
-
},
|
|
49
|
-
"engines": {
|
|
50
|
-
"node": ">=16"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "skill-statusline",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "Rich, themeable statusline for Claude Code — accurate context tracking, 5 themes, 3 layouts, token/cost/GitHub/skill display. Pure bash, zero deps.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"skill-statusline": "bin/cli.js",
|
|
7
|
+
"ccsl": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"lib/",
|
|
12
|
+
"themes/",
|
|
13
|
+
"layouts/",
|
|
14
|
+
"commands/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "bash test/run-all.sh"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"claude-code",
|
|
23
|
+
"statusline",
|
|
24
|
+
"status-bar",
|
|
25
|
+
"cli",
|
|
26
|
+
"claude",
|
|
27
|
+
"anthropic",
|
|
28
|
+
"ai-coding",
|
|
29
|
+
"developer-tools",
|
|
30
|
+
"terminal",
|
|
31
|
+
"prompt",
|
|
32
|
+
"themes",
|
|
33
|
+
"context-window",
|
|
34
|
+
"token-tracking"
|
|
35
|
+
],
|
|
36
|
+
"author": {
|
|
37
|
+
"name": "Anit Chaudhary",
|
|
38
|
+
"url": "https://github.com/AnitChaudhry"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/AnitChaudhry/skill-statusline.git"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://skills.thinqmesh.com",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/AnitChaudhry/skill-statusline/issues"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=16"
|
|
51
|
+
}
|
|
52
|
+
}
|