@kaynooo/cli-git 0.13.0 → 0.14.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 +15 -4
- package/dist/gb.js +183 -59
- package/dist/gc.js +159 -39
- package/dist/gp.js +1369 -0
- package/dist/gst.js +271 -63
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
# gst, gc and
|
|
1
|
+
# gst, gc, gb and gp
|
|
2
2
|
|
|
3
3
|
Git for Claude Code, where a session would otherwise chain `git status --short` and `git log --oneline` to read the state, or `git add <paths> && git status && git commit -m ...` to commit and have the commit bounced over its message.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
bun install -g @kaynooo/cli-git
|
|
7
|
-
gst
|
|
7
|
+
gst -n 3
|
|
8
8
|
gc 'fix(band): keep it visible' -m 'The band stays above a long prompt.' --ticket '#5 - deliver every pointer' -- src/band.ts tests/band.test.ts
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## gst
|
|
12
12
|
|
|
13
|
-
Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `--log
|
|
13
|
+
Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `-n N` (`--limit`, and the former `--log` and `-l`) adds the last N commits as `<sha7> <title>`. `--json` prints the same as `{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}`, a change as `{status, path, from?}`. It takes no index lock, so it runs beside another git command. Exit codes: 0, 2 outside a repository or a usage error.
|
|
14
|
+
|
|
15
|
+
`gst --repos [dir]...` (`-r`) lists every repository at and below the current one's toplevel, or below each dir given (the current directory outside a repository): a folder holding `.git` is one, four levels down, `node_modules`, `vendor`, `dist` and hidden folders never walked into, symlinks never followed. One line each: its path from the current directory, branch, how it stands against its upstream as of the last fetch (`2 ahead, 1 behind`, `up to date`, `no upstream`, `upstream gone`) and the files left to commit (`3 changed, 1 untracked` or `clean`). `--json` prints an array of the objects above, each with its `path` and no `commits`, a repository git cannot read being `{path, error}`.
|
|
16
|
+
|
|
17
|
+
## gp
|
|
18
|
+
|
|
19
|
+
`gp [dir]...` pushes the current branch of the repository, or of each dir's, when it is ahead of its upstream as of the last fetch, and with `-u` to origin (the only remote when there is no origin) when it has no upstream yet. `--repos` (`-r`) pushes every repository `gst --repos` lists, one after another.
|
|
20
|
+
|
|
21
|
+
- A detached HEAD, a branch with nothing ahead and a repository with no remote are skipped, saying so; a refused push shows git's reason and the next repository is still pushed.
|
|
22
|
+
- What follows `--` goes to each `git push` (`gp -- --tags`, `gp -- --force-with-lease`), and a branch with nothing ahead is then pushed too.
|
|
23
|
+
- `--dry-run` says what would be pushed; `--json` prints `{path, branch, remote, commits, outcome, reason?}` per repository, `outcome` being `pushed`, `would-push`, `skipped` or `refused`.
|
|
24
|
+
- Exit codes: 0 every push went through or there was nothing to push, 1 a push was refused or a repository could not be read, 2 outside a repository or a usage error.
|
|
14
25
|
|
|
15
26
|
## gc
|
|
16
27
|
|
|
17
|
-
`gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter
|
|
28
|
+
`gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter, nothing with `-q`/`--quiet`; `--json` prints `{sha, subject, files: [{status, path, from?}]}`.
|
|
18
29
|
|
|
19
30
|
- The message is the title, then the `-m` lines, then the `--ticket` lines, each block after a blank line; ticket lines are copied verbatim and read `#<n> - <title>`.
|
|
20
31
|
- Before anything is staged it refuses, exit 1, saying which rule broke: a title that is no Conventional Commit, a title over one line, more than two description lines, a bullet list, a hard-wrapped sentence, any trailer (`Co-Authored-By`, `Signed-off-by`, "Generated with"). A breaking change (`feat!:` or a `BREAKING CHANGE:` line) may give full details.
|
package/dist/gb.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gb.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -10,6 +10,24 @@ import { parseArgs } from "util";
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
12
|
|
|
13
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
+
var N = new Map;
|
|
15
|
+
var Nt = /\s+\S*$/;
|
|
16
|
+
var Y = /\s/;
|
|
17
|
+
function ko(t, e, r = "...") {
|
|
18
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
+
if (t.length <= e)
|
|
20
|
+
return t;
|
|
21
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
+
c = c.replace(Nt, "") || c;
|
|
24
|
+
if (o)
|
|
25
|
+
c = c.trimEnd();
|
|
26
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
+
}
|
|
28
|
+
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
29
|
+
var z = new Map;
|
|
30
|
+
|
|
13
31
|
// ../kit/src/mode.ts
|
|
14
32
|
import process2 from "process";
|
|
15
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -35,10 +53,10 @@ function isInteractive(streams = process2) {
|
|
|
35
53
|
import process6 from "process";
|
|
36
54
|
|
|
37
55
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
38
|
-
var
|
|
56
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
39
57
|
function b(r) {
|
|
40
58
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
41
|
-
if (!
|
|
59
|
+
if (!G2.test(e))
|
|
42
60
|
return [0, 0, 0];
|
|
43
61
|
if (e.length === 3 || e.length === 4)
|
|
44
62
|
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
@@ -46,7 +64,7 @@ function b(r) {
|
|
|
46
64
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
47
65
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
48
66
|
}
|
|
49
|
-
var
|
|
67
|
+
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
50
68
|
let [l, n, c] = b(r);
|
|
51
69
|
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
52
70
|
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
@@ -64,7 +82,7 @@ function f(r, e = []) {
|
|
|
64
82
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
65
83
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
66
84
|
return new Proxy(c, { get(t, i) {
|
|
67
|
-
let a =
|
|
85
|
+
let a = B2[i];
|
|
68
86
|
if (Array.isArray(a)) {
|
|
69
87
|
let s = g.get(i);
|
|
70
88
|
if (s === undefined)
|
|
@@ -304,12 +322,22 @@ function activeTheme() {
|
|
|
304
322
|
}
|
|
305
323
|
|
|
306
324
|
// ../kit/src/style.ts
|
|
325
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
307
326
|
function takesControlCodes(stream, env = process6.env) {
|
|
308
327
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
309
328
|
}
|
|
310
329
|
function paint(stream, env = process6.env) {
|
|
311
330
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
312
331
|
}
|
|
332
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
333
|
+
const colors = paint(stream, env);
|
|
334
|
+
let head = MARK_WORDS[mark];
|
|
335
|
+
if (takesControlCodes(stream, env)) {
|
|
336
|
+
const { theme } = activeTheme();
|
|
337
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
338
|
+
}
|
|
339
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
340
|
+
}
|
|
313
341
|
function role(name, stream, env = process6.env) {
|
|
314
342
|
const colors = paint(stream, env);
|
|
315
343
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
@@ -324,11 +352,78 @@ var STATUS_WORDS = {
|
|
|
324
352
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
325
353
|
|
|
326
354
|
// ../kit/src/format.ts
|
|
355
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
356
|
+
function formatSeconds(total) {
|
|
357
|
+
let rest = Math.max(0, Math.round(total));
|
|
358
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
359
|
+
const amount = Math.floor(rest / size);
|
|
360
|
+
rest -= amount * size;
|
|
361
|
+
return `${amount}${unit}`;
|
|
362
|
+
});
|
|
363
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
364
|
+
if (first === -1)
|
|
365
|
+
return "0s";
|
|
366
|
+
const next = amounts[first + 1];
|
|
367
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
368
|
+
}
|
|
327
369
|
function upTo(text, separator) {
|
|
328
370
|
const end = text.indexOf(separator);
|
|
329
371
|
return end === -1 ? text : text.slice(0, end);
|
|
330
372
|
}
|
|
373
|
+
function formatAge(date, now = Date.now()) {
|
|
374
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
375
|
+
if (Number.isNaN(at))
|
|
376
|
+
return "-";
|
|
377
|
+
const seconds = (now - at) / 1000;
|
|
378
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
379
|
+
}
|
|
380
|
+
function truncate(text, width) {
|
|
381
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
382
|
+
}
|
|
383
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
331
384
|
var ESCAPE = String.fromCharCode(27);
|
|
385
|
+
function textWidth(text) {
|
|
386
|
+
return Bun.stringWidth(text);
|
|
387
|
+
}
|
|
388
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
389
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
390
|
+
if (outputMode(stream, env) === "agent")
|
|
391
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
392
|
+
`);
|
|
393
|
+
const widths = [];
|
|
394
|
+
for (const row of cells) {
|
|
395
|
+
for (const [index, cell] of row.entries())
|
|
396
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
397
|
+
}
|
|
398
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
399
|
+
const colors = paint(stream);
|
|
400
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
401
|
+
const width = widths[index] ?? 0;
|
|
402
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
403
|
+
if (align[index] === "right")
|
|
404
|
+
return `${gap}${cell}`;
|
|
405
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
406
|
+
}).join(" ").trimEnd());
|
|
407
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
408
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
409
|
+
`);
|
|
410
|
+
}
|
|
411
|
+
function narrow(rows, widths, limit) {
|
|
412
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
413
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
414
|
+
const floor = 8;
|
|
415
|
+
while (used() > limit) {
|
|
416
|
+
let widest = -1;
|
|
417
|
+
for (const [index, width] of widths.entries()) {
|
|
418
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
419
|
+
widest = index;
|
|
420
|
+
}
|
|
421
|
+
if (widest === -1)
|
|
422
|
+
break;
|
|
423
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
424
|
+
}
|
|
425
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
426
|
+
}
|
|
332
427
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
333
428
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
334
429
|
}
|
|
@@ -651,9 +746,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
651
746
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
652
747
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
653
748
|
}
|
|
749
|
+
// ../kit/src/argv.ts
|
|
750
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
751
|
+
import { resolve as resolve3 } from "path";
|
|
752
|
+
import process10 from "process";
|
|
753
|
+
function commandLine() {
|
|
754
|
+
try {
|
|
755
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
756
|
+
} catch {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function realPath(word) {
|
|
761
|
+
try {
|
|
762
|
+
return realpathSync(resolve3(word));
|
|
763
|
+
} catch {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
768
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
769
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
770
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
771
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
772
|
+
}
|
|
654
773
|
// ../kit/src/process.ts
|
|
655
774
|
import { constants } from "os";
|
|
656
|
-
import
|
|
775
|
+
import process11 from "process";
|
|
657
776
|
var KILL_GRACE_MS = 2000;
|
|
658
777
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
659
778
|
function exitCodeOf(code, signal) {
|
|
@@ -675,7 +794,7 @@ function holdSignals(cleanup) {
|
|
|
675
794
|
},
|
|
676
795
|
release: () => {
|
|
677
796
|
for (const signal of SIGNALS)
|
|
678
|
-
|
|
797
|
+
process11.off(signal, onSignal);
|
|
679
798
|
}
|
|
680
799
|
};
|
|
681
800
|
function onSignal(signal) {
|
|
@@ -688,10 +807,10 @@ function holdSignals(cleanup) {
|
|
|
688
807
|
return;
|
|
689
808
|
held.release();
|
|
690
809
|
cleanup(signal);
|
|
691
|
-
|
|
810
|
+
process11.kill(process11.pid, signal);
|
|
692
811
|
}
|
|
693
812
|
for (const signal of SIGNALS)
|
|
694
|
-
|
|
813
|
+
process11.on(signal, onSignal);
|
|
695
814
|
return held;
|
|
696
815
|
}
|
|
697
816
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -705,7 +824,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
705
824
|
return;
|
|
706
825
|
try {
|
|
707
826
|
if (grouped)
|
|
708
|
-
|
|
827
|
+
process11.kill(-proc.pid, killing);
|
|
709
828
|
else
|
|
710
829
|
proc.kill(killing);
|
|
711
830
|
} catch {}
|
|
@@ -779,15 +898,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
779
898
|
var RESET_STYLE = `${ESC}[0m`;
|
|
780
899
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
781
900
|
// ../kit/src/cli.ts
|
|
782
|
-
import { readFileSync as
|
|
901
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
783
902
|
import { dirname as dirname3, join as join5 } from "path";
|
|
784
|
-
import
|
|
903
|
+
import process13 from "process";
|
|
785
904
|
|
|
786
905
|
// ../kit/src/usage.ts
|
|
787
906
|
import { appendFileSync, mkdirSync } from "fs";
|
|
788
907
|
import { homedir as homedir3 } from "os";
|
|
789
908
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
790
|
-
import
|
|
909
|
+
import process12 from "process";
|
|
791
910
|
|
|
792
911
|
// ../kit/src/logs.ts
|
|
793
912
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -801,14 +920,14 @@ var usageError;
|
|
|
801
920
|
function noteUsageError(message) {
|
|
802
921
|
usageError = message;
|
|
803
922
|
}
|
|
804
|
-
function stateHome(env =
|
|
923
|
+
function stateHome(env = process12.env) {
|
|
805
924
|
const dir = env.XDG_STATE_HOME;
|
|
806
925
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
807
926
|
}
|
|
808
|
-
function usagePath(env =
|
|
927
|
+
function usagePath(env = process12.env) {
|
|
809
928
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
810
929
|
}
|
|
811
|
-
function usageRecorded(env =
|
|
930
|
+
function usageRecorded(env = process12.env) {
|
|
812
931
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
813
932
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
814
933
|
}
|
|
@@ -822,7 +941,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
822
941
|
usageError = undefined;
|
|
823
942
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
824
943
|
}
|
|
825
|
-
function recordUsage(entry, env =
|
|
944
|
+
function recordUsage(entry, env = process12.env) {
|
|
826
945
|
if (!usageRecorded(env))
|
|
827
946
|
return;
|
|
828
947
|
try {
|
|
@@ -840,8 +959,8 @@ var LEVEL_OPTIONS = {
|
|
|
840
959
|
};
|
|
841
960
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
842
961
|
function printError(prefix, message, hint, cause) {
|
|
843
|
-
const colors = paint(
|
|
844
|
-
const styled = takesControlCodes(
|
|
962
|
+
const colors = paint(process13.stderr);
|
|
963
|
+
const styled = takesControlCodes(process13.stderr);
|
|
845
964
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
846
965
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
847
966
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -888,24 +1007,24 @@ function candidateLine(candidate) {
|
|
|
888
1007
|
}
|
|
889
1008
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
890
1009
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
891
|
-
|
|
1010
|
+
const typed = [];
|
|
892
1011
|
let at = 0;
|
|
893
1012
|
while (at < before.length) {
|
|
894
1013
|
const word = before[at];
|
|
895
1014
|
if (word === "--") {
|
|
896
|
-
|
|
1015
|
+
typed.push(...before.slice(at + 1));
|
|
897
1016
|
break;
|
|
898
1017
|
}
|
|
899
1018
|
if (!word.startsWith("-"))
|
|
900
|
-
|
|
1019
|
+
typed.push(word);
|
|
901
1020
|
else if (takesValue(word))
|
|
902
1021
|
at++;
|
|
903
1022
|
at++;
|
|
904
1023
|
}
|
|
905
1024
|
const last = positionals.at(-1);
|
|
906
|
-
if (
|
|
907
|
-
return positionals[
|
|
908
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1025
|
+
if (typed.length < positionals.length)
|
|
1026
|
+
return { name: positionals[typed.length], typed };
|
|
1027
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
909
1028
|
}
|
|
910
1029
|
async function leafCandidates(run, words) {
|
|
911
1030
|
const completing = await completingOf(run);
|
|
@@ -913,12 +1032,12 @@ async function leafCandidates(run, words) {
|
|
|
913
1032
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
914
1033
|
const flag = words.at(-2);
|
|
915
1034
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1035
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
916
1036
|
if (option?.type === "string") {
|
|
917
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1037
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
918
1038
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
919
1039
|
}
|
|
920
|
-
const
|
|
921
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1040
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
922
1041
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
923
1042
|
}
|
|
924
1043
|
async function printCandidates(found) {
|
|
@@ -927,9 +1046,9 @@ async function printCandidates(found) {
|
|
|
927
1046
|
return 0;
|
|
928
1047
|
}
|
|
929
1048
|
function packageVersion(entry = Bun.main) {
|
|
930
|
-
for (let dir = dirname3(
|
|
1049
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
931
1050
|
try {
|
|
932
|
-
const { version } = JSON.parse(
|
|
1051
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
933
1052
|
if (typeof version === "string")
|
|
934
1053
|
return version;
|
|
935
1054
|
} catch {}
|
|
@@ -937,7 +1056,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
937
1056
|
return "0.0.0";
|
|
938
1057
|
}
|
|
939
1058
|
}
|
|
940
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1059
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
941
1060
|
if (argv[0] === COMPLETE)
|
|
942
1061
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
943
1062
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -966,7 +1085,7 @@ var {Glob } = globalThis.Bun;
|
|
|
966
1085
|
var SESSION_FILES = new Glob("*.json");
|
|
967
1086
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
968
1087
|
// ../kit/src/watch.ts
|
|
969
|
-
import
|
|
1088
|
+
import process14 from "process";
|
|
970
1089
|
import { format } from "util";
|
|
971
1090
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
972
1091
|
var DEFAULT_SECONDS = 2;
|
|
@@ -988,7 +1107,7 @@ function withoutWatch(args) {
|
|
|
988
1107
|
}
|
|
989
1108
|
return rest;
|
|
990
1109
|
}
|
|
991
|
-
async function watching(value, step, stream =
|
|
1110
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
992
1111
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
993
1112
|
if (!takesControlCodes(stream))
|
|
994
1113
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -996,12 +1115,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
996
1115
|
for (let round = 0;round < rounds; round++) {
|
|
997
1116
|
const held = [];
|
|
998
1117
|
const { log, info } = console;
|
|
999
|
-
const write =
|
|
1118
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1000
1119
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1001
1120
|
`);
|
|
1002
1121
|
console.log = hold;
|
|
1003
1122
|
console.info = hold;
|
|
1004
|
-
|
|
1123
|
+
process14.stdout.write = (text) => {
|
|
1005
1124
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1006
1125
|
return true;
|
|
1007
1126
|
};
|
|
@@ -1010,7 +1129,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1010
1129
|
} finally {
|
|
1011
1130
|
console.log = log;
|
|
1012
1131
|
console.info = info;
|
|
1013
|
-
|
|
1132
|
+
process14.stdout.write = write;
|
|
1014
1133
|
}
|
|
1015
1134
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1016
1135
|
await sleep(interval);
|
|
@@ -1019,7 +1138,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1019
1138
|
}
|
|
1020
1139
|
// src/branch.ts
|
|
1021
1140
|
import { basename } from "path";
|
|
1022
|
-
import
|
|
1141
|
+
import process18 from "process";
|
|
1023
1142
|
|
|
1024
1143
|
// ../kit/src/picker/score.ts
|
|
1025
1144
|
var MATCH = 16;
|
|
@@ -1114,7 +1233,9 @@ var COLUMN_GAP = 2;
|
|
|
1114
1233
|
var PASTE_START = "\x1B[200~";
|
|
1115
1234
|
var PASTE_END = "\x1B[201~";
|
|
1116
1235
|
var LAST_WORD = /\S*\s*$/;
|
|
1117
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1236
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1237
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1238
|
+
var WHEEL_LINES = 3;
|
|
1118
1239
|
var KEYS = {
|
|
1119
1240
|
"\x1B[A": "up",
|
|
1120
1241
|
"\x1BOA": "up",
|
|
@@ -1196,6 +1317,9 @@ function lay(rows, searched) {
|
|
|
1196
1317
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1197
1318
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1198
1319
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1320
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1321
|
+
if (wheel !== undefined)
|
|
1322
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1199
1323
|
const named = codes.get(sequence);
|
|
1200
1324
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1201
1325
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -1285,11 +1409,11 @@ function chosen(state) {
|
|
|
1285
1409
|
|
|
1286
1410
|
// ../kit/src/picker/terminal.ts
|
|
1287
1411
|
import { openSync } from "fs";
|
|
1288
|
-
import
|
|
1412
|
+
import process17 from "process";
|
|
1289
1413
|
import tty from "tty";
|
|
1290
1414
|
|
|
1291
1415
|
// ../kit/src/picker/preview.ts
|
|
1292
|
-
import
|
|
1416
|
+
import process16 from "process";
|
|
1293
1417
|
|
|
1294
1418
|
// ../kit/src/shell.ts
|
|
1295
1419
|
var SEPARATORS = new Set([`
|
|
@@ -1358,7 +1482,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1358
1482
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1359
1483
|
const stop = () => {
|
|
1360
1484
|
try {
|
|
1361
|
-
|
|
1485
|
+
process16.kill(-proc.pid, "SIGKILL");
|
|
1362
1486
|
} catch {
|
|
1363
1487
|
proc.kill();
|
|
1364
1488
|
}
|
|
@@ -1438,7 +1562,7 @@ function caretColumn(state, layout) {
|
|
|
1438
1562
|
}
|
|
1439
1563
|
function helpLines(state, layout, theme) {
|
|
1440
1564
|
const lines = [
|
|
1441
|
-
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1565
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
|
|
1442
1566
|
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1443
1567
|
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1444
1568
|
];
|
|
@@ -1488,8 +1612,11 @@ var ESCAPE_WAIT_MS = 30;
|
|
|
1488
1612
|
var OPEN = { ctrl: "open" };
|
|
1489
1613
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1490
1614
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
1615
|
+
var CARET = "\x1B[7m \x1B[27m";
|
|
1491
1616
|
var PASTE_ON = "\x1B[?2004h";
|
|
1492
1617
|
var PASTE_OFF = "\x1B[?2004l";
|
|
1618
|
+
var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
|
|
1619
|
+
var MOUSE_OFF = "\x1B[?1006l\x1B[?1000l";
|
|
1493
1620
|
var CLEAR_BELOW = "\r\x1B[J";
|
|
1494
1621
|
var SIGNALS2 = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1495
1622
|
function up(lines) {
|
|
@@ -1503,7 +1630,7 @@ function openTerminal() {
|
|
|
1503
1630
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1504
1631
|
}
|
|
1505
1632
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
1506
|
-
const out =
|
|
1633
|
+
const out = process17.stderr;
|
|
1507
1634
|
let resize;
|
|
1508
1635
|
async function read(onChunk) {
|
|
1509
1636
|
const decoder = new TextDecoder;
|
|
@@ -1552,21 +1679,18 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1552
1679
|
let finish;
|
|
1553
1680
|
let restored = false;
|
|
1554
1681
|
let escape;
|
|
1555
|
-
let caret;
|
|
1556
1682
|
function draw(clear = false) {
|
|
1557
1683
|
if (restored)
|
|
1558
1684
|
return;
|
|
1559
1685
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1560
1686
|
let frame = HIDE_CURSOR;
|
|
1561
1687
|
if (reserved !== layout.height || clear) {
|
|
1562
|
-
frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
|
|
1563
1688
|
frame += CLEAR_BELOW + `
|
|
1564
1689
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1565
1690
|
reserved = layout.height;
|
|
1566
1691
|
}
|
|
1567
|
-
caret = caretColumn(state, layout);
|
|
1568
1692
|
frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
|
|
1569
|
-
`)}${up(layout.height - 1)}\r\x1B[${
|
|
1693
|
+
`)}${up(layout.height - 1)}\r\x1B[${caretColumn(state, layout)}G${CARET}\r`;
|
|
1570
1694
|
terminal.write(frame);
|
|
1571
1695
|
}
|
|
1572
1696
|
function pageSize() {
|
|
@@ -1605,7 +1729,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1605
1729
|
clearTimeout(previewTimer);
|
|
1606
1730
|
clearTimeout(escape);
|
|
1607
1731
|
previewing.abort();
|
|
1608
|
-
terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1732
|
+
terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1609
1733
|
terminal.close();
|
|
1610
1734
|
}
|
|
1611
1735
|
const stop = () => {
|
|
@@ -1680,11 +1804,11 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1680
1804
|
const ended = new Promise((resolve) => {
|
|
1681
1805
|
finish = resolve;
|
|
1682
1806
|
});
|
|
1683
|
-
|
|
1807
|
+
process17.once("exit", restore);
|
|
1684
1808
|
for (const signal of SIGNALS2)
|
|
1685
|
-
|
|
1809
|
+
process17.once(signal, stop);
|
|
1686
1810
|
try {
|
|
1687
|
-
terminal.write(PASTE_ON);
|
|
1811
|
+
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
1688
1812
|
terminal.listen(onChunk, () => draw(true));
|
|
1689
1813
|
refreshPreview();
|
|
1690
1814
|
draw(true);
|
|
@@ -1695,8 +1819,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1695
1819
|
await ended;
|
|
1696
1820
|
} finally {
|
|
1697
1821
|
for (const signal of SIGNALS2)
|
|
1698
|
-
|
|
1699
|
-
|
|
1822
|
+
process17.off(signal, stop);
|
|
1823
|
+
process17.off("exit", restore);
|
|
1700
1824
|
restore();
|
|
1701
1825
|
}
|
|
1702
1826
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -1709,7 +1833,7 @@ async function previewOf(preview, hidden, signal) {
|
|
|
1709
1833
|
}
|
|
1710
1834
|
}
|
|
1711
1835
|
// ../kit/src/picker.ts
|
|
1712
|
-
function
|
|
1836
|
+
function table2(rows) {
|
|
1713
1837
|
const widths = rows[0]?.cells.map((_, index) => Math.max(...rows.map((row) => Bun.stringWidth(row.cells[index])))) ?? [];
|
|
1714
1838
|
return rows.map((row) => [
|
|
1715
1839
|
...row.hidden,
|
|
@@ -1757,7 +1881,7 @@ var options = {
|
|
|
1757
1881
|
delete: { type: "boolean", short: "d", description: "delete the local branch with git branch -d" },
|
|
1758
1882
|
json: jsonOption("[{ name, remote, worktree, when, subject, date, upstream, track, merged }]")
|
|
1759
1883
|
};
|
|
1760
|
-
var FIELDS = ["%(refname)", "%(refname:short)", "%(committerdate:unix)", "%(
|
|
1884
|
+
var FIELDS = ["%(refname)", "%(refname:short)", "%(committerdate:unix)", "%(subject)", "%(worktreepath)", "%(upstream:short)", "%(upstream:track,nobracket)"];
|
|
1761
1885
|
var CHECKOUT = /^checkout: moving from (\S+) to (\S+)$/;
|
|
1762
1886
|
var KEYS2 = "enter go, ctrl-n new from query, ctrl-d delete if merged, ctrl-r fetch";
|
|
1763
1887
|
var TRACK_TINTS = { ahead: "green", behind: "red", gone: "yellow" };
|
|
@@ -1800,13 +1924,13 @@ function branches(against) {
|
|
|
1800
1924
|
`).filter(Boolean);
|
|
1801
1925
|
const merged = new Set(against !== undefined ? read(["branch", "--merged", against, "--format=%(refname:short)"]).split(`
|
|
1802
1926
|
`) : []);
|
|
1803
|
-
return lines.map((line) => line.split("\x00")).filter(([ref = ""]) => !ref.endsWith("/HEAD")).map(([ref = "", name = "", date = "0",
|
|
1927
|
+
return lines.map((line) => line.split("\x00")).filter(([ref = ""]) => !ref.endsWith("/HEAD")).map(([ref = "", name = "", date = "0", subject = "", worktree = "", upstream = "", track = ""]) => {
|
|
1804
1928
|
const remote = ref.startsWith("refs/remotes/");
|
|
1805
1929
|
return {
|
|
1806
1930
|
name,
|
|
1807
1931
|
remote,
|
|
1808
1932
|
worktree: worktree === here ? "" : worktree,
|
|
1809
|
-
when,
|
|
1933
|
+
when: formatAge(Number(date) * 1000),
|
|
1810
1934
|
subject,
|
|
1811
1935
|
date: Number(date),
|
|
1812
1936
|
upstream,
|
|
@@ -1967,7 +2091,7 @@ async function gb(args) {
|
|
|
1967
2091
|
if (parsed.values.json === true)
|
|
1968
2092
|
printJson(all);
|
|
1969
2093
|
else
|
|
1970
|
-
console.log(
|
|
2094
|
+
console.log(table2(all.map(row)).map((line) => takesControlCodes(process18.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
1971
2095
|
`));
|
|
1972
2096
|
return 0;
|
|
1973
2097
|
}
|
|
@@ -2024,4 +2148,4 @@ async function finish(command, typed, emitting) {
|
|
|
2024
2148
|
}
|
|
2025
2149
|
|
|
2026
2150
|
// src/gb.ts
|
|
2027
|
-
|
|
2151
|
+
process19.exitCode = await runMain({ name: "gb", run: gb });
|