@say8425/cc-statusline 2.0.2 → 2.1.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/README.md +2 -0
- package/dist/index.js +38 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ Add the following to `~/.claude/settings.json`:
|
|
|
48
48
|
- **Context**: Token usage with percentage (color-coded)
|
|
49
49
|
- **Git Diff**: File count, insertions, deletions
|
|
50
50
|
- **PR URL**: Clickable OSC 8 hyperlink
|
|
51
|
+
- **Worktree Support**: Shows real project name when running in a `cc --worktree` session
|
|
51
52
|
- **TrueColor**: Dynamic colors based on thresholds
|
|
52
53
|
- **Limit Reset Time**: Reset time display (HH:MM)
|
|
53
54
|
- **Block Usage**: 5-hour utilization percentage (from server API)
|
|
@@ -59,6 +60,7 @@ Add the following to `~/.claude/settings.json`:
|
|
|
59
60
|
| Emoji | Description |
|
|
60
61
|
| ----- | ------------------------ |
|
|
61
62
|
| 📁 | Project folder name |
|
|
63
|
+
| 🌲 | Worktree name (shown in worktree sessions) |
|
|
62
64
|
| 🌿 | Current Git branch |
|
|
63
65
|
| ⏱️ | Session elapsed time |
|
|
64
66
|
| 💰 | Session cost in USD |
|
package/dist/index.js
CHANGED
|
@@ -19,14 +19,16 @@ var cache = {
|
|
|
19
19
|
value: null,
|
|
20
20
|
timestamp: 0
|
|
21
21
|
},
|
|
22
|
-
accessToken: { value: null, timestamp: 0 }
|
|
22
|
+
accessToken: { value: null, timestamp: 0 },
|
|
23
|
+
mainProjectName: { value: null, timestamp: 0 }
|
|
23
24
|
};
|
|
24
25
|
var CACHE_TTL = {
|
|
25
26
|
branch: 5000,
|
|
26
27
|
gitChanges: 0,
|
|
27
28
|
prUrl: 30000,
|
|
28
29
|
blockUsage: 120000,
|
|
29
|
-
accessToken: 300000
|
|
30
|
+
accessToken: 300000,
|
|
31
|
+
mainProjectName: 300000
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
// src/git/branch.ts
|
|
@@ -80,6 +82,27 @@ async function getPrUrlCached() {
|
|
|
80
82
|
return cache.prUrl.value;
|
|
81
83
|
}
|
|
82
84
|
}
|
|
85
|
+
// src/git/worktree.ts
|
|
86
|
+
var {$: $4 } = globalThis.Bun;
|
|
87
|
+
async function getMainProjectNameCached() {
|
|
88
|
+
if (Date.now() - cache.mainProjectName.timestamp < CACHE_TTL.mainProjectName) {
|
|
89
|
+
return cache.mainProjectName.value;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const result = await $4`git rev-parse --git-common-dir 2>/dev/null`.text();
|
|
93
|
+
const gitCommonDir = result.trim();
|
|
94
|
+
if (gitCommonDir === ".git") {
|
|
95
|
+
cache.mainProjectName = { value: null, timestamp: Date.now() };
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const projectRoot = gitCommonDir.replace(/\/.git$/, "");
|
|
99
|
+
const projectName = projectRoot.split("/").pop() || null;
|
|
100
|
+
cache.mainProjectName = { value: projectName, timestamp: Date.now() };
|
|
101
|
+
return projectName;
|
|
102
|
+
} catch {
|
|
103
|
+
return cache.mainProjectName.value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
83
106
|
// src/colors.ts
|
|
84
107
|
var C = {
|
|
85
108
|
RESET: "\x1B[0m",
|
|
@@ -130,7 +153,12 @@ function renderStatusLine(ctx) {
|
|
|
130
153
|
const totalTokens = usage ? usage.input_tokens + usage.output_tokens + usage.cache_creation_input_tokens + usage.cache_read_input_tokens : 0;
|
|
131
154
|
const contextPct = Math.round(totalTokens / contextSize * 100);
|
|
132
155
|
const ctxColor = getUsageColor(contextPct);
|
|
133
|
-
let line1
|
|
156
|
+
let line1;
|
|
157
|
+
if (ctx.mainProjectName) {
|
|
158
|
+
line1 = `${C.WHITE}\uD83D\uDCC1 ${ctx.mainProjectName}${C.RESET} | ${C.WHITE}\uD83C\uDF32 ${folder}${C.RESET}`;
|
|
159
|
+
} else {
|
|
160
|
+
line1 = `${C.WHITE}\uD83D\uDCC1 ${folder}${C.RESET}`;
|
|
161
|
+
}
|
|
134
162
|
if (ctx.branch) {
|
|
135
163
|
line1 += ` | ${C.WHITE}\uD83C\uDF3F ${ctx.branch}${C.RESET}`;
|
|
136
164
|
}
|
|
@@ -184,12 +212,12 @@ async function readStdin() {
|
|
|
184
212
|
}
|
|
185
213
|
|
|
186
214
|
// src/usage/token.ts
|
|
187
|
-
var {$: $
|
|
215
|
+
var {$: $5 } = globalThis.Bun;
|
|
188
216
|
async function getAccessToken() {
|
|
189
217
|
if (process.platform !== "darwin")
|
|
190
218
|
return null;
|
|
191
219
|
try {
|
|
192
|
-
const result = await $
|
|
220
|
+
const result = await $5`security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null`.text();
|
|
193
221
|
const creds = JSON.parse(result);
|
|
194
222
|
return creds?.claudeAiOauth?.accessToken ?? null;
|
|
195
223
|
} catch {
|
|
@@ -269,11 +297,12 @@ async function main(cliArgs) {
|
|
|
269
297
|
const args = cliArgs ?? process.argv.slice(2);
|
|
270
298
|
const { showUsage } = parseCliArgs(args);
|
|
271
299
|
const claudeJson = JSON.parse(await readStdin() || "{}");
|
|
272
|
-
const [branch, gitChanges, prUrl, blockUsage] = await Promise.all([
|
|
300
|
+
const [branch, gitChanges, prUrl, blockUsage, mainProjectName] = await Promise.all([
|
|
273
301
|
getBranchCached(),
|
|
274
302
|
getGitChangesCached(),
|
|
275
303
|
getPrUrlCached(),
|
|
276
|
-
showUsage ? getUsageCached() : Promise.resolve(null)
|
|
304
|
+
showUsage ? getUsageCached() : Promise.resolve(null),
|
|
305
|
+
getMainProjectNameCached()
|
|
277
306
|
]);
|
|
278
307
|
const lines = renderStatusLine({
|
|
279
308
|
claudeJson,
|
|
@@ -281,7 +310,8 @@ async function main(cliArgs) {
|
|
|
281
310
|
gitChanges,
|
|
282
311
|
prUrl,
|
|
283
312
|
blockUsage,
|
|
284
|
-
showUsage
|
|
313
|
+
showUsage,
|
|
314
|
+
mainProjectName
|
|
285
315
|
});
|
|
286
316
|
for (const line of lines) {
|
|
287
317
|
console.log(line);
|