@kaynooo/cli-pick 0.11.3 → 0.11.5

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 +56 -17
  2. package/package.json +3 -3
package/dist/pick.js CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
- // @bun
1
+ #!/bin/sh
2
+ // @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
3
3
  var __esm = (fn, res, err) => () => {
4
4
  if (fn)
5
5
  try {
@@ -116,11 +116,14 @@ var init_config = __esm(() => {
116
116
 
117
117
  // ../kit/src/user-config.ts
118
118
  import { homedir } from "os";
119
- import { join as join2 } from "path";
119
+ import { isAbsolute, join as join2 } from "path";
120
120
  import process4 from "process";
121
+ function xdgFolder(value, fallback) {
122
+ return value !== undefined && isAbsolute(value) ? value : fallback;
123
+ }
121
124
  function configBase(where = {}) {
122
125
  const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
123
- return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
126
+ return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
124
127
  }
125
128
  function userConfigPath(bin, where = {}) {
126
129
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
@@ -1197,6 +1200,11 @@ init_format();
1197
1200
 
1198
1201
  // ../kit/src/progress.ts
1199
1202
  init_format();
1203
+
1204
+ // ../kit/src/process.ts
1205
+ var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
1206
+
1207
+ // ../kit/src/progress.ts
1200
1208
  init_style();
1201
1209
  init_theme();
1202
1210
  var ESC = String.fromCharCode(27);
@@ -1341,14 +1349,16 @@ init_text();
1341
1349
  // ../kit/src/usage.ts
1342
1350
  import { appendFileSync, mkdirSync } from "fs";
1343
1351
  import { homedir as homedir3 } from "os";
1344
- import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1352
+ import { dirname as dirname2, join as join4 } from "path";
1345
1353
  import process13 from "process";
1346
1354
 
1347
1355
  // ../kit/src/logs.ts
1356
+ init_user_config();
1348
1357
  var DAY_MS = 24 * 60 * 60 * 1000;
1349
1358
  var CLI_FOLDER = "kaynooo-cli";
1350
1359
 
1351
1360
  // ../kit/src/usage.ts
1361
+ init_user_config();
1352
1362
  var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
1353
1363
  var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
1354
1364
  var LONGEST_NAME = 40;
@@ -1357,8 +1367,7 @@ function noteUsageError(message) {
1357
1367
  usageError = message;
1358
1368
  }
1359
1369
  function stateHome(env = process13.env) {
1360
- const dir = env.XDG_STATE_HOME;
1361
- return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1370
+ return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
1362
1371
  }
1363
1372
  function usagePath(env = process13.env) {
1364
1373
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
@@ -1561,6 +1570,7 @@ init_style();
1561
1570
  init_text();
1562
1571
  // ../kit/src/secrets.ts
1563
1572
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1573
+ var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
1564
1574
  // ../kit/src/sessions.ts
1565
1575
  var {Glob } = globalThis.Bun;
1566
1576
  var SESSION_FILES = new Glob("*.json");
@@ -1603,6 +1613,7 @@ var COMMENT_PREFIXES = new Set([";", "&", "|", "(", ")"]);
1603
1613
  var SAFE_WORD = /^[\w@%+=:,./-]+$/;
1604
1614
  var DOUBLE_QUOTED_ESCAPES = new Set(["$", "`", '"', "\\"]);
1605
1615
  var KEYWORDS = new Set(["then", "do", "else", "if", "elif", "while", "until", "!", "{", "}"]);
1616
+ var FISH_COMBINERS = new Set(["and", "or", "not"]);
1606
1617
  var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "fish", "csh", "tcsh", "nu", "xonsh", "elvish", "pwsh", "powershell"]);
1607
1618
  var SCANNED_PROGRAMS = new Set(["su", "runuser", "flock"]);
1608
1619
  var COMMAND_STRING_PROGRAMS = new Set([...SHELLS, ...SCANNED_PROGRAMS]);
@@ -1614,6 +1625,7 @@ var FIND_EXEC = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
1614
1625
  function wrapper(short = "", long = [], operands = 0, runsString = false) {
1615
1626
  return { short, long, operands, runsString };
1616
1627
  }
1628
+ var RUNNER = { ...wrapper(), afterDashes: true };
1617
1629
  var WRAPPERS = new Map([
1618
1630
  ["command", wrapper()],
1619
1631
  ["builtin", wrapper()],
@@ -1635,7 +1647,23 @@ var WRAPPERS = new Map([
1635
1647
  ["parallel", wrapper("jnNSaIPlLdTsC", ["--jobs", "--max-args", "--max-replace-args", "--sshlogin", "--arg-file", "--delimiter", "--colsep"], 0, true)],
1636
1648
  ["unbuffer", wrapper()],
1637
1649
  ["systemd-run", wrapper("puEMH", ["--property", "--unit", "--description", "--slice", "--setenv", "--machine", "--host", "--uid", "--gid", "--working-directory", "--nice", "--service-type"])],
1638
- ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])]
1650
+ ["xargs", wrapper("IndsEaPL", ["--max-args", "--max-procs", "--max-chars", "--delimiter", "--arg-file", "--eof", "--max-lines", "--process-slot-var"])],
1651
+ ["strace", wrapper("abeEIoOpPsSuUX", ["--trace", "--output", "--attach", "--string-limit", "--user", "--env", "--columns", "--trace-path", "--signal", "--status", "--summary-sort-by", "--summary-columns", "--const-print-style", "--interruptible", "--detach-on"])],
1652
+ ["ltrace", wrapper("aeFlnopsuxX", ["--output", "--user", "--library", "--config", "--align", "--indent"])],
1653
+ ["taskset", wrapper("", [], 1)],
1654
+ ["fakeroot", wrapper("lsib", ["--lib", "--faked"])],
1655
+ ["sshpass", wrapper("pfdP")],
1656
+ ["coproc", wrapper()],
1657
+ ["proxychains", wrapper("f")],
1658
+ ["proxychains4", wrapper("f")],
1659
+ ["torsocks", wrapper("upaP", ["--user", "--pass", "--address", "--port"])],
1660
+ ["chrt", wrapper("TPD", ["--sched-runtime", "--sched-period", "--sched-deadline"], 1)],
1661
+ ["unshare", wrapper("SGRw", ["--setuid", "--setgid", "--root", "--wd", "--map-user", "--map-group", "--map-users", "--map-groups", "--propagation", "--setgroups"])],
1662
+ ["nsenter", wrapper("tSG", ["--target", "--setuid", "--setgid"])],
1663
+ ["out", RUNNER],
1664
+ ["slot", RUNNER],
1665
+ ["waitfor", RUNNER],
1666
+ ["base", RUNNER]
1639
1667
  ]);
1640
1668
  function shellQuote(word) {
1641
1669
  return SAFE_WORD.test(word) && !word.startsWith("=") ? word : `'${word.replaceAll("'", "'\\''")}'`;
@@ -2109,11 +2137,21 @@ var OPTIONS = {
2109
2137
  height: { type: "string", description: "lines or a percentage of the terminal to draw in (100%)" },
2110
2138
  json: jsonOption("{picked: [lines]}, the choice or the marked lines in input order")
2111
2139
  };
2112
- function print(chosen, json, end) {
2140
+ function print(chosen, lines, raw, json, end) {
2113
2141
  if (json)
2114
- printJson({ picked: chosen });
2142
+ printJson({ picked: chosen.map((index) => lines[index]) });
2115
2143
  else
2116
- process19.stdout.write(chosen.map((line) => line + end).join(""));
2144
+ process19.stdout.write(Buffer.concat(chosen.flatMap((index) => [raw[index], Buffer.from(end)])));
2145
+ }
2146
+ function splitBytes(bytes, separator) {
2147
+ const parts = [];
2148
+ let start = 0;
2149
+ for (let at = bytes.indexOf(separator);at !== -1; at = bytes.indexOf(separator, start)) {
2150
+ parts.push(bytes.subarray(start, at));
2151
+ start = at + 1;
2152
+ }
2153
+ parts.push(bytes.subarray(start));
2154
+ return parts.filter((part) => part.length > 0);
2117
2155
  }
2118
2156
  async function main(args) {
2119
2157
  const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, replaces: "fzf for a quick choice in a pipe, select in a shell script", examples: ["git branch --format='%(refname:short)' | pick", "ls | pick --multi --preview 'head -20 {}'", "git branch | pick --filter main # every match, best first, no terminal", "ps aux | pick --with-nth 2,11.. --nth 11.. # show some fields, search others"] });
@@ -2138,8 +2176,9 @@ async function main(args) {
2138
2176
  } catch {
2139
2177
  badUsage(`--delimiter is a regex, not ${values.delimiter}`);
2140
2178
  }
2141
- const lines = (await Bun.stdin.text()).split(values.read0 === true ? "\x00" : `
2142
- `).filter((line) => line !== "");
2179
+ const raw = splitBytes(await Bun.stdin.bytes(), values.read0 === true ? 0 : 10);
2180
+ const decoder = new TextDecoder;
2181
+ const lines = raw.map((bytes) => decoder.decode(bytes));
2143
2182
  if (lines.length === 0)
2144
2183
  fail("nothing to pick from", 1);
2145
2184
  const query = values.filter ?? values.query ?? "";
@@ -2147,22 +2186,22 @@ async function main(args) {
2147
2186
  `;
2148
2187
  const json = values.json === true;
2149
2188
  const searched = lines.map((line) => nth === undefined ? line : pickFields(line, nth, delimiter));
2150
- const matching = rank(query, searched).map(({ index }) => lines[index]);
2189
+ const matching = rank(query, searched).map(({ index }) => index);
2151
2190
  if (matching.length === 0 && (values["exit-0"] === true || values.filter !== undefined || !process19.stderr.isTTY))
2152
2191
  return 1;
2153
2192
  if (values.filter !== undefined || !process19.stderr.isTTY) {
2154
- print(values.multi === true || values.filter !== undefined ? matching : matching.slice(0, 1), json, end);
2193
+ print(values.multi === true || values.filter !== undefined ? matching : matching.slice(0, 1), lines, raw, json, end);
2155
2194
  return 0;
2156
2195
  }
2157
2196
  if (values["select-1"] === true && matching.length === 1) {
2158
- print(matching, json, end);
2197
+ print(matching, lines, raw, json, end);
2159
2198
  return 0;
2160
2199
  }
2161
2200
  const rows = lines.map((line, index) => ({ hidden: [line], cells: [withNth === undefined ? line : pickFields(line, withNth, delimiter).trimEnd()], ...nth === undefined ? {} : { search: searched[index] } }));
2162
2201
  const picked = await select(rows, { multi: values.multi === true, prompt: values.prompt ?? "> ", query, height, preview: values.preview, header: values.header });
2163
2202
  if (picked === undefined)
2164
2203
  return 130;
2165
- print(picked.rows.map((row) => row.hidden[0]), json, end);
2204
+ print(picked.rows.map((row) => rows.indexOf(row)), lines, raw, json, end);
2166
2205
  return 0;
2167
2206
  }
2168
2207
  process19.exitCode = await runMain({ name: "pick", run: main });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pick",
3
3
  "type": "module",
4
- "version": "0.11.3",
4
+ "version": "0.11.5",
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",
@@ -31,10 +31,10 @@
31
31
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
32
32
  },
33
33
  "scripts": {
34
- "build": "$npm_execpath build src/pick.ts --target bun --outdir dist",
34
+ "build": "$npm_execpath build src/pick.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
35
35
  "pick": "$npm_execpath src/pick.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.46.0"
38
+ "@kaynooo/cli-kit": "0.46.4"
39
39
  }
40
40
  }