@kaynooo/cli-git 0.9.0 → 0.10.1
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 +159 -24
- package/dist/gc.js +68 -4
- package/dist/gst.js +76 -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;
|
|
@@ -1143,15 +1153,69 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1143
1153
|
}
|
|
1144
1154
|
return code;
|
|
1145
1155
|
}
|
|
1156
|
+
// ../kit/src/folders.ts
|
|
1157
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1146
1158
|
// ../kit/src/secrets.ts
|
|
1147
1159
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1148
1160
|
// ../kit/src/sessions.ts
|
|
1149
1161
|
var {Glob } = globalThis.Bun;
|
|
1150
1162
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1163
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1164
|
+
// ../kit/src/watch.ts
|
|
1165
|
+
import process13 from "process";
|
|
1166
|
+
import { format } from "util";
|
|
1167
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1168
|
+
var DEFAULT_SECONDS = 2;
|
|
1169
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1170
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1171
|
+
function watchOption(what) {
|
|
1172
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1173
|
+
}
|
|
1174
|
+
function withoutWatch(args) {
|
|
1175
|
+
const rest = [];
|
|
1176
|
+
for (let at = 0;at < args.length; at++) {
|
|
1177
|
+
const arg = args[at];
|
|
1178
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1179
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1180
|
+
at++;
|
|
1181
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1182
|
+
rest.push(arg);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return rest;
|
|
1186
|
+
}
|
|
1187
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1188
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1189
|
+
if (!takesControlCodes(stream))
|
|
1190
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1191
|
+
let code = 0;
|
|
1192
|
+
for (let round = 0;round < rounds; round++) {
|
|
1193
|
+
const held = [];
|
|
1194
|
+
const { log, info } = console;
|
|
1195
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1196
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1197
|
+
`);
|
|
1198
|
+
console.log = hold;
|
|
1199
|
+
console.info = hold;
|
|
1200
|
+
process13.stdout.write = (text) => {
|
|
1201
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1202
|
+
return true;
|
|
1203
|
+
};
|
|
1204
|
+
try {
|
|
1205
|
+
code = await step();
|
|
1206
|
+
} finally {
|
|
1207
|
+
console.log = log;
|
|
1208
|
+
console.info = info;
|
|
1209
|
+
process13.stdout.write = write;
|
|
1210
|
+
}
|
|
1211
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1212
|
+
await sleep(interval);
|
|
1213
|
+
}
|
|
1214
|
+
return code;
|
|
1215
|
+
}
|
|
1152
1216
|
// src/branch.ts
|
|
1153
1217
|
import { basename } from "path";
|
|
1154
|
-
import
|
|
1218
|
+
import process17 from "process";
|
|
1155
1219
|
|
|
1156
1220
|
// ../kit/src/picker/score.ts
|
|
1157
1221
|
var MATCH = 16;
|
|
@@ -1254,6 +1318,14 @@ var KEYS = {
|
|
|
1254
1318
|
"\x1B[B": "down",
|
|
1255
1319
|
"\x1BOB": "down",
|
|
1256
1320
|
"\x0E": "down",
|
|
1321
|
+
"\x1B[5~": "pageup",
|
|
1322
|
+
"\x1B[6~": "pagedown",
|
|
1323
|
+
"\x1B[H": "home",
|
|
1324
|
+
"\x1B[1~": "home",
|
|
1325
|
+
"\x1BOH": "home",
|
|
1326
|
+
"\x1B[F": "end",
|
|
1327
|
+
"\x1B[4~": "end",
|
|
1328
|
+
"\x1BOF": "end",
|
|
1257
1329
|
"\r": "enter",
|
|
1258
1330
|
"\n": "enter",
|
|
1259
1331
|
"\x03": "cancel",
|
|
@@ -1262,7 +1334,10 @@ var KEYS = {
|
|
|
1262
1334
|
"\b": "erase",
|
|
1263
1335
|
"\x15": "clear",
|
|
1264
1336
|
"\x17": "word",
|
|
1265
|
-
"\t": "tab"
|
|
1337
|
+
"\t": "tab",
|
|
1338
|
+
"\x1F": "help",
|
|
1339
|
+
"\x1BOP": "help",
|
|
1340
|
+
"\x1B[11~": "help"
|
|
1266
1341
|
};
|
|
1267
1342
|
var CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1268
1343
|
function repeat(value, count) {
|
|
@@ -1332,7 +1407,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1332
1407
|
});
|
|
1333
1408
|
}
|
|
1334
1409
|
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 };
|
|
1410
|
+
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
1411
|
return withRows(state, rows);
|
|
1337
1412
|
}
|
|
1338
1413
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1354,6 +1429,8 @@ function highlighted(state) {
|
|
|
1354
1429
|
function press(state, key) {
|
|
1355
1430
|
if (state.done !== undefined)
|
|
1356
1431
|
return state;
|
|
1432
|
+
if (state.help)
|
|
1433
|
+
return { ...state, help: false };
|
|
1357
1434
|
if (typeof key === "object") {
|
|
1358
1435
|
if ("text" in key)
|
|
1359
1436
|
return withQuery(state, state.query + key.text);
|
|
@@ -1364,8 +1441,18 @@ function press(state, key) {
|
|
|
1364
1441
|
return move(state, -1);
|
|
1365
1442
|
case "down":
|
|
1366
1443
|
return move(state, 1);
|
|
1444
|
+
case "pageup":
|
|
1445
|
+
return move(state, -state.page);
|
|
1446
|
+
case "pagedown":
|
|
1447
|
+
return move(state, state.page);
|
|
1448
|
+
case "home":
|
|
1449
|
+
return move(state, -state.matches.length);
|
|
1450
|
+
case "end":
|
|
1451
|
+
return move(state, state.matches.length);
|
|
1367
1452
|
case "cancel":
|
|
1368
1453
|
return { ...state, done: "cancel" };
|
|
1454
|
+
case "help":
|
|
1455
|
+
return { ...state, help: true };
|
|
1369
1456
|
case "erase":
|
|
1370
1457
|
return withQuery(state, [...state.query].slice(0, -1).join(""));
|
|
1371
1458
|
case "clear":
|
|
@@ -1394,11 +1481,11 @@ function chosen(state) {
|
|
|
1394
1481
|
|
|
1395
1482
|
// ../kit/src/picker/terminal.ts
|
|
1396
1483
|
import { openSync } from "fs";
|
|
1397
|
-
import
|
|
1484
|
+
import process16 from "process";
|
|
1398
1485
|
import tty from "tty";
|
|
1399
1486
|
|
|
1400
1487
|
// ../kit/src/picker/preview.ts
|
|
1401
|
-
import
|
|
1488
|
+
import process15 from "process";
|
|
1402
1489
|
|
|
1403
1490
|
// ../kit/src/shell.ts
|
|
1404
1491
|
var SEPARATORS = new Set([`
|
|
@@ -1467,7 +1554,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1467
1554
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1468
1555
|
const stop = () => {
|
|
1469
1556
|
try {
|
|
1470
|
-
|
|
1557
|
+
process15.kill(-proc.pid, "SIGKILL");
|
|
1471
1558
|
} catch {
|
|
1472
1559
|
proc.kill();
|
|
1473
1560
|
}
|
|
@@ -1545,7 +1632,18 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1545
1632
|
function caretColumn(state, layout) {
|
|
1546
1633
|
return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
|
|
1547
1634
|
}
|
|
1635
|
+
function helpLines(state, layout, theme) {
|
|
1636
|
+
const lines = [
|
|
1637
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1638
|
+
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1639
|
+
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1640
|
+
];
|
|
1641
|
+
const title = "keys, any key closes this help";
|
|
1642
|
+
return [{ text: theme.accent(title), width: title.length }, ...lines.map((line) => fit(` ${line}`, layout.listWidth, theme.label))];
|
|
1643
|
+
}
|
|
1548
1644
|
function listLines(state, layout, theme) {
|
|
1645
|
+
if (state.help)
|
|
1646
|
+
return helpLines(state, layout, theme);
|
|
1549
1647
|
const header = state.header === "" ? [] : state.header.split(`
|
|
1550
1648
|
`).map((line) => fitStyled(line, layout.listWidth, theme.label));
|
|
1551
1649
|
const rows = Math.max(1, layout.listHeight - 2 - header.length);
|
|
@@ -1554,7 +1652,8 @@ function listLines(state, layout, theme) {
|
|
|
1554
1652
|
const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
|
|
1555
1653
|
const promptWidth = Bun.stringWidth(state.prompt);
|
|
1556
1654
|
const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
|
|
1557
|
-
const
|
|
1655
|
+
const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
|
|
1656
|
+
const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks}`, layout.listWidth, theme.label);
|
|
1558
1657
|
const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
|
|
1559
1658
|
if (state.matches.length === 0)
|
|
1560
1659
|
lines.push(fit(" no match", layout.listWidth, theme.label));
|
|
@@ -1581,6 +1680,7 @@ function render(state, layout, theme, preview = []) {
|
|
|
1581
1680
|
|
|
1582
1681
|
// ../kit/src/picker/terminal.ts
|
|
1583
1682
|
var PREVIEW_DELAY_MS = 120;
|
|
1683
|
+
var ESCAPE_WAIT_MS = 30;
|
|
1584
1684
|
var OPEN = { ctrl: "open" };
|
|
1585
1685
|
var HIDE_CURSOR = "\x1B[?25l";
|
|
1586
1686
|
var SHOW_CURSOR = "\x1B[?25h";
|
|
@@ -1592,14 +1692,24 @@ function up(lines) {
|
|
|
1592
1692
|
return lines > 0 ? `\x1B[${lines}A` : "";
|
|
1593
1693
|
}
|
|
1594
1694
|
function openTerminal() {
|
|
1595
|
-
let
|
|
1695
|
+
let mode;
|
|
1596
1696
|
try {
|
|
1597
|
-
|
|
1697
|
+
mode = new tty.ReadStream(openSync("/dev/tty", "r"));
|
|
1598
1698
|
} catch {
|
|
1599
1699
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
1600
1700
|
}
|
|
1601
|
-
const
|
|
1701
|
+
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
1702
|
+
const out = process16.stderr;
|
|
1602
1703
|
let resize;
|
|
1704
|
+
async function read(onChunk) {
|
|
1705
|
+
const decoder = new TextDecoder;
|
|
1706
|
+
try {
|
|
1707
|
+
for (let chunk = await keys.read();!chunk.done; chunk = await keys.read())
|
|
1708
|
+
onChunk(decoder.decode(chunk.value, { stream: true }));
|
|
1709
|
+
} catch {
|
|
1710
|
+
onChunk("\x03");
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1603
1713
|
return {
|
|
1604
1714
|
get columns() {
|
|
1605
1715
|
return out.columns || 80;
|
|
@@ -1611,17 +1721,18 @@ function openTerminal() {
|
|
|
1611
1721
|
write: (text) => void out.write(text),
|
|
1612
1722
|
listen(onChunk, onResize) {
|
|
1613
1723
|
resize = onResize;
|
|
1614
|
-
|
|
1724
|
+
mode.setRawMode(true);
|
|
1615
1725
|
out.on("resize", onResize);
|
|
1616
|
-
|
|
1726
|
+
read(onChunk);
|
|
1617
1727
|
},
|
|
1618
1728
|
close() {
|
|
1619
1729
|
if (resize !== undefined)
|
|
1620
1730
|
out.off("resize", resize);
|
|
1621
1731
|
try {
|
|
1622
|
-
|
|
1732
|
+
mode.setRawMode(false);
|
|
1623
1733
|
} finally {
|
|
1624
|
-
|
|
1734
|
+
mode.destroy();
|
|
1735
|
+
keys.cancel();
|
|
1625
1736
|
}
|
|
1626
1737
|
}
|
|
1627
1738
|
};
|
|
@@ -1636,20 +1747,29 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1636
1747
|
let shownLine;
|
|
1637
1748
|
let finish;
|
|
1638
1749
|
let restored = false;
|
|
1750
|
+
let escape;
|
|
1751
|
+
let caret;
|
|
1639
1752
|
function draw(clear = false) {
|
|
1640
1753
|
if (restored)
|
|
1641
1754
|
return;
|
|
1642
1755
|
const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
|
|
1643
1756
|
let frame = HIDE_CURSOR;
|
|
1644
1757
|
if (reserved !== layout.height || clear) {
|
|
1758
|
+
frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
|
|
1645
1759
|
frame += CLEAR_BELOW + `
|
|
1646
1760
|
`.repeat(layout.height - 1) + up(layout.height - 1);
|
|
1647
1761
|
reserved = layout.height;
|
|
1648
1762
|
}
|
|
1763
|
+
caret = caretColumn(state, layout);
|
|
1649
1764
|
frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
|
|
1650
|
-
`)}${up(layout.height - 1)}\r\x1B[${
|
|
1765
|
+
`)}${up(layout.height - 1)}\r\x1B[${caret}G${SHOW_CURSOR}`;
|
|
1651
1766
|
terminal.write(frame);
|
|
1652
1767
|
}
|
|
1768
|
+
function pageSize() {
|
|
1769
|
+
const headerLines = state.header === "" ? 0 : state.header.split(`
|
|
1770
|
+
`).length;
|
|
1771
|
+
return Math.max(1, layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition).listHeight - 2 - headerLines);
|
|
1772
|
+
}
|
|
1653
1773
|
function refreshPreview() {
|
|
1654
1774
|
const at = highlighted(state);
|
|
1655
1775
|
if (settings.preview === undefined || at === shownLine)
|
|
@@ -1679,6 +1799,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1679
1799
|
return;
|
|
1680
1800
|
restored = true;
|
|
1681
1801
|
clearTimeout(previewTimer);
|
|
1802
|
+
clearTimeout(escape);
|
|
1682
1803
|
previewing.abort();
|
|
1683
1804
|
terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
|
|
1684
1805
|
terminal.close();
|
|
@@ -1717,7 +1838,7 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1717
1838
|
if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
|
|
1718
1839
|
await reloadRows();
|
|
1719
1840
|
else
|
|
1720
|
-
state = press(state, key);
|
|
1841
|
+
state = press({ ...state, page: pageSize() }, key);
|
|
1721
1842
|
}
|
|
1722
1843
|
} finally {
|
|
1723
1844
|
draining = false;
|
|
@@ -1730,6 +1851,20 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1730
1851
|
draw();
|
|
1731
1852
|
}
|
|
1732
1853
|
function onChunk(chunk) {
|
|
1854
|
+
if (escape !== undefined) {
|
|
1855
|
+
clearTimeout(escape);
|
|
1856
|
+
escape = undefined;
|
|
1857
|
+
chunk = `\x1B${chunk}`;
|
|
1858
|
+
} else if (chunk === "\x1B") {
|
|
1859
|
+
escape = setTimeout(() => {
|
|
1860
|
+
escape = undefined;
|
|
1861
|
+
takeKeys("\x1B");
|
|
1862
|
+
}, ESCAPE_WAIT_MS);
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
takeKeys(chunk);
|
|
1866
|
+
}
|
|
1867
|
+
function takeKeys(chunk) {
|
|
1733
1868
|
const keys = parseKeys(chunk, paste, [...settings.expect ?? [], ...reload?.key === undefined ? [] : [reload.key]]);
|
|
1734
1869
|
if (busy && keys.includes("cancel")) {
|
|
1735
1870
|
stop();
|
|
@@ -1741,9 +1876,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1741
1876
|
const ended = new Promise((resolve) => {
|
|
1742
1877
|
finish = resolve;
|
|
1743
1878
|
});
|
|
1744
|
-
|
|
1879
|
+
process16.once("exit", restore);
|
|
1745
1880
|
for (const signal of SIGNALS2)
|
|
1746
|
-
|
|
1881
|
+
process16.once(signal, stop);
|
|
1747
1882
|
try {
|
|
1748
1883
|
terminal.write(PASTE_ON);
|
|
1749
1884
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -1756,8 +1891,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
1756
1891
|
await ended;
|
|
1757
1892
|
} finally {
|
|
1758
1893
|
for (const signal of SIGNALS2)
|
|
1759
|
-
|
|
1760
|
-
|
|
1894
|
+
process16.off(signal, stop);
|
|
1895
|
+
process16.off("exit", restore);
|
|
1761
1896
|
restore();
|
|
1762
1897
|
}
|
|
1763
1898
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2028,7 +2163,7 @@ async function gb(args) {
|
|
|
2028
2163
|
if (parsed.values.json === true)
|
|
2029
2164
|
printJson(all);
|
|
2030
2165
|
else
|
|
2031
|
-
console.log(table(all.map(row)).map((line) => takesControlCodes(
|
|
2166
|
+
console.log(table(all.map(row)).map((line) => takesControlCodes(process17.stdout) ? line : Bun.stripANSI(line)).join(`
|
|
2032
2167
|
`));
|
|
2033
2168
|
return 0;
|
|
2034
2169
|
}
|
|
@@ -2085,4 +2220,4 @@ async function finish(command, typed, emitting) {
|
|
|
2085
2220
|
}
|
|
2086
2221
|
|
|
2087
2222
|
// src/gb.ts
|
|
2088
|
-
|
|
2223
|
+
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;
|
|
@@ -1143,12 +1153,66 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1143
1153
|
}
|
|
1144
1154
|
return code;
|
|
1145
1155
|
}
|
|
1156
|
+
// ../kit/src/folders.ts
|
|
1157
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1146
1158
|
// ../kit/src/secrets.ts
|
|
1147
1159
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1148
1160
|
// ../kit/src/sessions.ts
|
|
1149
1161
|
var {Glob } = globalThis.Bun;
|
|
1150
1162
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1163
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1164
|
+
// ../kit/src/watch.ts
|
|
1165
|
+
import process13 from "process";
|
|
1166
|
+
import { format } from "util";
|
|
1167
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1168
|
+
var DEFAULT_SECONDS = 2;
|
|
1169
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1170
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1171
|
+
function watchOption(what) {
|
|
1172
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1173
|
+
}
|
|
1174
|
+
function withoutWatch(args) {
|
|
1175
|
+
const rest = [];
|
|
1176
|
+
for (let at = 0;at < args.length; at++) {
|
|
1177
|
+
const arg = args[at];
|
|
1178
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1179
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1180
|
+
at++;
|
|
1181
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1182
|
+
rest.push(arg);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return rest;
|
|
1186
|
+
}
|
|
1187
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1188
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1189
|
+
if (!takesControlCodes(stream))
|
|
1190
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1191
|
+
let code = 0;
|
|
1192
|
+
for (let round = 0;round < rounds; round++) {
|
|
1193
|
+
const held = [];
|
|
1194
|
+
const { log, info } = console;
|
|
1195
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1196
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1197
|
+
`);
|
|
1198
|
+
console.log = hold;
|
|
1199
|
+
console.info = hold;
|
|
1200
|
+
process13.stdout.write = (text) => {
|
|
1201
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1202
|
+
return true;
|
|
1203
|
+
};
|
|
1204
|
+
try {
|
|
1205
|
+
code = await step();
|
|
1206
|
+
} finally {
|
|
1207
|
+
console.log = log;
|
|
1208
|
+
console.info = info;
|
|
1209
|
+
process13.stdout.write = write;
|
|
1210
|
+
}
|
|
1211
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1212
|
+
await sleep(interval);
|
|
1213
|
+
}
|
|
1214
|
+
return code;
|
|
1215
|
+
}
|
|
1152
1216
|
// src/git.ts
|
|
1153
1217
|
async function git2(args, env) {
|
|
1154
1218
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -1220,7 +1284,7 @@ var OPTIONS = {
|
|
|
1220
1284
|
};
|
|
1221
1285
|
var RENAME = /^[RC]\d*$/;
|
|
1222
1286
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
1223
|
-
var LITERAL = { ...
|
|
1287
|
+
var LITERAL = { ...process15.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
1224
1288
|
function messageOf(title, lines, tickets) {
|
|
1225
1289
|
return [title, lines.join(`
|
|
1226
1290
|
`), tickets.join(`
|
|
@@ -1318,4 +1382,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
|
|
|
1318
1382
|
signals.release();
|
|
1319
1383
|
}
|
|
1320
1384
|
}
|
|
1321
|
-
|
|
1385
|
+
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;
|
|
@@ -1143,15 +1153,69 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1143
1153
|
}
|
|
1144
1154
|
return code;
|
|
1145
1155
|
}
|
|
1156
|
+
// ../kit/src/folders.ts
|
|
1157
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1146
1158
|
// ../kit/src/secrets.ts
|
|
1147
1159
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1148
1160
|
// ../kit/src/sessions.ts
|
|
1149
1161
|
var {Glob } = globalThis.Bun;
|
|
1150
1162
|
var SESSION_FILES = new Glob("*.json");
|
|
1151
1163
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1164
|
+
// ../kit/src/watch.ts
|
|
1165
|
+
import process13 from "process";
|
|
1166
|
+
import { format } from "util";
|
|
1167
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1168
|
+
var DEFAULT_SECONDS = 2;
|
|
1169
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1170
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1171
|
+
function watchOption(what) {
|
|
1172
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1173
|
+
}
|
|
1174
|
+
function withoutWatch(args) {
|
|
1175
|
+
const rest = [];
|
|
1176
|
+
for (let at = 0;at < args.length; at++) {
|
|
1177
|
+
const arg = args[at];
|
|
1178
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1179
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1180
|
+
at++;
|
|
1181
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1182
|
+
rest.push(arg);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return rest;
|
|
1186
|
+
}
|
|
1187
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1188
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1189
|
+
if (!takesControlCodes(stream))
|
|
1190
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1191
|
+
let code = 0;
|
|
1192
|
+
for (let round = 0;round < rounds; round++) {
|
|
1193
|
+
const held = [];
|
|
1194
|
+
const { log, info } = console;
|
|
1195
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1196
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1197
|
+
`);
|
|
1198
|
+
console.log = hold;
|
|
1199
|
+
console.info = hold;
|
|
1200
|
+
process13.stdout.write = (text) => {
|
|
1201
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1202
|
+
return true;
|
|
1203
|
+
};
|
|
1204
|
+
try {
|
|
1205
|
+
code = await step();
|
|
1206
|
+
} finally {
|
|
1207
|
+
console.log = log;
|
|
1208
|
+
console.info = info;
|
|
1209
|
+
process13.stdout.write = write;
|
|
1210
|
+
}
|
|
1211
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1212
|
+
await sleep(interval);
|
|
1213
|
+
}
|
|
1214
|
+
return code;
|
|
1215
|
+
}
|
|
1152
1216
|
// src/colour.ts
|
|
1153
|
-
import
|
|
1154
|
-
function letter(status, stream =
|
|
1217
|
+
import process15 from "process";
|
|
1218
|
+
function letter(status, stream = process15.stdout) {
|
|
1155
1219
|
const colors = paint(stream);
|
|
1156
1220
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1157
1221
|
return tint(status);
|
|
@@ -1242,10 +1306,11 @@ var USAGE = `gst [--log N]: the repository's branch, upstream, changed files and
|
|
|
1242
1306
|
Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
|
|
1243
1307
|
var OPTIONS = {
|
|
1244
1308
|
log: { type: "string", short: "l", description: "add the last N commits as <sha7> <title>" },
|
|
1309
|
+
watch: watchOption("the status"),
|
|
1245
1310
|
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
|
|
1246
1311
|
};
|
|
1247
1312
|
function group(title, lines) {
|
|
1248
|
-
return lines.length === 0 ? [] : [paint(
|
|
1313
|
+
return lines.length === 0 ? [] : [paint(process16.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1249
1314
|
}
|
|
1250
1315
|
function staged({ index, from, path }) {
|
|
1251
1316
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
@@ -1256,6 +1321,8 @@ async function main(argv) {
|
|
|
1256
1321
|
fail(`gst takes no paths
|
|
1257
1322
|
|
|
1258
1323
|
${USAGE}`);
|
|
1324
|
+
if (parsed.values.watch !== undefined)
|
|
1325
|
+
return watching(parsed.values.watch, async () => main(withoutWatch(argv)));
|
|
1259
1326
|
const count = parsed.values.log === undefined ? 0 : wholeNumber(parsed.values.log, "log", 1);
|
|
1260
1327
|
const [read, head, log] = await Promise.all([
|
|
1261
1328
|
git2(["status", "--porcelain=v2", "--branch"]),
|
|
@@ -1288,12 +1355,12 @@ ${USAGE}`);
|
|
|
1288
1355
|
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1289
1356
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1290
1357
|
...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",
|
|
1358
|
+
...group("untracked", status.untracked.map((file) => paint(process16.stdout).dim(file))),
|
|
1359
|
+
...group("conflicted", status.conflicted.map((file) => paint(process16.stdout).red(file))),
|
|
1360
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process16.stdout)(commitSha)} ${commitTitle}`))
|
|
1294
1361
|
];
|
|
1295
1362
|
console.log(lines.join(`
|
|
1296
1363
|
`));
|
|
1297
1364
|
return 0;
|
|
1298
1365
|
}
|
|
1299
|
-
|
|
1366
|
+
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.1",
|
|
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.27.1"
|
|
48
48
|
}
|
|
49
49
|
}
|