@kaynooo/cli-git 0.18.0 → 0.19.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/gd.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1541,7 +1552,7 @@ var init_prompt = __esm(() => {
1541
1552
  });
1542
1553
 
1543
1554
  // src/gd.ts
1544
- import process24 from "process";
1555
+ import process23 from "process";
1545
1556
 
1546
1557
  // ../kit/src/index.ts
1547
1558
  init_args();
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
@@ -2031,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
2031
2045
  `);
2032
2046
  chmodSync(script, 448);
2033
2047
  return {
2034
- env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2048
+ env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2035
2049
  close: () => {
2036
2050
  server.stop(true);
2037
2051
  rmSync(dir, { recursive: true, force: true });
@@ -2454,22 +2468,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
2454
2468
  }
2455
2469
  // ../kit/src/workspace-root.ts
2456
2470
  init_user_config();
2457
- import { homedir as homedir5 } from "os";
2458
- import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
2459
- import process21 from "process";
2460
- function expandHome(path, home) {
2461
- if (path === "~")
2462
- return home;
2463
- return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
2464
- }
2465
- function configured(env, home) {
2466
- const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
2467
- return typeof folder === "string" && folder !== "" ? folder : undefined;
2468
- }
2469
- function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
2470
- const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
2471
- return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
2472
- }
2473
2471
  // src/git.ts
2474
2472
  async function git2(args, env) {
2475
2473
  const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
@@ -2479,8 +2477,8 @@ async function git2(args, env) {
2479
2477
 
2480
2478
  // src/repos.ts
2481
2479
  import { readdir } from "fs/promises";
2482
- import { join as join10, relative, resolve as resolve5 } from "path";
2483
- import process23 from "process";
2480
+ import { join as join9, relative, resolve as resolve4 } from "path";
2481
+ import process22 from "process";
2484
2482
 
2485
2483
  // src/status.ts
2486
2484
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
@@ -2576,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
2576
2574
  found.push(dir);
2577
2575
  if (left === 0)
2578
2576
  return;
2579
- await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
2577
+ await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join9(dir, entry.name), left - 1)));
2580
2578
  }
2581
- await walk(resolve5(root), depth);
2579
+ await walk(resolve4(root), depth);
2582
2580
  return found.sort();
2583
2581
  }
2584
2582
  async function toplevelOf(dir) {
@@ -2586,14 +2584,14 @@ async function toplevelOf(dir) {
2586
2584
  return read.code === 0 ? read.stdout.trim() : undefined;
2587
2585
  }
2588
2586
  async function reposOf(roots) {
2589
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
2587
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
2590
2588
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
2591
2589
  return [...new Set(found.flat())].sort();
2592
2590
  }
2593
2591
  async function repoState(dir) {
2594
2592
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
2595
2593
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
2596
- return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
2594
+ return { path: relative(process22.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
2597
2595
  }
2598
2596
  function trackingOf(status) {
2599
2597
  if (status.upstream === null)
@@ -2638,9 +2636,10 @@ var OPTIONS = {
2638
2636
  staged: { type: "boolean", short: "s", description: "only what is staged" },
2639
2637
  ref: { type: "string", description: "compare to this commit, branch or tag, or a..b, instead of the index" },
2640
2638
  patch: { type: "boolean", short: "p", description: "print the patch of every file listed, not just of the paths given" },
2639
+ stat: { type: "boolean", description: "list the files with their added and removed lines, the paths given too, never a patch" },
2641
2640
  json: jsonOption("[{title, files: [{path, added, removed}], patch?}] per section, added and removed being null for a binary file, patch there with paths or --patch, the files then those of the paths")
2642
2641
  };
2643
- var LITERAL = { ...process24.env, GIT_LITERAL_PATHSPECS: "1" };
2642
+ var LITERAL = { ...process23.env, GIT_LITERAL_PATHSPECS: "1" };
2644
2643
  var NOT_A_REPOSITORY = /not a git repository/i;
2645
2644
  function parseNumstat(text) {
2646
2645
  const fields = text.split("\x00");
@@ -2672,9 +2671,9 @@ ${ran.stderr.trim()}`, NOT_A_REPOSITORY.test(ran.stderr) ? 2 : 1);
2672
2671
  return ran.stdout;
2673
2672
  }
2674
2673
  async function show(patch) {
2675
- const viewer = process24.stdout.isTTY ? Bun.which("view") : null;
2674
+ const viewer = process23.stdout.isTTY ? Bun.which("view") : null;
2676
2675
  if (viewer === null) {
2677
- process24.stdout.write(patch);
2676
+ process23.stdout.write(patch);
2678
2677
  return;
2679
2678
  }
2680
2679
  const child = Bun.spawn([viewer, "--diff"], { stdin: new TextEncoder().encode(patch), stdout: "inherit", stderr: "inherit" });
@@ -2693,10 +2692,12 @@ async function main(argv) {
2693
2692
  badUsage(`--ref takes a commit, branch or tag, not ${values.ref}`);
2694
2693
  if (values.ref !== undefined && values.staged === true)
2695
2694
  badUsage("--ref and --staged exclude each other: --ref compares the working tree");
2695
+ if (values.stat === true && values.patch === true)
2696
+ badUsage("--stat and --patch exclude each other");
2696
2697
  if (await toplevelOf(".") === undefined)
2697
2698
  fail("not inside a git repository", 2);
2698
2699
  const wanted = sections(values);
2699
- const patched = positionals.length > 0 || values.patch === true;
2700
+ const patched = (positionals.length > 0 || values.patch === true) && values.stat !== true;
2700
2701
  if (values.json === true) {
2701
2702
  printJson(await Promise.all(wanted.map(async ({ title, args }) => ({
2702
2703
  title,
@@ -2710,19 +2711,19 @@ async function main(argv) {
2710
2711
  await show(patches.join(""));
2711
2712
  return 0;
2712
2713
  }
2713
- const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], [])) })));
2714
- const { dim } = paint(process24.stdout);
2715
- const green = role("ok", process24.stdout);
2716
- const red = role("problem", process24.stdout);
2714
+ const found = await Promise.all(wanted.map(async (each) => ({ ...each, files: parseNumstat(await diff([...each.args, "--numstat", "-z"], positionals)) })));
2715
+ const { dim } = paint(process23.stdout);
2716
+ const green = role("ok", process23.stdout);
2717
+ const red = role("problem", process23.stdout);
2717
2718
  const shown = found.filter((each) => each.files.length > 0);
2718
2719
  if (shown.length === 0) {
2719
2720
  console.log(dim("no change in the tracked files"));
2720
2721
  return 0;
2721
2722
  }
2722
2723
  console.log(shown.map((each) => `${each.title}
2723
- ${table(each.files.map((file) => [role("path", process24.stdout)(file.path), file.added === null ? dim("binary") : green(`+${file.added}`), file.removed === null ? "" : red(`-${file.removed}`)]))}`).join(`
2724
+ ${table(each.files.map((file) => [role("path", process23.stdout)(file.path), file.added === null ? dim("binary") : green(`+${file.added}`), file.removed === null ? "" : red(`-${file.removed}`)]))}`).join(`
2724
2725
 
2725
2726
  `));
2726
2727
  return 0;
2727
2728
  }
2728
- process24.exitCode = await runMain({ name: "gd", run: main });
2729
+ process23.exitCode = await runMain({ name: "gd", run: main });
package/dist/gf.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1541,7 +1552,7 @@ var init_prompt = __esm(() => {
1541
1552
  });
1542
1553
 
1543
1554
  // src/gf.ts
1544
- import process24 from "process";
1555
+ import process23 from "process";
1545
1556
 
1546
1557
  // ../kit/src/index.ts
1547
1558
  init_args();
@@ -1971,12 +1982,15 @@ import { join as join6 } from "path";
1971
1982
  import process16 from "process";
1972
1983
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1973
1984
  var ECHOED = /username|yes\/no/i;
1985
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1974
1986
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1975
1987
  function askpass(pause = () => () => {
1976
1988
  return;
1977
1989
  }) {
1978
1990
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1979
- return;
1991
+ return { env: { ...NO_PROMPTS }, close: () => {
1992
+ return;
1993
+ } };
1980
1994
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1981
1995
  const socketPath = join6(dir, "socket");
1982
1996
  const script = join6(dir, "askpass");
@@ -2031,7 +2045,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
2031
2045
  `);
2032
2046
  chmodSync(script, 448);
2033
2047
  return {
2034
- env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2048
+ env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2035
2049
  close: () => {
2036
2050
  server.stop(true);
2037
2051
  rmSync(dir, { recursive: true, force: true });
@@ -2454,26 +2468,10 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
2454
2468
  }
2455
2469
  // ../kit/src/workspace-root.ts
2456
2470
  init_user_config();
2457
- import { homedir as homedir5 } from "os";
2458
- import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
2459
- import process21 from "process";
2460
- function expandHome(path, home) {
2461
- if (path === "~")
2462
- return home;
2463
- return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
2464
- }
2465
- function configured(env, home) {
2466
- const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
2467
- return typeof folder === "string" && folder !== "" ? folder : undefined;
2468
- }
2469
- function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
2470
- const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
2471
- return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
2472
- }
2473
2471
  // src/repos.ts
2474
2472
  import { readdir } from "fs/promises";
2475
- import { join as join10, relative, resolve as resolve5 } from "path";
2476
- import process23 from "process";
2473
+ import { join as join9, relative, resolve as resolve4 } from "path";
2474
+ import process22 from "process";
2477
2475
 
2478
2476
  // src/git.ts
2479
2477
  async function git2(args, env) {
@@ -2576,9 +2574,9 @@ async function reposUnder(root, depth = DEPTH) {
2576
2574
  found.push(dir);
2577
2575
  if (left === 0)
2578
2576
  return;
2579
- await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
2577
+ await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join9(dir, entry.name), left - 1)));
2580
2578
  }
2581
- await walk(resolve5(root), depth);
2579
+ await walk(resolve4(root), depth);
2582
2580
  return found.sort();
2583
2581
  }
2584
2582
  async function toplevelOf(dir) {
@@ -2586,14 +2584,14 @@ async function toplevelOf(dir) {
2586
2584
  return read.code === 0 ? read.stdout.trim() : undefined;
2587
2585
  }
2588
2586
  async function reposOf(roots) {
2589
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
2587
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process22.cwd()];
2590
2588
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
2591
2589
  return [...new Set(found.flat())].sort();
2592
2590
  }
2593
2591
  async function repoState(dir) {
2594
2592
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
2595
2593
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
2596
- return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
2594
+ return { path: relative(process22.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
2597
2595
  }
2598
2596
  function trackingOf(status) {
2599
2597
  if (status.upstream === null)
@@ -2695,16 +2693,16 @@ var OPTIONS = {
2695
2693
  json: jsonOption("one {path, branch, upstream, commits, outcome, reason?} per repository, outcome being updated, current, fetched, skipped or refused")
2696
2694
  };
2697
2695
  function line(result) {
2698
- const { dim } = paint(process24.stdout);
2696
+ const { dim } = paint(process23.stdout);
2699
2697
  const count = `${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
2700
2698
  const said = {
2701
- updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`, process24.stdout),
2699
+ updated: () => marked("ok", `${result.branch} <- ${result.upstream}, ${count}`, process23.stdout),
2702
2700
  current: () => dim(`${result.branch} up to date`),
2703
2701
  fetched: () => `${result.branch} is ${result.commits} behind ${result.upstream}`,
2704
2702
  skipped: () => dim(`${result.branch ?? ""} ${result.reason ?? "skipped"}`.trim()),
2705
- refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process24.stdout)
2703
+ refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process23.stdout)
2706
2704
  }[result.outcome];
2707
- return [role("path", process24.stdout)(result.path), said()];
2705
+ return [role("path", process23.stdout)(result.path), said()];
2708
2706
  }
2709
2707
  async function main(argv) {
2710
2708
  const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], exits: EXITS, replaces: "git fetch --prune, git pull --ff-only and a git -C <repo> pull per nested repository", examples: ["gf", ["gf --repos", "every repository nested in this one"], ["gf --no-pull", "fetch and say how far behind the branch is"]] });
@@ -2712,14 +2710,14 @@ async function main(argv) {
2712
2710
  const results = [];
2713
2711
  const progress = progressLine();
2714
2712
  const prompts = askpass(progress.pause);
2715
- const env = prompts === undefined ? undefined : { ...process24.env, ...prompts.env };
2713
+ const env = { ...process23.env, ...prompts.env };
2716
2714
  try {
2717
2715
  for (const [at, repo] of repos.entries()) {
2718
2716
  progress.update(repos.length > 1 ? { step: `fetching ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `fetching ${repo.path}` });
2719
2717
  results.push(await sync(repo, { pull: values["no-pull"] !== true, env }));
2720
2718
  }
2721
2719
  } finally {
2722
- prompts?.close();
2720
+ prompts.close();
2723
2721
  progress.stop();
2724
2722
  }
2725
2723
  if (values.json === true)
@@ -2728,4 +2726,4 @@ async function main(argv) {
2728
2726
  console.log(table(results.map(line)));
2729
2727
  return results.some((result) => result.outcome === "refused") ? 1 : 0;
2730
2728
  }
2731
- process24.exitCode = await runMain({ name: "gf", run: main });
2729
+ process23.exitCode = await runMain({ name: "gf", run: main });
package/dist/gm.js CHANGED
@@ -652,21 +652,32 @@ function wholeNumber(value, name, fallback, min = 1) {
652
652
  badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
653
653
  return number;
654
654
  }
655
+ function durationMs(text, unit) {
656
+ if (BARE_DURATION.test(text))
657
+ return Number(text) * UNIT_MS[unit];
658
+ if (!DURATION.test(text))
659
+ return 0;
660
+ let ms = 0;
661
+ for (const [, amount, part] of text.matchAll(DURATION_PART))
662
+ ms += Number(amount) * UNIT_MS[part];
663
+ return ms;
664
+ }
655
665
  function duration(value, name, fallback, unit = "s") {
656
666
  if (value === undefined)
657
667
  return fallback;
658
- const match = DURATION.exec(value.trim());
659
- const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
668
+ const ms = durationMs(value.trim(), unit);
660
669
  if (ms < 1)
661
670
  badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
662
671
  return ms;
663
672
  }
664
- var WHOLE, DURATION, UNIT_MS;
673
+ var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
665
674
  var init_input = __esm(() => {
666
675
  init_args();
667
676
  WHOLE = /^\d+$/;
668
- DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
669
- UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
677
+ BARE_DURATION = /^\d+(?:\.\d+)?$/;
678
+ DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
679
+ DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
680
+ UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
670
681
  });
671
682
 
672
683
  // ../kit/src/args.ts
@@ -1542,8 +1553,8 @@ var init_prompt = __esm(() => {
1542
1553
 
1543
1554
  // src/gm.ts
1544
1555
  import { readFileSync as readFileSync7 } from "fs";
1545
- import { join as join10, relative } from "path";
1546
- import process26 from "process";
1556
+ import { join as join9, relative } from "path";
1557
+ import process25 from "process";
1547
1558
 
1548
1559
  // ../kit/src/index.ts
1549
1560
  init_args();
@@ -1973,12 +1984,15 @@ import { join as join6 } from "path";
1973
1984
  import process16 from "process";
1974
1985
  var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
1975
1986
  var ECHOED = /username|yes\/no/i;
1987
+ var NO_PROMPTS = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "", SSH_ASKPASS: "", SSH_ASKPASS_REQUIRE: "never" };
1976
1988
  var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
1977
1989
  function askpass(pause = () => () => {
1978
1990
  return;
1979
1991
  }) {
1980
1992
  if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
1981
- return;
1993
+ return { env: { ...NO_PROMPTS }, close: () => {
1994
+ return;
1995
+ } };
1982
1996
  const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
1983
1997
  const socketPath = join6(dir, "socket");
1984
1998
  const script = join6(dir, "askpass");
@@ -2033,7 +2047,7 @@ ${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no
2033
2047
  `);
2034
2048
  chmodSync(script, 448);
2035
2049
  return {
2036
- env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2050
+ env: { GIT_ASKPASS: script, GIT_TERMINAL_PROMPT: "0", SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
2037
2051
  close: () => {
2038
2052
  server.stop(true);
2039
2053
  rmSync(dir, { recursive: true, force: true });
@@ -2456,22 +2470,6 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
2456
2470
  }
2457
2471
  // ../kit/src/workspace-root.ts
2458
2472
  init_user_config();
2459
- import { homedir as homedir5 } from "os";
2460
- import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
2461
- import process21 from "process";
2462
- function expandHome(path, home) {
2463
- if (path === "~")
2464
- return home;
2465
- return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
2466
- }
2467
- function configured(env, home) {
2468
- const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
2469
- return typeof folder === "string" && folder !== "" ? folder : undefined;
2470
- }
2471
- function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
2472
- const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
2473
- return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
2474
- }
2475
2473
  // ../kit/src/picker.ts
2476
2474
  init_folders();
2477
2475
  init_state();
@@ -2482,11 +2480,11 @@ init_job();
2482
2480
  init_redraw();
2483
2481
  init_style();
2484
2482
  import { openSync } from "fs";
2485
- import process24 from "process";
2483
+ import process23 from "process";
2486
2484
  import tty from "tty";
2487
2485
 
2488
2486
  // ../kit/src/picker/preview.ts
2489
- import process23 from "process";
2487
+ import process22 from "process";
2490
2488
 
2491
2489
  // ../kit/src/shell.ts
2492
2490
  var SEPARATORS = new Set([`
@@ -2573,7 +2571,7 @@ async function runPreview(template, line, signal, hidden = []) {
2573
2571
  ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
2574
2572
  const stop = () => {
2575
2573
  try {
2576
- process23.kill(-proc.pid, "SIGKILL");
2574
+ process22.kill(-proc.pid, "SIGKILL");
2577
2575
  } catch {
2578
2576
  proc.kill();
2579
2577
  }
@@ -2736,7 +2734,7 @@ function openTerminal() {
2736
2734
  return fail("no terminal to read keys from (/dev/tty)");
2737
2735
  }
2738
2736
  const keys = Bun.file("/dev/tty").stream().getReader();
2739
- const out = process24.stderr;
2737
+ const out = process23.stderr;
2740
2738
  let resize;
2741
2739
  async function read(onChunk) {
2742
2740
  const decoder = new TextDecoder;
@@ -2925,9 +2923,9 @@ async function select(rows, settings, terminal = openTerminal()) {
2925
2923
  const ended = new Promise((resolve) => {
2926
2924
  finish = resolve;
2927
2925
  });
2928
- process24.once("exit", restore);
2926
+ process23.once("exit", restore);
2929
2927
  for (const signal of SIGNALS2)
2930
- process24.once(signal, stop);
2928
+ process23.once(signal, stop);
2931
2929
  try {
2932
2930
  terminal.write(`${PASTE_ON}${MOUSE_ON}`);
2933
2931
  terminal.listen(onChunk, () => draw(true));
@@ -2940,8 +2938,8 @@ async function select(rows, settings, terminal = openTerminal()) {
2940
2938
  await ended;
2941
2939
  } finally {
2942
2940
  for (const signal of SIGNALS2)
2943
- process24.off(signal, stop);
2944
- process24.off("exit", restore);
2941
+ process23.off(signal, stop);
2942
+ process23.off("exit", restore);
2945
2943
  restore();
2946
2944
  }
2947
2945
  return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
@@ -2991,7 +2989,7 @@ function list(rows) {
2991
2989
 
2992
2990
  // src/branch.ts
2993
2991
  import { basename } from "path";
2994
- import process25 from "process";
2992
+ import process24 from "process";
2995
2993
  var usage2 = `gb [branch]: picks a git branch and switches to it
2996
2994
  gb -
2997
2995
  gb -c <name>
@@ -3216,7 +3214,7 @@ async function gb(args) {
3216
3214
  if (parsed.values.json === true)
3217
3215
  printJson(all);
3218
3216
  else
3219
- console.log(table2(all.map(row)).map((line) => takesControlCodes(process25.stdout) ? line : Bun.stripANSI(line)).join(`
3217
+ console.log(table2(all.map(row)).map((line) => takesControlCodes(process24.stdout) ? line : Bun.stripANSI(line)).join(`
3220
3218
  `));
3221
3219
  return 0;
3222
3220
  }
@@ -3320,7 +3318,7 @@ var OPTIONS = {
3320
3318
  };
3321
3319
  var NOT_A_REPOSITORY = /not a git repository/i;
3322
3320
  var RENAME = /^[RC]\d*$/;
3323
- var EDITOR_OFF = { ...process26.env, GIT_EDITOR: "true", GIT_MERGE_AUTOEDIT: "no" };
3321
+ var EDITOR_OFF = { ...process25.env, GIT_EDITOR: "true", GIT_MERGE_AUTOEDIT: "no" };
3324
3322
  var BINARY_PROBE = 8000;
3325
3323
  var SYMLINK_MODE = "120000";
3326
3324
  async function ran(args, env) {
@@ -3361,7 +3359,7 @@ async function isMarkable(path, bytes, stages) {
3361
3359
  async function conflicted() {
3362
3360
  const top = (await ran(["rev-parse", "--show-toplevel"])).trim();
3363
3361
  return Promise.all([...await unmergedStages()].map(async ([fromTop, stages]) => {
3364
- const path = relative(process26.cwd(), join10(top, fromTop));
3362
+ const path = relative(process25.cwd(), join9(top, fromTop));
3365
3363
  let bytes;
3366
3364
  try {
3367
3365
  bytes = readFileSync7(path);
@@ -3373,7 +3371,7 @@ async function conflicted() {
3373
3371
  }));
3374
3372
  }
3375
3373
  function conflictLines(conflicts) {
3376
- return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path", process26.stdout)(path)}: conflicted, no markers to show (deleted on a side, binary or a mode change)`] : hunks.flatMap((hunk) => [role("path", process26.stdout)(`${path}:${hunk.from}-${hunk.to}`), ...hunk.lines.map(({ line, text }) => `${line} ${text}`), ""]));
3374
+ return conflicts.flatMap(({ path, hunks }) => hunks.length === 0 ? [`${role("path", process25.stdout)(path)}: conflicted, no markers to show (deleted on a side, binary or a mode change)`] : hunks.flatMap((hunk) => [role("path", process25.stdout)(`${path}:${hunk.from}-${hunk.to}`), ...hunk.lines.map(({ line, text }) => `${line} ${text}`), ""]));
3377
3375
  }
3378
3376
  function fileLine(line) {
3379
3377
  const [letter = "", from = "", to] = line.split("\t");
@@ -3391,7 +3389,7 @@ function conflictReport(branch, into, conflicts, json, squash = false) {
3391
3389
  printJson({ outcome: "conflict", branch, into, conflicts: conflicts.map(({ path, hunks }) => ({ path, hunks })) });
3392
3390
  return 1;
3393
3391
  }
3394
- console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`, process26.stdout), ...conflictLines(conflicts)].join(`
3392
+ console.log([marked("problem", `merging ${branch} into ${into} left ${conflicts.length} conflicted ${conflicts.length === 1 ? "file" : "files"}`, process25.stdout), ...conflictLines(conflicts)].join(`
3395
3393
  `).trimEnd());
3396
3394
  console.log(squash ? `
3397
3395
  resolve the files and commit them with gc, or git reset --merge to give up` : `
@@ -3412,7 +3410,7 @@ async function mergedReport(before, branch, into, json) {
3412
3410
  const how = outcome === "merge" ? `merge commit ${sha.slice(0, 7)}` : "fast-forward";
3413
3411
  const list = changed.split(`
3414
3412
  `).filter(Boolean);
3415
- console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`, process26.stdout), ...list.map(fileLine)].join(`
3413
+ console.log([marked("ok", `${into} <- ${branch}, ${how}, ${count}, ${list.length} ${list.length === 1 ? "file" : "files"} changed`, process25.stdout), ...list.map(fileLine)].join(`
3416
3414
  `));
3417
3415
  return 0;
3418
3416
  }
@@ -3427,7 +3425,7 @@ ${(stderr || stdout).trim()}`);
3427
3425
  `);
3428
3426
  return { outcome: code === 0 ? "clean" : "conflict", conflicts: [...new Set(rest.slice(0, Math.max(0, rest.indexOf(""))))] };
3429
3427
  }
3430
- function verdictText(verdict, tint = paint(process26.stdout)) {
3428
+ function verdictText(verdict, tint = paint(process25.stdout)) {
3431
3429
  if (verdict.outcome === "up-to-date")
3432
3430
  return tint.dim("merged already");
3433
3431
  return verdict.outcome === "clean" ? tint.green("clean") : tint.red(`conflicts: ${verdict.conflicts.join(", ")}`);
@@ -3441,7 +3439,7 @@ async function squashedReport(before, branch, into, json) {
3441
3439
  }
3442
3440
  const list = changed.split(`
3443
3441
  `).filter(Boolean);
3444
- console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`, process26.stdout), ...list.map(fileLine)].join(`
3442
+ console.log([marked("ok", `${branch} squashed into the index of ${into}: ${commits} ${commits === 1 ? "commit" : "commits"}, ${list.length} ${list.length === 1 ? "file" : "files"}, commit them with gc`, process25.stdout), ...list.map(fileLine)].join(`
3445
3443
  `));
3446
3444
  return 0;
3447
3445
  }
@@ -3455,9 +3453,9 @@ async function dryRun(branch, into, json) {
3455
3453
  if (verdict.outcome === "up-to-date")
3456
3454
  console.log(`${branch} is already merged into ${into}`);
3457
3455
  else if (verdict.outcome === "clean")
3458
- console.log(marked("ok", `merging ${branch} into ${into} would not conflict`, process26.stdout));
3456
+ console.log(marked("ok", `merging ${branch} into ${into} would not conflict`, process25.stdout));
3459
3457
  else
3460
- console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`, process26.stdout), ...verdict.conflicts.map((path) => ` ${path}`)].join(`
3458
+ console.log([marked("problem", `merging ${branch} into ${into} would conflict in ${verdict.conflicts.length} ${verdict.conflicts.length === 1 ? "file" : "files"}`, process25.stdout), ...verdict.conflicts.map((path) => ` ${path}`)].join(`
3461
3459
  `));
3462
3460
  return code;
3463
3461
  }
@@ -3532,7 +3530,7 @@ async function main(argv) {
3532
3530
  if (json)
3533
3531
  printJson({ outcome: "refused", into, conflicts: [...left, ...unpicked].map(({ path, hunks }) => ({ path, hunks })) });
3534
3532
  else
3535
- console.log([...problems.map((problem) => marked("problem", problem, process26.stdout)), ...conflictLines([...left, ...unpicked])].join(`
3533
+ console.log([...problems.map((problem) => marked("problem", problem, process25.stdout)), ...conflictLines([...left, ...unpicked])].join(`
3536
3534
  `).trimEnd());
3537
3535
  return 1;
3538
3536
  }
@@ -3588,4 +3586,4 @@ ${USAGE}`);
3588
3586
  return fail(`git merge failed:
3589
3587
  ${(merged.stderr || merged.stdout).trim()}`, NOT_A_REPOSITORY.test(merged.stderr) ? 2 : 1);
3590
3588
  }
3591
- process26.exitCode = await runMain({ name: "gm", run: main });
3589
+ process25.exitCode = await runMain({ name: "gm", run: main });