@kaynooo/cli-git 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ Prints one line with the branch, its upstream and how far ahead and behind it is
53
53
 
54
54
  ## gm
55
55
 
56
- `gm <branch>` merges the branch into the current one with `git merge --no-edit` and prints what came in: fast-forward or merge commit, the commits and the files changed. A working tree with uncommitted changes is refused.
56
+ `gm <branch>` merges the branch into the current one with `git merge --no-edit` and prints what came in: fast-forward or merge commit, the commits and the files changed. Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are, through a conflict and gm --abort too.
57
57
 
58
58
  - On a conflict every conflicted file is listed with its conflict regions (the markers and two lines around them, line numbers included) and the exit is 1; `gm --continue` commits once the markers are gone, refusing while one remains, and `gm --abort` gives the merge up.
59
59
  - `gm --dry-run <branch>` says whether the merge would conflict, and in which files, with `git merge-tree` and nothing touched.
package/dist/gb.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gc.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gcl.js CHANGED
@@ -645,7 +645,7 @@ class Completing {
645
645
  }
646
646
  var completion = { active: false };
647
647
  var OUTPUT_OPTIONS = {
648
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
648
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
649
649
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
650
650
  };
651
651
  function applyOutput(color, plain, env = process9.env) {
@@ -1155,6 +1155,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1155
1155
  import { dirname as dirname3, join as join5 } from "path";
1156
1156
  import process15 from "process";
1157
1157
 
1158
+ // ../kit/src/completions.ts
1159
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1160
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1161
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1162
+ set -l current (commandline -ct)
1163
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1164
+ if test "$line" = __files__
1165
+ __fish_complete_path $current
1166
+ else
1167
+ echo $line
1168
+ end
1169
+ end
1170
+ end`;
1171
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1172
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1173
+ local -a lines
1174
+ COMPREPLY=()
1175
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1176
+ for line in "\${lines[@]}"; do
1177
+ if [[ $line == __files__ ]]; then
1178
+ COMPREPLY+=($(compgen -f -- "$cur"))
1179
+ else
1180
+ words+="\${line%%$'\\t'*}"$'\\n'
1181
+ fi
1182
+ done
1183
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1184
+ }`;
1185
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1186
+ local line
1187
+ local -a described plain
1188
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1189
+ if [[ $line == __files__ ]]; then
1190
+ _files
1191
+ elif [[ $line == *$'\\t'* ]]; then
1192
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1193
+ else
1194
+ plain+=("$line")
1195
+ fi
1196
+ done
1197
+ (( \${#described} )) && _describe -V value described
1198
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1199
+ return 0
1200
+ }`;
1201
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1202
+ if (shell === "fish")
1203
+ return `${header}
1204
+ ${FISH_FUNCTION}
1205
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1206
+ `).join("")}`;
1207
+ if (shell === "bash")
1208
+ return `${header}
1209
+ ${BASH_FUNCTION}
1210
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1211
+ `;
1212
+ return `${header}
1213
+ ${ZSH_FUNCTION}
1214
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1215
+ `;
1216
+ }
1217
+
1158
1218
  // ../kit/src/notify.ts
1159
1219
  import process13 from "process";
1160
1220
  var NOTIFY_AFTER_MS = 1e4;
@@ -1228,7 +1288,11 @@ var LEVEL_OPTIONS = {
1228
1288
  ...OUTPUT_OPTIONS,
1229
1289
  help: { type: "boolean", short: "h", description: "show this help" }
1230
1290
  };
1231
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1291
+ var TOP_OPTIONS = {
1292
+ ...LEVEL_OPTIONS,
1293
+ version: { type: "boolean", short: "v", description: "print the version" },
1294
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1295
+ };
1232
1296
  function printError(prefix, message, hint, cause) {
1233
1297
  const colors = paint(process15.stderr);
1234
1298
  const styled = takesControlCodes(process15.stderr);
@@ -1311,6 +1375,19 @@ async function leafCandidates(run, words) {
1311
1375
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1312
1376
  return values === undefined ? [FILES] : values.map(candidateLine);
1313
1377
  }
1378
+ var COMPLETIONS = "--completions";
1379
+ function flagValue([flag = "", ...rest]) {
1380
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1381
+ }
1382
+ function printCompletionScript(name, args) {
1383
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1384
+ if (shell === undefined || args.length !== 1) {
1385
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1386
+ return 2;
1387
+ }
1388
+ console.log(completionScript(shell, [name]).trimEnd());
1389
+ return 0;
1390
+ }
1314
1391
  async function printCandidates(found) {
1315
1392
  for (const line of await found)
1316
1393
  console.log(line);
@@ -1334,6 +1411,8 @@ function packageVersion(entry = Bun.main) {
1334
1411
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1335
1412
  if (argv[0] === COMPLETE)
1336
1413
  return printCandidates(leafCandidates(run, argv.slice(1)));
1414
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1415
+ return printCompletionScript(name, flagValue(argv));
1337
1416
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1338
1417
  console.log(version ?? packageVersion());
1339
1418
  return 0;
package/dist/gd.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gf.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gm.js CHANGED
@@ -643,7 +643,7 @@ class Completing {
643
643
  }
644
644
  var completion = { active: false };
645
645
  var OUTPUT_OPTIONS = {
646
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
646
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
647
647
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
648
648
  };
649
649
  function applyOutput(color, plain, env = process9.env) {
@@ -1153,6 +1153,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1153
1153
  import { dirname as dirname3, join as join5 } from "path";
1154
1154
  import process15 from "process";
1155
1155
 
1156
+ // ../kit/src/completions.ts
1157
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1158
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1159
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1160
+ set -l current (commandline -ct)
1161
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1162
+ if test "$line" = __files__
1163
+ __fish_complete_path $current
1164
+ else
1165
+ echo $line
1166
+ end
1167
+ end
1168
+ end`;
1169
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1170
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1171
+ local -a lines
1172
+ COMPREPLY=()
1173
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1174
+ for line in "\${lines[@]}"; do
1175
+ if [[ $line == __files__ ]]; then
1176
+ COMPREPLY+=($(compgen -f -- "$cur"))
1177
+ else
1178
+ words+="\${line%%$'\\t'*}"$'\\n'
1179
+ fi
1180
+ done
1181
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1182
+ }`;
1183
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1184
+ local line
1185
+ local -a described plain
1186
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1187
+ if [[ $line == __files__ ]]; then
1188
+ _files
1189
+ elif [[ $line == *$'\\t'* ]]; then
1190
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1191
+ else
1192
+ plain+=("$line")
1193
+ fi
1194
+ done
1195
+ (( \${#described} )) && _describe -V value described
1196
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1197
+ return 0
1198
+ }`;
1199
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1200
+ if (shell === "fish")
1201
+ return `${header}
1202
+ ${FISH_FUNCTION}
1203
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1204
+ `).join("")}`;
1205
+ if (shell === "bash")
1206
+ return `${header}
1207
+ ${BASH_FUNCTION}
1208
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1209
+ `;
1210
+ return `${header}
1211
+ ${ZSH_FUNCTION}
1212
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1213
+ `;
1214
+ }
1215
+
1156
1216
  // ../kit/src/notify.ts
1157
1217
  import process13 from "process";
1158
1218
  var NOTIFY_AFTER_MS = 1e4;
@@ -1226,7 +1286,11 @@ var LEVEL_OPTIONS = {
1226
1286
  ...OUTPUT_OPTIONS,
1227
1287
  help: { type: "boolean", short: "h", description: "show this help" }
1228
1288
  };
1229
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1289
+ var TOP_OPTIONS = {
1290
+ ...LEVEL_OPTIONS,
1291
+ version: { type: "boolean", short: "v", description: "print the version" },
1292
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1293
+ };
1230
1294
  function printError(prefix, message, hint, cause) {
1231
1295
  const colors = paint(process15.stderr);
1232
1296
  const styled = takesControlCodes(process15.stderr);
@@ -1309,6 +1373,19 @@ async function leafCandidates(run, words) {
1309
1373
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1310
1374
  return values === undefined ? [FILES] : values.map(candidateLine);
1311
1375
  }
1376
+ var COMPLETIONS = "--completions";
1377
+ function flagValue([flag = "", ...rest]) {
1378
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1379
+ }
1380
+ function printCompletionScript(name, args) {
1381
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1382
+ if (shell === undefined || args.length !== 1) {
1383
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1384
+ return 2;
1385
+ }
1386
+ console.log(completionScript(shell, [name]).trimEnd());
1387
+ return 0;
1388
+ }
1312
1389
  async function printCandidates(found) {
1313
1390
  for (const line of await found)
1314
1391
  console.log(line);
@@ -1332,6 +1409,8 @@ function packageVersion(entry = Bun.main) {
1332
1409
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1333
1410
  if (argv[0] === COMPLETE)
1334
1411
  return printCandidates(leafCandidates(run, argv.slice(1)));
1412
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1413
+ return printCompletionScript(name, flagValue(argv));
1335
1414
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1336
1415
  console.log(version ?? packageVersion());
1337
1416
  return 0;
@@ -2645,7 +2724,7 @@ var USAGE = `gm [branch]: merges the branch into the current one with git merge
2645
2724
  Without a branch, on a terminal, picks one: every branch but the current one with how far it is ahead of and behind it, a preview of what the merge would do (the commits coming in, the files they touch, whether it would conflict and where), enter to merge and ctrl-s to merge with --squash. Without a terminal it lists the branches with that verdict each, clean, conflicts with the files, or merged already. A merge in progress is refused here: gm --continue or gm --abort.
2646
2725
  --squash stages the changes of the branch without committing them or recording a merge, to commit with gc; a conflict then leaves the files to resolve and git reset --merge to give up.
2647
2726
 
2648
- A working tree with uncommitted changes is refused. The output names the outcome (fast-forward, merge commit or already up to date), the commits and the files that came in. On a conflict every conflicted file is listed with its conflict regions (the <<<<<<<, ======= and >>>>>>> lines and two lines around them, line numbers included) and the exit is 1.
2727
+ Staged changes are refused, and so are unstaged ones in files the merge changes; other unstaged edits stay as they are, through a conflict and gm --abort too. The output names the outcome (fast-forward, merge commit or already up to date), the commits and the files that came in. On a conflict every conflicted file is listed with its conflict regions (the <<<<<<<, ======= and >>>>>>> lines and two lines around them, line numbers included) and the exit is 1.
2649
2728
  gm --dry-run <branch> says whether the merge would conflict and in which files, touching nothing (git merge-tree). gm --continue commits the merge once the markers are gone from the conflicted files, refusing while one remains; gm --abort gives the merge up.`;
2650
2729
  var EXITS2 = [[0, "it merged, the branch was already merged, or --dry-run found no conflict"], [1, "a conflict, a dirty tree, an unknown branch, a refused step or git failed"], [2, "outside a git repository or a usage error"]];
2651
2730
  var OPTIONS = {
@@ -2804,6 +2883,19 @@ async function choose2(into) {
2804
2883
  enter merge, ctrl-s merge --squash`, expect: ["ctrl-s"], searched: 1, preview: async (hidden) => preview2(hidden[0] ?? "") });
2805
2884
  return picked === undefined || picked.hidden[0] === undefined ? undefined : { branch: picked.hidden[0], squash: picked.key === "ctrl-s" };
2806
2885
  }
2886
+ async function refuseUnsafeChanges(branch) {
2887
+ const paths = async (args) => (await ran([...args, "--name-only", "-z"])).split("\x00").filter((path) => path !== "");
2888
+ const staged = await paths(["diff", "--cached"]);
2889
+ if (staged.length > 0)
2890
+ fail(`staged changes would go into the merge (${staged.join(", ")}): commit them first (gc), or unstage them (gu --staged)`, 1);
2891
+ const dirty = await paths(["diff"]);
2892
+ if (dirty.length === 0)
2893
+ return;
2894
+ const touched = new Set(await paths(["diff", "--no-renames", `HEAD...${branch}`]));
2895
+ const overlap = dirty.filter((path) => touched.has(path));
2896
+ if (overlap.length > 0)
2897
+ fail(`uncommitted changes in files the merge changes (${overlap.join(", ")}): commit them first (gc), or set them aside as a patch (gu)`, 1);
2898
+ }
2807
2899
  async function main(argv) {
2808
2900
  const { values, positionals } = parse(argv, USAGE, OPTIONS, { positionals: ["[branch]"], exits: EXITS2, replaces: "git merge and then git diff --name-only --diff-filter=U and reading each file for markers", examples: ["gm feature", ["gm --dry-run feature", "whether it would conflict, and where"], ["gm --continue", "commit once the conflicts are resolved"], ["gm --abort", "give the merge up"]] });
2809
2901
  const json = values.json === true;
@@ -2864,8 +2956,7 @@ ${USAGE}`);
2864
2956
  return dryRun(branch, into, json);
2865
2957
  if (await merging())
2866
2958
  fail("a merge is already in progress: gm --continue once the conflicts are resolved, or gm --abort", 1);
2867
- if ((await ran(["status", "--porcelain", "--untracked-files=no"])).trim() !== "")
2868
- fail("the working tree has uncommitted changes, commit or stash them first (gc, git stash)", 1);
2959
+ await refuseUnsafeChanges(branch);
2869
2960
  if (await succeeds(["merge-base", "--is-ancestor", branch, "HEAD"])) {
2870
2961
  if (json)
2871
2962
  printJson({ outcome: "up-to-date", branch, into });
package/dist/gp.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gst.js CHANGED
@@ -642,7 +642,7 @@ class Completing {
642
642
  }
643
643
  var completion = { active: false };
644
644
  var OUTPUT_OPTIONS = {
645
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
645
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
646
646
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
647
647
  };
648
648
  function applyOutput(color, plain, env = process9.env) {
@@ -1152,6 +1152,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1152
1152
  import { dirname as dirname3, join as join5 } from "path";
1153
1153
  import process15 from "process";
1154
1154
 
1155
+ // ../kit/src/completions.ts
1156
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1157
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1158
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1159
+ set -l current (commandline -ct)
1160
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1161
+ if test "$line" = __files__
1162
+ __fish_complete_path $current
1163
+ else
1164
+ echo $line
1165
+ end
1166
+ end
1167
+ end`;
1168
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1169
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1170
+ local -a lines
1171
+ COMPREPLY=()
1172
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1173
+ for line in "\${lines[@]}"; do
1174
+ if [[ $line == __files__ ]]; then
1175
+ COMPREPLY+=($(compgen -f -- "$cur"))
1176
+ else
1177
+ words+="\${line%%$'\\t'*}"$'\\n'
1178
+ fi
1179
+ done
1180
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1181
+ }`;
1182
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1183
+ local line
1184
+ local -a described plain
1185
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1186
+ if [[ $line == __files__ ]]; then
1187
+ _files
1188
+ elif [[ $line == *$'\\t'* ]]; then
1189
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1190
+ else
1191
+ plain+=("$line")
1192
+ fi
1193
+ done
1194
+ (( \${#described} )) && _describe -V value described
1195
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1196
+ return 0
1197
+ }`;
1198
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1199
+ if (shell === "fish")
1200
+ return `${header}
1201
+ ${FISH_FUNCTION}
1202
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1203
+ `).join("")}`;
1204
+ if (shell === "bash")
1205
+ return `${header}
1206
+ ${BASH_FUNCTION}
1207
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1208
+ `;
1209
+ return `${header}
1210
+ ${ZSH_FUNCTION}
1211
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1212
+ `;
1213
+ }
1214
+
1155
1215
  // ../kit/src/notify.ts
1156
1216
  import process13 from "process";
1157
1217
  var NOTIFY_AFTER_MS = 1e4;
@@ -1225,7 +1285,11 @@ var LEVEL_OPTIONS = {
1225
1285
  ...OUTPUT_OPTIONS,
1226
1286
  help: { type: "boolean", short: "h", description: "show this help" }
1227
1287
  };
1228
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1288
+ var TOP_OPTIONS = {
1289
+ ...LEVEL_OPTIONS,
1290
+ version: { type: "boolean", short: "v", description: "print the version" },
1291
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1292
+ };
1229
1293
  function printError(prefix, message, hint, cause) {
1230
1294
  const colors = paint(process15.stderr);
1231
1295
  const styled = takesControlCodes(process15.stderr);
@@ -1308,6 +1372,19 @@ async function leafCandidates(run, words) {
1308
1372
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1309
1373
  return values === undefined ? [FILES] : values.map(candidateLine);
1310
1374
  }
1375
+ var COMPLETIONS = "--completions";
1376
+ function flagValue([flag = "", ...rest]) {
1377
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1378
+ }
1379
+ function printCompletionScript(name, args) {
1380
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1381
+ if (shell === undefined || args.length !== 1) {
1382
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1383
+ return 2;
1384
+ }
1385
+ console.log(completionScript(shell, [name]).trimEnd());
1386
+ return 0;
1387
+ }
1311
1388
  async function printCandidates(found) {
1312
1389
  for (const line of await found)
1313
1390
  console.log(line);
@@ -1331,6 +1408,8 @@ function packageVersion(entry = Bun.main) {
1331
1408
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1332
1409
  if (argv[0] === COMPLETE)
1333
1410
  return printCandidates(leafCandidates(run, argv.slice(1)));
1411
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1412
+ return printCompletionScript(name, flagValue(argv));
1334
1413
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1335
1414
  console.log(version ?? packageVersion());
1336
1415
  return 0;
package/dist/gu.js CHANGED
@@ -644,7 +644,7 @@ class Completing {
644
644
  }
645
645
  var completion = { active: false };
646
646
  var OUTPUT_OPTIONS = {
647
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
647
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
648
648
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
649
649
  };
650
650
  function applyOutput(color, plain, env = process9.env) {
@@ -1154,6 +1154,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
1154
1154
  import { dirname as dirname3, join as join5 } from "path";
1155
1155
  import process15 from "process";
1156
1156
 
1157
+ // ../kit/src/completions.ts
1158
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1159
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1160
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1161
+ set -l current (commandline -ct)
1162
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1163
+ if test "$line" = __files__
1164
+ __fish_complete_path $current
1165
+ else
1166
+ echo $line
1167
+ end
1168
+ end
1169
+ end`;
1170
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1171
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1172
+ local -a lines
1173
+ COMPREPLY=()
1174
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1175
+ for line in "\${lines[@]}"; do
1176
+ if [[ $line == __files__ ]]; then
1177
+ COMPREPLY+=($(compgen -f -- "$cur"))
1178
+ else
1179
+ words+="\${line%%$'\\t'*}"$'\\n'
1180
+ fi
1181
+ done
1182
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1183
+ }`;
1184
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1185
+ local line
1186
+ local -a described plain
1187
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1188
+ if [[ $line == __files__ ]]; then
1189
+ _files
1190
+ elif [[ $line == *$'\\t'* ]]; then
1191
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1192
+ else
1193
+ plain+=("$line")
1194
+ fi
1195
+ done
1196
+ (( \${#described} )) && _describe -V value described
1197
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1198
+ return 0
1199
+ }`;
1200
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1201
+ if (shell === "fish")
1202
+ return `${header}
1203
+ ${FISH_FUNCTION}
1204
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1205
+ `).join("")}`;
1206
+ if (shell === "bash")
1207
+ return `${header}
1208
+ ${BASH_FUNCTION}
1209
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1210
+ `;
1211
+ return `${header}
1212
+ ${ZSH_FUNCTION}
1213
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1214
+ `;
1215
+ }
1216
+
1157
1217
  // ../kit/src/notify.ts
1158
1218
  import process13 from "process";
1159
1219
  var NOTIFY_AFTER_MS = 1e4;
@@ -1227,7 +1287,11 @@ var LEVEL_OPTIONS = {
1227
1287
  ...OUTPUT_OPTIONS,
1228
1288
  help: { type: "boolean", short: "h", description: "show this help" }
1229
1289
  };
1230
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1290
+ var TOP_OPTIONS = {
1291
+ ...LEVEL_OPTIONS,
1292
+ version: { type: "boolean", short: "v", description: "print the version" },
1293
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1294
+ };
1231
1295
  function printError(prefix, message, hint, cause) {
1232
1296
  const colors = paint(process15.stderr);
1233
1297
  const styled = takesControlCodes(process15.stderr);
@@ -1310,6 +1374,19 @@ async function leafCandidates(run, words) {
1310
1374
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1311
1375
  return values === undefined ? [FILES] : values.map(candidateLine);
1312
1376
  }
1377
+ var COMPLETIONS = "--completions";
1378
+ function flagValue([flag = "", ...rest]) {
1379
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1380
+ }
1381
+ function printCompletionScript(name, args) {
1382
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1383
+ if (shell === undefined || args.length !== 1) {
1384
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1385
+ return 2;
1386
+ }
1387
+ console.log(completionScript(shell, [name]).trimEnd());
1388
+ return 0;
1389
+ }
1313
1390
  async function printCandidates(found) {
1314
1391
  for (const line of await found)
1315
1392
  console.log(line);
@@ -1333,6 +1410,8 @@ function packageVersion(entry = Bun.main) {
1333
1410
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1334
1411
  if (argv[0] === COMPLETE)
1335
1412
  return printCandidates(leafCandidates(run, argv.slice(1)));
1413
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1414
+ return printCompletionScript(name, flagValue(argv));
1336
1415
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1337
1416
  console.log(version ?? packageVersion());
1338
1417
  return 0;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.16.0",
4
+ "version": "0.17.0",
5
5
  "description": "gst, gc, gb, gp, gf, gm, gcl, gd and gu: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, nested repositories pushed or fetched, a branch merged with its conflicts listed, a clone into the workspace, the changes per file and an undo that keeps what it takes away.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/git#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/git#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://git.kaynooo.fr/kaynooo/cli.git",
11
+ "url": "git+https://github.com/Kayno0o/cli.git",
12
12
  "directory": "packages/git"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": [
16
16
  "claude-code",
17
17
  "cli",
@@ -56,6 +56,6 @@
56
56
  "gu": "$npm_execpath src/gu.ts"
57
57
  },
58
58
  "devDependencies": {
59
- "@kaynooo/cli-kit": "0.39.0"
59
+ "@kaynooo/cli-kit": "0.41.0"
60
60
  }
61
61
  }