@kaynooo/cli-git 0.9.0 → 0.10.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/dist/gb.js +140 -18
- package/dist/gc.js +66 -4
- package/dist/gst.js +74 -9
- package/package.json +2 -2
package/dist/gb.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gb.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -618,13 +618,23 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
618
618
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
619
619
|
return number;
|
|
620
620
|
}
|
|
621
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
622
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
623
|
+
function duration(value, name, fallback, unit = "s") {
|
|
624
|
+
if (value === undefined)
|
|
625
|
+
return fallback;
|
|
626
|
+
const match = DURATION.exec(value.trim());
|
|
627
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
628
|
+
if (ms < 1)
|
|
629
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
630
|
+
return ms;
|
|
631
|
+
}
|
|
621
632
|
|
|
622
633
|
// ../kit/src/args.ts
|
|
623
634
|
var DASHES = /^-+/;
|
|
624
635
|
function jsonOption(holds) {
|
|
625
636
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
626
637
|
}
|
|
627
|
-
|
|
628
638
|
class Exit extends Error {
|
|
629
639
|
code;
|
|
630
640
|
hint;
|
|
@@ -1149,9 +1159,61 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
1149
1159
|
var {Glob } = globalThis.Bun;
|
|
1150
1160
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1161
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1162
|
+
// ../kit/src/watch.ts
|
|
1163
|
+
import process13 from "process";
|
|
1164
|
+
import { format } from "util";
|
|
1165
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1166
|
+
var DEFAULT_SECONDS = 2;
|
|
1167
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1168
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1169
|
+
function watchOption(what) {
|
|
1170
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1171
|
+
}
|
|
1172
|
+
function withoutWatch(args) {
|
|
1173
|
+
const rest = [];
|
|
1174
|
+
for (let at = 0;at < args.length; at++) {
|
|
1175
|
+
const arg = args[at];
|
|
1176
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1177
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1178
|
+
at++;
|
|
1179
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1180
|
+
rest.push(arg);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return rest;
|
|
1184
|
+
}
|
|
1185
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1186
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1187
|
+
if (!takesControlCodes(stream))
|
|
1188
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1189
|
+
let code = 0;
|
|
1190
|
+
for (let round = 0;round < rounds; round++) {
|
|
1191
|
+
const held = [];
|
|
1192
|
+
const { log, info } = console;
|
|
1193
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1194
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1195
|
+
`);
|
|
1196
|
+
console.log = hold;
|
|
1197
|
+
console.info = hold;
|
|
1198
|
+
process13.stdout.write = (text) => {
|
|
1199
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1200
|
+
return true;
|
|
1201
|
+
};
|
|
1202
|
+
try {
|
|
1203
|
+
code = await step();
|
|
1204
|
+
} finally {
|
|
1205
|
+
console.log = log;
|
|
1206
|
+
console.info = info;
|
|
1207
|
+
process13.stdout.write = write;
|
|
1208
|
+
}
|
|
1209
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1210
|
+
await sleep(interval);
|
|
1211
|
+
}
|
|
1212
|
+
return code;
|
|
1213
|
+
}
|
|
1152
1214
|
// src/branch.ts
|
|
1153
1215
|
import { basename } from "path";
|
|
1154
|
-
import
|
|
1216
|
+
import process17 from "process";
|
|
1155
1217
|
|
|
1156
1218
|
// ../kit/src/picker/score.ts
|
|
1157
1219
|
var MATCH = 16;
|
|
@@ -1254,6 +1316,14 @@ var KEYS = {
|
|
|
1254
1316
|
"\x1B[B": "down",
|
|
1255
1317
|
"\x1BOB": "down",
|
|
1256
1318
|
"\x0E": "down",
|
|
1319
|
+
"\x1B[5~": "pageup",
|
|
1320
|
+
"\x1B[6~": "pagedown",
|
|
1321
|
+
"\x1B[H": "home",
|
|
1322
|
+
"\x1B[1~": "home",
|
|
1323
|
+
"\x1BOH": "home",
|
|
1324
|
+
"\x1B[F": "end",
|
|
1325
|
+
"\x1B[4~": "end",
|
|
1326
|
+
"\x1BOF": "end",
|
|
1257
1327
|
"\r": "enter",
|
|
1258
1328
|
"\n": "enter",
|
|
1259
1329
|
"\x03": "cancel",
|
|
@@ -1262,7 +1332,10 @@ var KEYS = {
|
|
|
1262
1332
|
"\b": "erase",
|
|
1263
1333
|
"\x15": "clear",
|
|
1264
1334
|
"\x17": "word",
|
|
1265
|
-
"\t": "tab"
|
|
1335
|
+
"\t": "tab",
|
|
1336
|
+
"\x1F": "help",
|
|
1337
|
+
"\x1BOP": "help",
|
|
1338
|
+
"\x1B[11~": "help"
|
|
1266
1339
|
};
|
|
1267
1340
|
var CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1268
1341
|
function repeat(value, count) {
|
|
@@ -1332,7 +1405,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1332
1405
|
});
|
|
1333
1406
|
}
|
|
1334
1407
|
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1335
|
-
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, marked: new Set, multi, prompt, done: undefined };
|
|
1408
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1336
1409
|
return withRows(state, rows);
|
|
1337
1410
|
}
|
|
1338
1411
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1354,6 +1427,8 @@ function highlighted(state) {
|
|
|
1354
1427
|
function press(state, key) {
|
|
1355
1428
|
if (state.done !== undefined)
|
|
1356
1429
|
return state;
|
|
1430
|
+
if (state.help)
|
|
1431
|
+
return { ...state, help: false };
|
|
1357
1432
|
if (typeof key === "object") {
|
|
1358
1433
|
if ("text" in key)
|
|
1359
1434
|
return withQuery(state, state.query + key.text);
|
|
@@ -1364,8 +1439,18 @@ function press(state, key) {
|
|
|
1364
1439
|
return move(state, -1);
|
|
1365
1440
|
case "down":
|
|
1366
1441
|
return move(state, 1);
|
|
1442
|
+
case "pageup":
|
|
1443
|
+
return move(state, -state.page);
|
|
1444
|
+
case "pagedown":
|
|
1445
|
+
return move(state, state.page);
|
|
1446
|
+
case "home":
|
|
1447
|
+
return move(state, -state.matches.length);
|
|
1448
|
+
case "end":
|
|
1449
|
+
return move(state, state.matches.length);
|
|
1367
1450
|
case "cancel":
|
|
1368
1451
|
return { ...state, done: "cancel" };
|
|
1452
|
+
case "help":
|
|
1453
|
+
return { ...state, help: true };
|
|
1369
1454
|
case "erase":
|
|
1370
1455
|
return withQuery(state, [...state.query].slice(0, -1).join(""));
|
|
1371
1456
|
case "clear":
|
|
@@ -1394,11 +1479,11 @@ function chosen(state) {
|
|
|
1394
1479
|
|
|
1395
1480
|
// ../kit/src/picker/terminal.ts
|
|
1396
1481
|
import { openSync } from "fs";
|
|
1397
|
-
import
|
|
1482
|
+
import process16 from "process";
|
|
1398
1483
|
import tty from "tty";
|
|
1399
1484
|
|
|
1400
1485
|
// ../kit/src/picker/preview.ts
|
|
1401
|
-
import
|
|
1486
|
+
import process15 from "process";
|
|
1402
1487
|
|
|
1403
1488
|
// ../kit/src/shell.ts
|
|
1404
1489
|
var SEPARATORS = new Set([`
|
|
@@ -1467,7 +1552,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1467
1552
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1468
1553
|
const stop = () => {
|
|
1469
1554
|
try {
|
|
1470
|
-
|
|
1555
|
+
process15.kill(-proc.pid, "SIGKILL");
|
|
1471
1556
|
} catch {
|
|
1472
1557
|
proc.kill();
|
|
1473
1558
|
}
|
|
@@ -1545,7 +1630,18 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1545
1630
|
function caretColumn(state, layout) {
|
|
1546
1631
|
return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
|
|
1547
1632
|
}
|
|
1633
|
+
function helpLines(state, layout, theme) {
|
|
1634
|
+
const lines = [
|
|
1635
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1636
|
+
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1637
|
+
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1638
|
+
];
|
|
1639
|
+
const title = "keys, any key closes this help";
|
|
1640
|
+
return [{ text: theme.accent(title), width: title.length }, ...lines.map((line) => fit(` ${line}`, layout.listWidth, theme.label))];
|
|
1641
|
+
}
|
|
1548
1642
|
function listLines(state, layout, theme) {
|
|
1643
|
+
if (state.help)
|
|
1644
|
+
return helpLines(state, layout, theme);
|
|
1549
1645
|
const header = state.header === "" ? [] : state.header.split(`
|
|
1550
1646
|
`).map((line) => fitStyled(line, layout.listWidth, theme.label));
|
|
1551
1647
|
const rows = Math.max(1, layout.listHeight - 2 - header.length);
|
|
@@ -1554,7 +1650,8 @@ function listLines(state, layout, theme) {
|
|
|
1554
1650
|
const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
|
|
1555
1651
|
const promptWidth = Bun.stringWidth(state.prompt);
|
|
1556
1652
|
const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
|
|
1557
|
-
const
|
|
1653
|
+
const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
|
|
1654
|
+
const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks}`, layout.listWidth, theme.label);
|
|
1558
1655
|
const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
|
|
1559
1656
|
if (state.matches.length === 0)
|
|
1560
1657
|
lines.push(fit(" no match", layout.listWidth, theme.label));
|
|
@@ -1581,6 +1678,7 @@ function render(state, layout, theme, preview = []) {
|
|
|
1581
1678
|
|
|
1582
1679
|
// ../kit/src/picker/terminal.ts
|
|
1583
1680
|
var PREVIEW_DELAY_MS = 120;
|
|
1681
|
+
var ESCAPE_WAIT_MS = 30;
|
|
1584
1682
|
var OPEN = { ctrl: "open" };
|
|
1585
1683
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1586
1684
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
@@ -1598,7 +1696,7 @@ function openTerminal() {
|
|
|
1598
1696
|
} catch {
|
|
1599
1697
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1600
1698
|
}
|
|
1601
|
-
const out =
|
|
1699
|
+
const out = process16.stderr;
|
|
1602
1700
|
let resize;
|
|
1603
1701
|
return {
|
|
1604
1702
|
get columns() {
|
|
@@ -1636,20 +1734,29 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1636
1734
|
let shownLine;
|
|
1637
1735
|
let finish;
|
|
1638
1736
|
let restored = false;
|
|
1737
|
+
let escape;
|
|
1738
|
+
let caret;
|
|
1639
1739
|
function draw(clear = false) {
|
|
1640
1740
|
if (restored)
|
|
1641
1741
|
return;
|
|
1642
1742
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1643
1743
|
let frame = HIDE_CURSOR;
|
|
1644
1744
|
if (reserved !== layout.height || clear) {
|
|
1745
|
+
frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
|
|
1645
1746
|
frame += CLEAR_BELOW + `
|
|
1646
1747
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1647
1748
|
reserved = layout.height;
|
|
1648
1749
|
}
|
|
1750
|
+
caret = caretColumn(state, layout);
|
|
1649
1751
|
frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
|
|
1650
|
-
`)}${up(layout.height - 1)}\r\x1B[${
|
|
1752
|
+
`)}${up(layout.height - 1)}\r\x1B[${caret}G${SHOW_CURSOR}`;
|
|
1651
1753
|
terminal.write(frame);
|
|
1652
1754
|
}
|
|
1755
|
+
function pageSize() {
|
|
1756
|
+
const headerLines = state.header === "" ? 0 : state.header.split(`
|
|
1757
|
+
`).length;
|
|
1758
|
+
return Math.max(1, layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition).listHeight - 2 - headerLines);
|
|
1759
|
+
}
|
|
1653
1760
|
function refreshPreview() {
|
|
1654
1761
|
const at = highlighted(state);
|
|
1655
1762
|
if (settings.preview === undefined || at === shownLine)
|
|
@@ -1679,6 +1786,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1679
1786
|
return;
|
|
1680
1787
|
restored = true;
|
|
1681
1788
|
clearTimeout(previewTimer);
|
|
1789
|
+
clearTimeout(escape);
|
|
1682
1790
|
previewing.abort();
|
|
1683
1791
|
terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1684
1792
|
terminal.close();
|
|
@@ -1717,7 +1825,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1717
1825
|
if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
|
|
1718
1826
|
await reloadRows();
|
|
1719
1827
|
else
|
|
1720
|
-
state = press(state, key);
|
|
1828
|
+
state = press({ ...state, page: pageSize() }, key);
|
|
1721
1829
|
}
|
|
1722
1830
|
} finally {
|
|
1723
1831
|
draining = false;
|
|
@@ -1730,6 +1838,20 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1730
1838
|
draw();
|
|
1731
1839
|
}
|
|
1732
1840
|
function onChunk(chunk) {
|
|
1841
|
+
if (escape !== undefined) {
|
|
1842
|
+
clearTimeout(escape);
|
|
1843
|
+
escape = undefined;
|
|
1844
|
+
chunk = `\x1B${chunk}`;
|
|
1845
|
+
} else if (chunk === "\x1B") {
|
|
1846
|
+
escape = setTimeout(() => {
|
|
1847
|
+
escape = undefined;
|
|
1848
|
+
takeKeys("\x1B");
|
|
1849
|
+
}, ESCAPE_WAIT_MS);
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
takeKeys(chunk);
|
|
1853
|
+
}
|
|
1854
|
+
function takeKeys(chunk) {
|
|
1733
1855
|
const keys = parseKeys(chunk, paste, [...settings.expect ?? [], ...reload?.key === undefined ? [] : [reload.key]]);
|
|
1734
1856
|
if (busy && keys.includes("cancel")) {
|
|
1735
1857
|
stop();
|
|
@@ -1741,9 +1863,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1741
1863
|
const ended = new Promise((resolve) => {
|
|
1742
1864
|
finish = resolve;
|
|
1743
1865
|
});
|
|
1744
|
-
|
|
1866
|
+
process16.once("exit", restore);
|
|
1745
1867
|
for (const signal of SIGNALS2)
|
|
1746
|
-
|
|
1868
|
+
process16.once(signal, stop);
|
|
1747
1869
|
try {
|
|
1748
1870
|
terminal.write(PASTE_ON);
|
|
1749
1871
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -1756,8 +1878,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1756
1878
|
await ended;
|
|
1757
1879
|
} finally {
|
|
1758
1880
|
for (const signal of SIGNALS2)
|
|
1759
|
-
|
|
1760
|
-
|
|
1881
|
+
process16.off(signal, stop);
|
|
1882
|
+
process16.off("exit", restore);
|
|
1761
1883
|
restore();
|
|
1762
1884
|
}
|
|
1763
1885
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2028,7 +2150,7 @@ async function gb(args) {
|
|
|
2028
2150
|
if (parsed.values.json === true)
|
|
2029
2151
|
printJson(all);
|
|
2030
2152
|
else
|
|
2031
|
-
console.log(table(all.map(row)).map((line) => takesControlCodes(
|
|
2153
|
+
console.log(table(all.map(row)).map((line) => takesControlCodes(process17.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
2032
2154
|
`));
|
|
2033
2155
|
return 0;
|
|
2034
2156
|
}
|
|
@@ -2085,4 +2207,4 @@ async function finish(command, typed, emitting) {
|
|
|
2085
2207
|
}
|
|
2086
2208
|
|
|
2087
2209
|
// src/gb.ts
|
|
2088
|
-
|
|
2210
|
+
process18.exitCode = await runMain({ name: "gb", run: gb });
|
package/dist/gc.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gc.ts
|
|
5
|
-
import
|
|
5
|
+
import process15 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -618,13 +618,23 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
618
618
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
619
619
|
return number;
|
|
620
620
|
}
|
|
621
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
622
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
623
|
+
function duration(value, name, fallback, unit = "s") {
|
|
624
|
+
if (value === undefined)
|
|
625
|
+
return fallback;
|
|
626
|
+
const match = DURATION.exec(value.trim());
|
|
627
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
628
|
+
if (ms < 1)
|
|
629
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
630
|
+
return ms;
|
|
631
|
+
}
|
|
621
632
|
|
|
622
633
|
// ../kit/src/args.ts
|
|
623
634
|
var DASHES = /^-+/;
|
|
624
635
|
function jsonOption(holds) {
|
|
625
636
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
626
637
|
}
|
|
627
|
-
|
|
628
638
|
class Exit extends Error {
|
|
629
639
|
code;
|
|
630
640
|
hint;
|
|
@@ -1149,6 +1159,58 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
1149
1159
|
var {Glob } = globalThis.Bun;
|
|
1150
1160
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1161
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1162
|
+
// ../kit/src/watch.ts
|
|
1163
|
+
import process13 from "process";
|
|
1164
|
+
import { format } from "util";
|
|
1165
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1166
|
+
var DEFAULT_SECONDS = 2;
|
|
1167
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1168
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1169
|
+
function watchOption(what) {
|
|
1170
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1171
|
+
}
|
|
1172
|
+
function withoutWatch(args) {
|
|
1173
|
+
const rest = [];
|
|
1174
|
+
for (let at = 0;at < args.length; at++) {
|
|
1175
|
+
const arg = args[at];
|
|
1176
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1177
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1178
|
+
at++;
|
|
1179
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1180
|
+
rest.push(arg);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return rest;
|
|
1184
|
+
}
|
|
1185
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1186
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1187
|
+
if (!takesControlCodes(stream))
|
|
1188
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1189
|
+
let code = 0;
|
|
1190
|
+
for (let round = 0;round < rounds; round++) {
|
|
1191
|
+
const held = [];
|
|
1192
|
+
const { log, info } = console;
|
|
1193
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1194
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1195
|
+
`);
|
|
1196
|
+
console.log = hold;
|
|
1197
|
+
console.info = hold;
|
|
1198
|
+
process13.stdout.write = (text) => {
|
|
1199
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1200
|
+
return true;
|
|
1201
|
+
};
|
|
1202
|
+
try {
|
|
1203
|
+
code = await step();
|
|
1204
|
+
} finally {
|
|
1205
|
+
console.log = log;
|
|
1206
|
+
console.info = info;
|
|
1207
|
+
process13.stdout.write = write;
|
|
1208
|
+
}
|
|
1209
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1210
|
+
await sleep(interval);
|
|
1211
|
+
}
|
|
1212
|
+
return code;
|
|
1213
|
+
}
|
|
1152
1214
|
// src/git.ts
|
|
1153
1215
|
async function git2(args, env) {
|
|
1154
1216
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -1220,7 +1282,7 @@ var OPTIONS = {
|
|
|
1220
1282
|
};
|
|
1221
1283
|
var RENAME = /^[RC]\d*$/;
|
|
1222
1284
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
1223
|
-
var LITERAL = { ...
|
|
1285
|
+
var LITERAL = { ...process15.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
1224
1286
|
function messageOf(title, lines, tickets) {
|
|
1225
1287
|
return [title, lines.join(`
|
|
1226
1288
|
`), tickets.join(`
|
|
@@ -1318,4 +1380,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
1318
1380
|
signals.release();
|
|
1319
1381
|
}
|
|
1320
1382
|
}
|
|
1321
|
-
|
|
1383
|
+
process15.exitCode = await runMain({ name: "gc", run: main });
|
package/dist/gst.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gst.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -618,13 +618,23 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
618
618
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
619
619
|
return number;
|
|
620
620
|
}
|
|
621
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
622
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
623
|
+
function duration(value, name, fallback, unit = "s") {
|
|
624
|
+
if (value === undefined)
|
|
625
|
+
return fallback;
|
|
626
|
+
const match = DURATION.exec(value.trim());
|
|
627
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
628
|
+
if (ms < 1)
|
|
629
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
630
|
+
return ms;
|
|
631
|
+
}
|
|
621
632
|
|
|
622
633
|
// ../kit/src/args.ts
|
|
623
634
|
var DASHES = /^-+/;
|
|
624
635
|
function jsonOption(holds) {
|
|
625
636
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
626
637
|
}
|
|
627
|
-
|
|
628
638
|
class Exit extends Error {
|
|
629
639
|
code;
|
|
630
640
|
hint;
|
|
@@ -1149,9 +1159,61 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
1149
1159
|
var {Glob } = globalThis.Bun;
|
|
1150
1160
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1161
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1162
|
+
// ../kit/src/watch.ts
|
|
1163
|
+
import process13 from "process";
|
|
1164
|
+
import { format } from "util";
|
|
1165
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1166
|
+
var DEFAULT_SECONDS = 2;
|
|
1167
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1168
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1169
|
+
function watchOption(what) {
|
|
1170
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1171
|
+
}
|
|
1172
|
+
function withoutWatch(args) {
|
|
1173
|
+
const rest = [];
|
|
1174
|
+
for (let at = 0;at < args.length; at++) {
|
|
1175
|
+
const arg = args[at];
|
|
1176
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1177
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1178
|
+
at++;
|
|
1179
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1180
|
+
rest.push(arg);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return rest;
|
|
1184
|
+
}
|
|
1185
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1186
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1187
|
+
if (!takesControlCodes(stream))
|
|
1188
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1189
|
+
let code = 0;
|
|
1190
|
+
for (let round = 0;round < rounds; round++) {
|
|
1191
|
+
const held = [];
|
|
1192
|
+
const { log, info } = console;
|
|
1193
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1194
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1195
|
+
`);
|
|
1196
|
+
console.log = hold;
|
|
1197
|
+
console.info = hold;
|
|
1198
|
+
process13.stdout.write = (text) => {
|
|
1199
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1200
|
+
return true;
|
|
1201
|
+
};
|
|
1202
|
+
try {
|
|
1203
|
+
code = await step();
|
|
1204
|
+
} finally {
|
|
1205
|
+
console.log = log;
|
|
1206
|
+
console.info = info;
|
|
1207
|
+
process13.stdout.write = write;
|
|
1208
|
+
}
|
|
1209
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1210
|
+
await sleep(interval);
|
|
1211
|
+
}
|
|
1212
|
+
return code;
|
|
1213
|
+
}
|
|
1152
1214
|
// src/colour.ts
|
|
1153
|
-
import
|
|
1154
|
-
function letter(status, stream =
|
|
1215
|
+
import process15 from "process";
|
|
1216
|
+
function letter(status, stream = process15.stdout) {
|
|
1155
1217
|
const colors = paint(stream);
|
|
1156
1218
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1157
1219
|
return tint(status);
|
|
@@ -1242,10 +1304,11 @@ var USAGE = `gst [--log N]: the repository's branch, upstream, changed files and
|
|
|
1242
1304
|
Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
|
|
1243
1305
|
var OPTIONS = {
|
|
1244
1306
|
log: { type: "string", short: "l", description: "add the last N commits as <sha7> <title>" },
|
|
1307
|
+
watch: watchOption("the status"),
|
|
1245
1308
|
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
|
|
1246
1309
|
};
|
|
1247
1310
|
function group(title, lines) {
|
|
1248
|
-
return lines.length === 0 ? [] : [paint(
|
|
1311
|
+
return lines.length === 0 ? [] : [paint(process16.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1249
1312
|
}
|
|
1250
1313
|
function staged({ index, from, path }) {
|
|
1251
1314
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
@@ -1256,6 +1319,8 @@ async function main(argv) {
|
|
|
1256
1319
|
fail(`gst takes no paths
|
|
1257
1320
|
|
|
1258
1321
|
${USAGE}`);
|
|
1322
|
+
if (parsed.values.watch !== undefined)
|
|
1323
|
+
return watching(parsed.values.watch, async () => main(withoutWatch(argv)));
|
|
1259
1324
|
const count = parsed.values.log === undefined ? 0 : wholeNumber(parsed.values.log, "log", 1);
|
|
1260
1325
|
const [read, head, log] = await Promise.all([
|
|
1261
1326
|
git2(["status", "--porcelain=v2", "--branch"]),
|
|
@@ -1288,12 +1353,12 @@ ${USAGE}`);
|
|
|
1288
1353
|
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1289
1354
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1290
1355
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
1291
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
1292
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
1293
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
1356
|
+
...group("untracked", status.untracked.map((file) => paint(process16.stdout).dim(file))),
|
|
1357
|
+
...group("conflicted", status.conflicted.map((file) => paint(process16.stdout).red(file))),
|
|
1358
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process16.stdout)(commitSha)} ${commitTitle}`))
|
|
1294
1359
|
];
|
|
1295
1360
|
console.log(lines.join(`
|
|
1296
1361
|
`));
|
|
1297
1362
|
return 0;
|
|
1298
1363
|
}
|
|
1299
|
-
|
|
1364
|
+
process16.exitCode = await runMain({ name: "gst", run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "gst, gc and gb: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, and a branch picked.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"gb": "$npm_execpath src/gb.ts"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@kaynooo/cli-kit": "0.
|
|
47
|
+
"@kaynooo/cli-kit": "0.25.0"
|
|
48
48
|
}
|
|
49
49
|
}
|