@kaynooo/cli-git 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gb.js 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;
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.16.0",
4
+ "version": "0.16.1",
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",
@@ -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
  }