@kaynooo/cli-pick 0.11.0 → 0.11.2

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.
Files changed (2) hide show
  1. package/dist/pick.js +81 -2
  2. package/package.json +5 -5
package/dist/pick.js CHANGED
@@ -483,7 +483,7 @@ class Completing {
483
483
  }
484
484
  var completion = { active: false };
485
485
  var OUTPUT_OPTIONS = {
486
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
486
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
487
487
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
488
488
  };
489
489
  function applyOutput(color, plain, env = process9.env) {
@@ -689,6 +689,66 @@ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs
689
689
  import { dirname as dirname3, join as join5 } from "path";
690
690
  import process13 from "process";
691
691
 
692
+ // ../kit/src/completions.ts
693
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
694
+ 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'
695
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
696
+ set -l current (commandline -ct)
697
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
698
+ if test "$line" = __files__
699
+ __fish_complete_path $current
700
+ else
701
+ echo $line
702
+ end
703
+ end
704
+ end`;
705
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
706
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
707
+ local -a lines
708
+ COMPREPLY=()
709
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
710
+ for line in "\${lines[@]}"; do
711
+ if [[ $line == __files__ ]]; then
712
+ COMPREPLY+=($(compgen -f -- "$cur"))
713
+ else
714
+ words+="\${line%%$'\\t'*}"$'\\n'
715
+ fi
716
+ done
717
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
718
+ }`;
719
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
720
+ local line
721
+ local -a described plain
722
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
723
+ if [[ $line == __files__ ]]; then
724
+ _files
725
+ elif [[ $line == *$'\\t'* ]]; then
726
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
727
+ else
728
+ plain+=("$line")
729
+ fi
730
+ done
731
+ (( \${#described} )) && _describe -V value described
732
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
733
+ return 0
734
+ }`;
735
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
736
+ if (shell === "fish")
737
+ return `${header}
738
+ ${FISH_FUNCTION}
739
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
740
+ `).join("")}`;
741
+ if (shell === "bash")
742
+ return `${header}
743
+ ${BASH_FUNCTION}
744
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
745
+ `;
746
+ return `${header}
747
+ ${ZSH_FUNCTION}
748
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
749
+ `;
750
+ }
751
+
692
752
  // ../kit/src/notify.ts
693
753
  import process11 from "process";
694
754
  var NOTIFY_AFTER_MS = 1e4;
@@ -762,7 +822,11 @@ var LEVEL_OPTIONS = {
762
822
  ...OUTPUT_OPTIONS,
763
823
  help: { type: "boolean", short: "h", description: "show this help" }
764
824
  };
765
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
825
+ var TOP_OPTIONS = {
826
+ ...LEVEL_OPTIONS,
827
+ version: { type: "boolean", short: "v", description: "print the version" },
828
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
829
+ };
766
830
  function printError(prefix, message, hint, cause) {
767
831
  const colors = paint(process13.stderr);
768
832
  const styled = takesControlCodes(process13.stderr);
@@ -842,6 +906,19 @@ async function leafCandidates(run, words) {
842
906
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
843
907
  return values === undefined ? [FILES] : values.map(candidateLine);
844
908
  }
909
+ var COMPLETIONS = "--completions";
910
+ function flagValue([flag = "", ...rest]) {
911
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
912
+ }
913
+ function printCompletionScript(name, args) {
914
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
915
+ if (shell === undefined || args.length !== 1) {
916
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
917
+ return 2;
918
+ }
919
+ console.log(completionScript(shell, [name]).trimEnd());
920
+ return 0;
921
+ }
845
922
  async function printCandidates(found) {
846
923
  for (const line of await found)
847
924
  console.log(line);
@@ -865,6 +942,8 @@ function packageVersion(entry = Bun.main) {
865
942
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
866
943
  if (argv[0] === COMPLETE)
867
944
  return printCandidates(leafCandidates(run, argv.slice(1)));
945
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
946
+ return printCompletionScript(name, flagValue(argv));
868
947
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
869
948
  console.log(version ?? packageVersion());
870
949
  return 0;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pick",
3
3
  "type": "module",
4
- "version": "0.11.0",
4
+ "version": "0.11.2",
5
5
  "description": "pick: a themed fuzzy selector, lines on stdin, the chosen one on stdout.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/pick#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/pick#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/pick"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": [
16
16
  "cli",
17
17
  "fuzzy",
@@ -35,6 +35,6 @@
35
35
  "pick": "$npm_execpath src/pick.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.40.0"
38
+ "@kaynooo/cli-kit": "0.41.1"
39
39
  }
40
40
  }