@politty/zod 0.1.1 → 0.2.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 +31 -0
- package/dist/{arg-registry-B8QvBM_Q.d.ts → arg-registry-Be4GJADw.d.ts} +15 -1
- package/dist/augment.d.ts +1 -1
- package/dist/augment.js +1 -1
- package/dist/cli-main-C8D_mKfv.js +2 -0
- package/dist/cli-main-ClQaGXB3.js +1 -0
- package/dist/cli-run-BFXIag27.js +1 -0
- package/dist/cli.js +1 -15
- package/dist/command-Mbdt0bmN.js +1 -0
- package/dist/compile-cache-VuUbFWIo.js +1 -0
- package/dist/compile-cache.js +1 -3
- package/dist/completion-D8DMrPqg.js +116 -0
- package/dist/completion-DUMcvXkT.js +1 -0
- package/dist/completion.d.ts +87 -7
- package/dist/completion.js +1 -4
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +84 -3045
- package/dist/dynamic-CMtee4tD.js +1 -0
- package/dist/dynamic-CrnlveHj.js +6 -0
- package/dist/field-meta-COGya7xp.js +1 -0
- package/dist/index.d.ts +20 -16
- package/dist/index.js +1 -27
- package/dist/log-collector-hiFa3sNm.js +1 -0
- package/dist/logger-CJsyJ8sb.js +1 -0
- package/dist/prompt-CqmGq1_N.js +1 -0
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -32
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -47
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -4
- package/dist/register-C1WbbeYH.js +1 -0
- package/dist/runner-C_wCXh6X.js +1 -0
- package/dist/runner-uPmkI9Gb.js +29 -0
- package/dist/schema-BiUP_KyV.js +1 -0
- package/dist/schema-extractor-DU0Vuhbd.js +1 -0
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +2 -1835
- package/dist/subcommand-router-D8GTMXYL.js +1 -0
- package/dist/with-completion-command-DDohm8U6.js +3 -0
- package/dist/{index-CMb2xLiJ.d.ts → with-completion-command-xaVZtAga.d.ts} +3 -74
- package/package.json +3 -3
- package/dist/cli-main-BQfutJEX.js +0 -3
- package/dist/cli-main-D4kkrRfX.js +0 -314
- package/dist/cli-run-wxd6kPPf.js +0 -8
- package/dist/command-k-4yAz4J.js +0 -42
- package/dist/compile-cache-BC65o7MH.js +0 -103
- package/dist/completion-DW5qVc3l.js +0 -5613
- package/dist/field-meta-DMy5BcRr.js +0 -146
- package/dist/log-collector-CoUkLVJB.js +0 -114
- package/dist/logger-i_bb-Jhc.js +0 -133
- package/dist/prompt-BjIZThsH.js +0 -169
- package/dist/register-DlGnMLIY.js +0 -440
- package/dist/runner-DAGvxV2P.js +0 -2980
- package/dist/runner-MMjpKeEa.js +0 -3
- package/dist/schema-extractor-DMSozq40.js +0 -250
- package/dist/src-CLogLsbS.js +0 -12
- package/dist/src-bYH2XCQ4.js +0 -6
- package/dist/subcommand-router-Cskpofdk.js +0 -134
package/README.md
CHANGED
|
@@ -62,6 +62,37 @@ runMain(command);
|
|
|
62
62
|
|
|
63
63
|
Field descriptions can also come from valibot's own metadata actions. They are actions, not schemas, so they belong inside `v.pipe(...)`: `v.pipe(v.string(), v.description("..."))` or `v.pipe(v.string(), v.metadata({ description: "..." }))`. The one zod-only feature without a valibot counterpart is the `politty/augment` module (zod `GlobalMeta` interface augmentation) — use `arg()` or `v.metadata()` instead. The `politty` package itself remains the zod flavor (an alias of `@politty/zod`).
|
|
64
64
|
|
|
65
|
+
### Using zod/mini instead of zod
|
|
66
|
+
|
|
67
|
+
politty is also available as [`@politty/zod-mini`](https://www.npmjs.com/package/@politty/zod-mini), built on [`zod/mini`](https://zod.dev/) — the same `zod` package's minimal, function-style entry point instead of its chainable classic API — for a smaller bundle. Same API (`defineCommand`, `arg`, `runMain`, and all subpath modules):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install @politty/zod-mini zod
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import * as z from "zod/mini";
|
|
75
|
+
import { defineCommand, runMain, arg } from "@politty/zod-mini";
|
|
76
|
+
|
|
77
|
+
const command = defineCommand({
|
|
78
|
+
name: "greet",
|
|
79
|
+
args: z.object({
|
|
80
|
+
name: arg(z.string(), { description: "Name to greet", positional: true }),
|
|
81
|
+
loud: arg(z._default(z.boolean(), false), { alias: "l" }),
|
|
82
|
+
}),
|
|
83
|
+
run: (args) => {
|
|
84
|
+
const greeting = `Hello, ${args.name}!`;
|
|
85
|
+
console.log(args.loud ? greeting.toUpperCase() : greeting);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
runMain(command);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`zod/mini` drops classic zod's chainable sugar (`.optional()`, `.default()`, `.describe()`, `.meta()`), so schemas are built with functions instead (`z.optional(z.string())`, `z._default(z.string(), "x")`). Field descriptions come from `arg()` or from zod's own metadata registry: `schema.register(z.globalRegistry, { description: "..." })`. The `politty/augment` module (classic zod's `GlobalMeta` interface augmentation) has no `@politty/zod-mini` counterpart for the same reason it has none for valibot — use `arg()` or the registry instead.
|
|
93
|
+
|
|
94
|
+
You can write your schemas against either `import * as z from "zod/mini"` or [`import * as z from "@zod/mini"`](https://zod.dev/packages/mini) — `@zod/mini` re-exports `zod/mini` (same classes, same `globalRegistry`), so schemas built either way are fully interchangeable. Per zod's own installation instructions, install `@zod/mini` alongside `zod` (`npm install zod @zod/mini`), not instead of it — `@zod/mini` only re-exports `zod/mini` from a peer dependency on `zod`, so `zod` still needs to be resolvable in your project either way.
|
|
95
|
+
|
|
65
96
|
## Quick Start
|
|
66
97
|
|
|
67
98
|
```typescript
|
|
@@ -247,6 +247,20 @@ type IsEmpty<T> = keyof T extends never ? true : false;
|
|
|
247
247
|
* resolved by a `prompt` handler)
|
|
248
248
|
*/
|
|
249
249
|
type ArgSource = "cli" | "env" | "default";
|
|
250
|
+
/**
|
|
251
|
+
* Identifies the CLI name a command was invoked with in the current run.
|
|
252
|
+
* - `name`: the literal token typed on the CLI to reach this command
|
|
253
|
+
* (a canonical subcommand name or one of its `aliases`).
|
|
254
|
+
* - `aliasFor`: set only when `name` is an alias, to the canonical
|
|
255
|
+
* subcommand name it resolves to; `undefined` when invoked by its
|
|
256
|
+
* canonical name (or run directly, with no subcommand routing involved).
|
|
257
|
+
*/
|
|
258
|
+
interface RunInvocation {
|
|
259
|
+
/** The name or alias actually typed on the CLI to reach this command */
|
|
260
|
+
name: string;
|
|
261
|
+
/** Canonical name `name` is an alias for; undefined when not an alias */
|
|
262
|
+
aliasFor?: string | undefined;
|
|
263
|
+
}
|
|
250
264
|
/**
|
|
251
265
|
* Example definition for a command
|
|
252
266
|
*/
|
|
@@ -1022,4 +1036,4 @@ interface ArgFn<TSchemaBase extends SchemaLike = SchemaLike> {
|
|
|
1022
1036
|
<T extends TSchemaBase, M extends ArgMeta<InferSchemaOutput<T>>>(schema: T, meta: ValidateArgMeta<M, InferSchemaOutput<T>>): T;
|
|
1023
1037
|
}
|
|
1024
1038
|
//#endregion
|
|
1025
|
-
export {
|
|
1039
|
+
export { toCamelCase as $, LogEntry as A, RunResultFailure as B, Command as C, GlobalCleanupContext as D, GlobalArgs as E, NonRunnableCommand as F, SubCommandsRecord as G, RunnableCommand as H, PromptResolver as I, isLazyCommand as J, UnknownSubcommandHandler as K, RunCommandOptions as L, LogStream as M, Logger as N, GlobalSetupContext as O, MainOptions as P, UnknownKeysMode as Q, RunInvocation as R, CollectedLogs as S, Example as T, SetupContext as U, RunResultSuccess as V, SubCommandValue as W, ExtractedFields as X, lazy as Y, ResolvedFieldMeta as Z, DynamicCompletionResult as _, CustomCompletion as a, ArgsSchema as b, PromptType as c, ExpandCompletion as d, toKebabCase as et, ResolvedExpandCandidate as f, DynamicCompletionResolver as g, DynamicCompletionContext as h, CompletionType as i, LogLevel as j, IsEmpty as k, ValidateArgMeta as l, DynamicCompletionCandidate as m, ArgMeta as n, SchemaLike as nt, EffectContext as o, CompletionDirectiveMask as p, LazyCommand as q, CompletionMeta as r, PromptMeta as s, ArgFn as t, InferSchemaOutput as tt, ExpandCandidate as u, AnyCommand as v, CommandBase as w, CleanupContext as x, ArgSource as y, RunResult as z };
|
package/dist/augment.d.ts
CHANGED
package/dist/augment.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as e,i as t}from"./schema-extractor-DU0Vuhbd.js";import{n}from"./command-Mbdt0bmN.js";import{n as r}from"./runner-uPmkI9Gb.js";import{chmodSync as i,existsSync as a,mkdirSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{basename as l,dirname as u,extname as d,isAbsolute as f,join as p,relative as m,resolve as h}from"node:path";import{fileURLToPath as g}from"node:url";const _=`Generated by politty: compile-cache bin shim`,v=[`./cli.js`,`./cli.mjs`,`./index.js`,`./index.mjs`];function y(e){let t=h(e);for(;;){let e=p(t,`package.json`);if(a(e))return{pkg:JSON.parse(s(e,`utf8`)),dir:t};let n=u(t);if(n===t)return;t=n}}function b(e){if(!e)return[];if(typeof e.bin==`string`&&e.bin){let t=x(e);return t?[[t,e.bin]]:[]}return typeof e.bin==`object`&&e.bin!==null?Object.entries(e.bin).filter(e=>typeof e[1]==`string`&&e[1]!==``):[]}function x(e){if(e){if(typeof e.bin==`object`&&e.bin!==null){let[t]=Object.keys(e.bin);if(t)return t}if(typeof e.name==`string`&&e.name){let t=e.name;return t.startsWith(`@`)?t.split(`/`)[1]??t:t}}}function S(e){let t=u(e),n=l(e);for(let e of v)if(l(e)!==n&&a(p(t,e)))return e}function C(e,t,n){return[`#!/usr/bin/env node`,``,`// ${_}.`,`// Enables the Node.js on-disk compile cache (V8 code cache) before the`,`// CLI module graph is compiled, so warm starts skip recompilation`,`// (Node >= 22.8.0; silent no-op otherwise).`,`try {`,` const { enableCompileCache } = await import(${JSON.stringify(n)});`,` enableCompileCache(${JSON.stringify(e)});`,`} catch {`,` // ${n} is not resolvable from here (e.g. a fully`,` // bundled CLI) — start without the compile cache rather than failing`,` // the CLI.`,`}`,`await import(${JSON.stringify(t)});`,``].join(`
|
|
2
|
+
`)}function w(e){return e===void 0?[]:Array.isArray(e)?e:[e]}function T(e){return(t={})=>E(`${e}/compile-cache`,t)}function E(e,t){let n=t.cwd??process.cwd(),r=y(n),l=r?.pkg,p=w(t.entry),m=w(t.out),T=b(l),E;if(m.length>0){if(p.length>0&&p.length!==m.length)throw Error(`--entry count (${p.length}) does not match --out count (${m.length}); pass one --out per --entry or omit --out entirely.`);E=m.map(e=>f(e)?e:h(n,e))}else{if(T.length===0||r===void 0)throw Error(`Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.`);if(p.length>0&&p.length!==T.length)throw Error(`--entry count (${p.length}) does not match the package's bin entries (${T.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);E=T.map(([,e])=>h(r.dir,e))}if(new Set(E).size!==E.length)throw Error(`Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).`);let O=new Map;if(r)for(let[e,t]of T)O.set(h(r.dir,t),e);let k=[],A=t.compileCacheSpecifier??e;if(/[\r\n\u2028\u2029]/.test(A))throw Error(`Invalid compile-cache specifier ${JSON.stringify(A)}: a module specifier cannot contain a line terminator.`);let j=E.map((e,r)=>{let i=O.get(e),o=t.program??i??x(l);if(!o)throw Error(`Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.`);if(t.program===void 0&&i===void 0&&m.length>0&&k.push(`Warning: ${D(e,n)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(o)}. Pass --program to override.`),e.endsWith(`.cjs`))throw Error(`The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a "type": "module" package) output path.`);if(d(e)===``)throw Error(`The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a "type": "module" package) output path.`);if(e.endsWith(`.js`)&&l?.type!==`module`)throw Error(l===void 0?`The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`:`The generated shim is an ES module, but the package is not "type": "module". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).`);let c=p[r]??S(e);if(c===void 0)throw Error(`Cannot derive an entry: none of ${v.join(`, `)} exist next to ${e}. Pass --entry explicitly.`);if(!c.startsWith(`./`)&&!c.startsWith(`../`)&&!c.startsWith(`file:`))throw Error(`Invalid entry ${c}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);let f;if(c.startsWith(`file:`))try{f=g(c)}catch{f=void 0}else f=h(u(e),c);if(f===e)throw Error(`The shim at ${e} would import itself (entry ${c}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);if(a(e)&&!s(e,`utf8`).includes(_))throw Error(`Refusing to overwrite ${e}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);return{outputPath:e,program:o,entry:c,compileCacheSpecifier:A}});for(let e of k)console.warn(e);for(let{outputPath:e,program:t,entry:n}of j)o(u(e),{recursive:!0}),c(e,C(t,n,A)),i(e,493);return j}function D(e,t){let n=m(t,e);return n&&!n.startsWith(`..`)?n:e}const O=t({bin:e.string({description:`CLI binary or built JS entry file to invoke`,placeholder:`PATH`}),program:e.string({description:`Program name embedded in worker metadata`,placeholder:`NAME`}),shell:e.enum([`bash`,`zsh`,`fish`],{description:`Shell worker to generate`,placeholder:`SHELL`}),out:e.optionalString({description:`Output worker path (defaults to dist/completion/<shell>-worker.<ext>)`,placeholder:`PATH`}),verify:e.boolean({description:`Verify __completion-worker-path resolves to the generated worker`})}),k=n({name:`generate-worker`,description:`Generate and verify a bundled shell completion worker`,args:O,async run(e){let{generateBundledCompletionWorker:t}=await import(`./completion-DUMcvXkT.js`);await t({bin:e.bin,programName:e.program,shell:e.shell,...e.out!==void 0&&{outputPath:e.out},verify:e.verify})}}),A=t({entry:e.optionalStringArray({description:`Module specifier the shim imports, relative to the shim file; repeatable, one per bin/--out (defaults to ./cli.js, ./cli.mjs, ./index.js, or ./index.mjs next to each shim)`,placeholder:`SPECIFIER`}),out:e.optionalStringArray({description:`Output path for the generated shim; repeatable, one per --entry (defaults to the bin paths in package.json)`,placeholder:`PATH`}),program:e.optionalString({description:`Program name for the cache directory, applied to all shims (defaults per shim to its bin name)`,placeholder:`NAME`}),compileCacheSpecifier:e.optionalString({description:`Module specifier the shim imports enableCompileCache from (defaults to the compile-cache subpath of the politty package running this command)`,placeholder:`SPECIFIER`})});function j(e){let t=T(e),i=n({name:`generate-shim`,description:`Generate a compile-cache bin shim that loads the real CLI via dynamic import`,args:A,run(e){let n=process.cwd(),r=t({...e.entry!==void 0&&{entry:e.entry},...e.out!==void 0&&{out:e.out},...e.program!==void 0&&{program:e.program},...e.compileCacheSpecifier!==void 0&&{compileCacheSpecifier:e.compileCacheSpecifier},cwd:n});for(let e of r)console.log(`Generated compile-cache shim: ${D(e.outputPath,n)} (program: ${e.program}, entry: ${e.entry}, compile-cache: ${e.compileCacheSpecifier})`)}}),a=n({name:`politty`,description:`politty development utilities`,subCommands:{"generate-shim":i,"generate-worker":k}});return r(a).catch(e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)})}export{T as n,j as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./cli-main-C8D_mKfv.js";export{e as runPolittyCli};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./register-C1WbbeYH.js";const{runPolittyCli:e}=await import(`./cli-main-ClQaGXB3.js`);await e(`@politty/zod`);export{};
|
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
//#region src/cli.ts
|
|
5
|
-
/**
|
|
6
|
-
* Bin shim: enable the on-disk V8 compile cache before the real CLI graph
|
|
7
|
-
* is compiled, so warm starts skip recompilation (Node >= 22.8.0; no-op
|
|
8
|
-
* otherwise). The actual CLI lives in `cli-run.ts` and is loaded via
|
|
9
|
-
* dynamic import — ESM static imports are compiled during the link phase,
|
|
10
|
-
* before any code runs, so they could never hit a cache enabled here.
|
|
11
|
-
*/
|
|
12
|
-
enableCompileCache("politty");
|
|
13
|
-
await import("./cli-run-wxd6kPPf.js");
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { };
|
|
2
|
+
import{n as e}from"./compile-cache-VuUbFWIo.js";e(`politty`),await import(`./cli-run-BFXIag27.js`);export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return{name:e.name,description:e.description,aliases:e.aliases,args:e.args,subCommands:e.subCommands,setup:e.setup,run:e.run,cleanup:e.cleanup,notes:e.notes,examples:e.examples}}function t(){return e}export{e as n,t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"node:module";import{join as t}from"node:path";import{homedir as n}from"node:os";function r(e){let t=e.replace(/^@/,``).replace(/[/\\]+/g,`-`).trim();if(!(!t||/^[.-]+$/.test(t)))return t}function i(e){let i=r(e);if(i===void 0)return;let a=process.env.XDG_CACHE_HOME;if(a)return t(a,i,`node-compile-cache`);try{let e=n();return e?t(e,`.cache`,i,`node-compile-cache`):void 0}catch{return}}function a(t){let n=typeof t==`string`?{programName:t}:t??{};try{let t=e.enableCompileCache;if(typeof t!=`function`)return{enabled:!1};let r;process.env.NODE_COMPILE_CACHE||(r=n.cacheDir??(n.programName===void 0?void 0:i(n.programName)));let a=r===void 0?t():t(r),o=e.constants?.compileCacheStatus;return{enabled:o===void 0?a.status===0||a.status===1:a.status===o.ENABLED||a.status===o.ALREADY_ENABLED,...a.directory!==void 0&&{directory:a.directory}}}catch{return{enabled:!1}}}export{a as n,i as t};
|
package/dist/compile-cache.js
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import{t as e}from"./schema-extractor-DU0Vuhbd.js";import{n as t}from"./command-Mbdt0bmN.js";import{c as n}from"./subcommand-router-D8GTMXYL.js";import{a as r,i,n as a,o,r as s,s as c}from"./with-completion-command-DDohm8U6.js";import{c as l,d as u,f as d,g as f,h as p,i as m,l as h,m as g,p as _,s as v,t as y,u as ee}from"./dynamic-CrnlveHj.js";import{existsSync as b,mkdirSync as x,readFileSync as S,realpathSync as C,renameSync as te,rmSync as ne,statSync as w,writeFileSync as re}from"node:fs";import{dirname as T,extname as ie,isAbsolute as ae,join as E,relative as oe,resolve as se}from"node:path";import{promisify as ce}from"node:util";import{execFile as le}from"node:child_process";function ue(e,t,n=[],r=!1){if(t.length===0)return;let i=de(e,n);for(let e of t)e.set(fe(e,i,r))}function de(e,t){let n=new Map,r=new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function fe(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of me(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=pe(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function pe(e){let t=[],n=new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*me(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function he(e,t,n,r){let i=v(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function D(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function O(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function k(e,t,n){return`__${e}_expand_${t}__${D(n)}`}function ge(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${O(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function A(e){return e.filter(e=>!e.name.startsWith(`__`))}function j(e){let t=[];for(let n of A(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function _e(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return he(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function ve(t){return t.args?e(t.args).fields.filter(e=>e.positional):[]}function ye(e,t){return e.filter(e=>!e.positional).map(e=>_e(e,t))}function be(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return he(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function xe(t,r,i=[],a=!1){let o=[];if(r.subCommands)for(let[e,t]of Object.entries(r.subCommands)){let r=n(t);r?o.push(xe(e,r,i,a)):o.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let s=[],c=r.args?e(r.args).fields:[],l={name:t,description:r.description,aliases:r.aliases,subcommands:o,options:ye(c,s),positionals:be(c,s)};return ue(l,s,i,a),l}function M(e,t,n){return e?`${e}${n}${t}`:t}function Se(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>M(e,t,`:`)))}function Ce(e,t){let n=[],r=A(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?h(i.cliName,i.alias):P(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of A(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...Ce(r,M(t,e,`:`)));return n}function we(e,t){return Ce(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function N(e,t=``,n=``){let r=[];for(let i of A(e.subcommands)){let e=M(n,D(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=M(t,n,`:`);r.push(...N(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function Te(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Ee(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function De(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${D(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Oe(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${De(r,t)} ;;`)}return n}function ke(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${De(r,t)} ;;`)}return n}function Ae(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=D(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function P(e,t){let n=h(e.cliName,e.alias);if(e.isGlobal===!0){let e=new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of u(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ee(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function je(e){let t=[];return Me(e,[],[``],[],`root`,t),t}function Me(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?P(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of A(e.subcommands))Me(o,[...t,o.name],Se(n,o),[...r,...n],i===`root`?D(o.name):`${i}_${D(o.name)}`,a)}function Ne(e,t,n=[]){let r=Pe(e),i=new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of u(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=h(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);if(i>=0){a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);continue}let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:P(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of A(e.subcommands))n(t,Se(r,t))};return n(e,[``]),t}function F(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(F(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function I(t,n,r,i=!1){let a=[];if(r){let t=[];a=ye(e(r).fields,t).map(e=>(e.isGlobal=!0,e)),ue({name:n,subcommands:[],options:a,positionals:[]},t,[],i)}let o=xe(n,t,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:n,globalOptions:a}}function L(e){try{return Math.floor(w(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=E(n,e);try{if(w(t).isFile())return t}catch{}}return null}function R(e,t){return t||process.env[O(D(e))]||(Le(e)??process.argv[1]??``)}function z(e){let t=R(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${L(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=R(t,n),o=L(a),s=p(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=`_${t}`,o=R(t,n),s=L(o),c=p(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=k(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=D(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${D(r.fieldName)}:-}`:`\${_used_field_keys_${D(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function B(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...d(o,e,t)});if(s.length===0)continue;let c=P(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function V(e,t,n,r=[]){if(e.length===0)return[];let i=[];i.push(` case "$_pos_count" in`);for(let a of e){a.variadic?i.push(` ${a.position}|*)`):i.push(` ${a.position})`);for(let o of He(a.valueCompletion,!1,t,{funcSuffix:n,..._(a,r,e)}))i.push(` ${o}`);i.push(` ;;`)}return i.push(` esac`),i}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...V(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` __${t}_not_used "--help" && _avail+=(--help)`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...V(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=j(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...V(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=A(s.subcommands),u=je(s),d=Ne(s,u,r.globalOptions),f=[];f.push(...z({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&f.push(`# politty-completion-worker: true`),f.push(`# Generated by politty`),f.push(``),o||f.push(...Re({programName:n,binPath:t.binPath}));let p=u.length>0,h=u.filter(e=>e.isArrayOption),g=h.length>0;p&&(f.push(`__${a}_enc() {`),f.push(` local LC_ALL=C`),f.push(` local _s=$1 _r='' _c _i`),f.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),f.push(" _c=${_s:_i:1}"),f.push(` case "$_c" in`),f.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),f.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),f.push(` esac`),f.push(` done`),f.push(` printf '%s' "$_r"`),f.push(`}`),f.push(``));for(let e of u){let t=k(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
2
|
+
`);f.push(`${t}__${e}=${l(r)}`)}f.push(``)}F(s)&&(f.push(...ge(a,n)),f.push(``),f.push(`__${a}_apply_dynamic_output() {`),f.push(` local _raw="$1"`),f.push(` COMPREPLY=()`),f.push(` local _directive=0`),f.push(` local -a _lines=()`),f.push(` local _line`),f.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),f.push(" local _last=$((${#_lines[@]} - 1))"),f.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),f.push(' _directive="${_lines[$_last]#:}"'),f.push(` unset '_lines[_last]'`),f.push(` fi`),f.push(' for _line in "${_lines[@]}"; do'),f.push(` [[ -z "$_line" ]] && continue`),f.push(` COMPREPLY+=("$_line")`),f.push(` done`),f.push(' local _ip="${_inline_prefix:-}"'),f.push(` if (( _directive & ${m.DirectoryCompletion} )); then`),f.push(` compopt +o default 2>/dev/null`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _d`),f.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),f.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${m.FileCompletion} )); then`),f.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _f`),f.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),f.push(` else`),f.push(` compopt -o default 2>/dev/null`),f.push(` fi`),f.push(` else`),f.push(` if (( _directive & ${m.NoFileCompletion} )); then`),f.push(` compopt +o default 2>/dev/null`),f.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` fi`),f.push(` fi`),f.push(` if (( _directive & ${m.NoSpace} )); then`),f.push(` compopt -o nospace 2>/dev/null`),f.push(` fi`),f.push(`}`),f.push(``)),f.push(`__${a}_not_used() {`),f.push(' for _u in "${_used_opts[@]}"; do'),f.push(` for _chk in "$@"; do`),f.push(` [[ "$_u" == "$_chk" ]] && return 1`),f.push(` done`),f.push(` done`),f.push(` return 0`),f.push(`}`),f.push(``),f.push(`__${a}_opt_takes_value() {`),f.push(` case "$1:$2" in`),f.push(...we(s,``)),f.push(` esac`),f.push(` return 1`),f.push(`}`),f.push(``),p&&(f.push(`__${a}_track_opt() {`),f.push(` case "$1:$2" in`),f.push(...Oe(d,`bash`)),f.push(` esac`),f.push(`}`),f.push(``),f.push(`__${a}_track_pos() {`),f.push(` case "$1:$2" in`),f.push(...ke(d,`bash`)),f.push(` esac`),f.push(`}`),f.push(``)),g&&(f.push(`__${a}_track_array_expand() {`),f.push(` case "$1:$2" in`),f.push(...Ae(h,`bash`)),f.push(` esac`),f.push(`}`),f.push(``));let _=N(s);_.length>0&&(f.push(`__${a}_is_subcmd() {`),f.push(` case "$1:$2" in`),f.push(...Te(_)),f.push(` esac`),f.push(` return 1`),f.push(`}`),f.push(``));for(let e of c)f.push(...Je(e,a,[]));if(f.push(`__${a}_complete_root() {`),f.push(...Ke(s.options,s.positionals,a,`root`)),f.push(` if [[ -z "$_inline_prefix" ]] && __${a}_opt_takes_value "" "$_prev"; then return; fi`),f.push(` if [[ -n "$_inline_prefix" ]] && __${a}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),s.positionals.length>0?(f.push(` if (( _after_dd )); then`),f.push(...V(s.positionals,a,`root`,s.options).map(e=>` ${e}`)),f.push(` return`),f.push(` fi`)):f.push(` if (( _after_dd )); then return; fi`),f.push(` if [[ "$_cur" == -* ]]; then`),f.push(` local -a _avail=()`),f.push(...qe(s.options,a)),f.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),f.push(` compopt +o default 2>/dev/null`),c.length>0){f.push(` else`);let e=j(s.subcommands).map(e=>e.name).join(` `);f.push(...Ge(e,s.positionals,a,`root`,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(f.push(` else`),f.push(...V(s.positionals,a,`root`,s.options).map(e=>` ${e}`)));f.push(` fi`),f.push(`}`),f.push(``);let v=Ee(_,a).join(`
|
|
3
|
+
`);f.push(`_${a}_completions() {`),f.push(` COMPREPLY=()`),f.push(``),f.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),f.push(` local -a _words=()`),f.push(` local _i=1`),f.push(` while (( _i <= COMP_CWORD )); do`),f.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),f.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),f.push(` (( _i += 2 ))`),f.push(` else`),f.push(' _words+=("${COMP_WORDS[_i]}")'),f.push(` (( _i++ ))`),f.push(` fi`),f.push(` done`),f.push(``),f.push(` local _cur=""`),f.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),f.push(` local _inline_prefix=""`),f.push(``),f.push(` local _prev=""`),f.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),f.push(``),f.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),f.push(` local -a _used_opts=()`),p&&(f.push(` ${B(`_arg_values_`)}`),f.push(` ${B(`_global_arg_values_`)}`)),g&&(f.push(` ${B(`_used_field_keys_`)}`),f.push(` ${B(`_global_used_field_keys_`)}`),f.push(` ${B(`_global_arr_seen_`)}`)),f.push(``),f.push(` local _j=0`),f.push(" while (( _j < ${#_words[@]} - 1 )); do"),f.push(' local _w="${_words[_j]}"'),f.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),f.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let y=p?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;f.push(` if (( _after_dd )); then ${y}(( _pos_count++ )); (( _j++ )); continue; fi`),f.push(` if [[ "$_w" == -*=* ]]; then`),f.push(' _used_opts+=("${_w%%=*}")'),p&&(f.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),g&&f.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),f.push(` (( _j++ )); continue`),f.push(` fi`),f.push(` if [[ "$_w" == -* ]]; then`),f.push(` _used_opts+=("$_w")`),f.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),f.push(' local _next="${_words[_j+1]:-}"'),f.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),p&&(f.push(` if (( _skip_next )); then`),f.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),g&&(f.push(" if (( _j + 2 < ${#_words[@]} )); then"),f.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),f.push(` fi`)),f.push(` fi`)),f.push(` fi`),f.push(` (( _j++ )); continue`),f.push(` fi`);let ee=g?`; ${B(`_arg_values_`)}; ${B(`_used_field_keys_`)}; ${B(`_global_arr_seen_`)}`:p?`; ${B(`_arg_values_`)}`:``,b=p?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;return _.length>0?f.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${ee}; else ${b}(( _pos_count++ )); fi`):(p&&f.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),f.push(` (( _pos_count++ ))`)),f.push(` (( _j++ ))`),f.push(` done`),f.push(``),f.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),f.push(' _inline_prefix="${_cur%%=*}="'),f.push(' _cur="${_cur#*=}"'),f.push(` fi`),f.push(``),f.push(` case "$_subcmd" in`),f.push(v),f.push(` *) __${a}_complete_root ;;`),f.push(` esac`),f.push(`}`),f.push(``),o||f.push(`complete -o default -F _${a}_completions ${n}`),f.push(``),{script:f.join(`
|
|
4
|
+
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
5
|
+
eval "$(${n} completion bash --static)"
|
|
6
|
+
|
|
7
|
+
# For faster shell startup, save the script instead:
|
|
8
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
9
|
+
${n} completion bash --static > ~/.local/share/bash-completion/completions/${n}
|
|
10
|
+
|
|
11
|
+
# Then reload your shell or run:
|
|
12
|
+
source ~/.bashrc`}}const Xe=ce(le),Ze={bash:`bash`,zsh:`zsh`,fish:`fish`},Qe=[`# politty-completion-version: 1`,`# politty-completion-mode: worker`,`# politty-completion-worker: true`];function $e(e){return Ze[e]}function et(e){return E(`dist`,`completion`,`${e}-worker.${$e(e)}`)}function tt(e){let t=Ze[e];return[`completion/${e}-worker.${t}`,`../completion/${e}-worker.${t}`,`dist/completion/${e}-worker.${t}`,`../dist/completion/${e}-worker.${t}`,`completion-worker.${e}`,`../completion-worker.${e}`]}function nt(e,t,n){if(n?.disabled)return[];let r=n?.relativePaths?.[t];return(r&&r.length>0?r:tt(t)).map(n=>n.replaceAll(`{shell}`,t).replaceAll(`{ext}`,Ze[t]).replaceAll(`{program}`,e))}function rt(e){try{let t=S(e,`utf8`),n=null;for(let e of t.split(`
|
|
13
|
+
`)){let t=e.match(/^# cmd-shim-target=(.+)$/);t&&(n=t[1])}return n}catch{return null}}function H(e,t){if(!t)return;e.add(T(se(t)));try{e.add(T(C(t)))}catch{}let n=rt(t);n&&H(e,n)}function it(e){return S(e,`utf8`).split(`
|
|
14
|
+
`,24).join(`
|
|
15
|
+
`)}function at(e,t){return[...Qe,`# program: ${e}`,`# shell: ${t}`]}function ot(e,t,n){let r=e.split(`
|
|
16
|
+
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function U(e,t,n){if(!b(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function st(e,t,n){try{return U(e,t,n),!0}catch{return!1}}function ct(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=new Set;e.binPath!==void 0&&H(n,e.binPath),process.argv[1]&&H(n,process.argv[1]),H(n,R(e.programName,e.binPath));for(let n of t)if(ae(n)&&st(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(ae(n))continue;let t=E(r,n);if(st(t,e.programName,e.shell))return t}return null}function W(e,t){return ae(e)?e:se(t,e)}function lt(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?W(e,n):e,i=ie(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function ut(e,t,n){let r=lt(e,t,n.cwd);try{let{stdout:e,stderr:t}=await Xe(r.command,r.args,{cwd:n.cwd,env:{...process.env,...n.env},encoding:`utf8`,maxBuffer:10485760});return{stdout:e,stderr:t}}catch(e){let t=typeof e==`object`&&e&&`stderr`in e?String(e.stderr??``).trim():``,n=t?`\n${t}`:``;throw Error(`Command failed: ${r.command} ${r.args.join(` `)}${n}`,e instanceof Error?{cause:e}:void 0)}}function dt(e){let t=w(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function ft(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function pt(e,t,n){let r=oe(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${ft(t)})`)}async function mt(e){let t=e.cwd??process.cwd(),n=W(e.outputPath??et(e.shell),t);x(T(n),{recursive:!0}),ne(n,{force:!0}),await ut(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=dt(n);U(n,e.programName,e.shell);let i;if(e.verify){let r=(await ut(e.bin,[`__completion-worker-path`,e.shell],{cwd:t,env:e.env})).stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);if(r.length!==1)throw Error(`Expected __completion-worker-path ${e.shell} to print exactly one path, got ${r.length}.`);i=W(r[0],t);let a=C(n),o=C(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||pt(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function G(e){return p(`/${e}/node-compile-cache`)}function K(e){return e?p(`${e}/node-compile-cache`):void 0}function q(e,t){return e?p(`${e}/completion-worker.${t}`):void 0}function J(e,t){return p(`/${e}/completion-worker.${t}`)}function Y(e,t,n){return t?` ${e} ${t}`:` ${e} "\${XDG_CACHE_HOME:-$HOME/.cache}"${n}`}function ht(e,t){return e?` printf '%s\\n' ${e}`:[` set -l _cache_root "$XDG_CACHE_HOME"`,` test -n "$_cache_root"; or set _cache_root "$HOME/.cache"`,` printf '%s\\n' "$_cache_root"${t}`].join(`
|
|
17
|
+
`)}function gt(e,t){return nt(e.programName,t,e.bundledWorker).map(p).join(` `)}function _t(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function vt(e){return nt(e.programName,`fish`,e.bundledWorker).map(_t).join(` `)}function yt(e){return e.bundledWorker?.queryCommand===!0&&!e.bundledWorker.disabled}function bt(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=Y(`printf '%s\\n'`,K(t.cacheDir),G(n)),l=Y(`printf '%s\\n'`,q(t.cacheDir,`bash`),J(n,`bash`)),u=gt(t,`bash`),d=yt(t),h=[];return h.push(...z({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),h.push(`# Generated by politty`),h.push(`# politty-completion-mode: dispatcher`),h.push(``),h.push(`__${r}_resolve_bin() {`),h.push(` if [[ -n "\${${o}:-}" ]]; then`),h.push(` printf '%s\\n' "\${${o}}"`),h.push(` return 0`),h.push(` fi`),h.push(` type -P ${s} 2>/dev/null`),h.push(`}`),h.push(``),h.push(`__${r}_node_compile_cache_dir() {`),h.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),h.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),h.push(` return 0`),h.push(` fi`),h.push(c),h.push(`}`),h.push(``),h.push(`__${r}_static_worker_path() {`),h.push(l),h.push(`}`),h.push(``),h.push(`__${r}_worker_file_sig() {`),h.push(` local _worker="$1" _sig`),h.push(` _sig=${f(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),h.push(` printf '%s\\n' "$_sig"`),h.push(`}`),h.push(``),h.push(`__${r}_is_worker_file() {`),h.push(` local _worker="$1" _head`),h.push(` [[ -f "$_worker" ]] || return 1`),h.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),h.push(` _head=$'\\n'"$_head"$'\\n'`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),h.push(`}`),h.push(``),h.push(`__${r}_load_worker() {`),h.push(` local _worker="$1" _sig _key`),h.push(` __${r}_is_worker_file "$_worker" || return 1`),h.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),h.push(` _key="$_worker:$_sig"`),h.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),h.push(` source "$_worker" 2>/dev/null || return 1`),h.push(` __${r}_loaded_worker_key="$_key"`),h.push(` fi`),h.push(` declare -F _${i}_completions >/dev/null 2>&1`),h.push(`}`),h.push(``),h.push(`__${r}_realpath() {`),h.push(` local _path="$1" _dir _target _limit=0`),h.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),h.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),h.push(` _target="$(readlink "$_path")" || return 1`),h.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),h.push(` (( _limit++ ))`),h.push(` done`),h.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),h.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),h.push(`}`),h.push(``),h.push(`__${r}_worker_from_dir() {`),h.push(` local _dir="$1" _rel _candidate`),u.length>0&&(h.push(` for _rel in ${u}; do`),h.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),h.push(` if __${r}_is_worker_file "$_candidate"; then`),h.push(` printf '%s\\n' "$_candidate"`),h.push(` return 0`),h.push(` fi`),h.push(` done`)),h.push(` return 1`),h.push(`}`),h.push(``),h.push(`__${r}_cmd_shim_target() {`),h.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),h.push(`}`),h.push(``),h.push(`__${r}_bundled_worker_path() {`),h.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),h.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),h.push(` if [[ -n "$_real" ]]; then`),h.push(` _dir="$(dirname "$_real")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` fi`),h.push(` _dir="$(dirname "$_bin")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),h.push(` if [[ -n "$_target" ]]; then`),h.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),h.push(` _dir="$(dirname "$_real")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` fi`),d&&(h.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),h.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),h.push(` return 0`),h.push(` fi`),h.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),h.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),h.push(` __${r}_queried_bin="$_bin"`),h.push(` __${r}_queried_worker="$_reported"`),h.push(` printf '%s\\n' "$_reported"`),h.push(` return 0`),h.push(` fi`)),h.push(` return 1`),h.push(`}`),h.push(``),h.push(`__${r}_bin_sig() {`),h.push(` local _bin="$1" _sig`),h.push(` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`),h.push(` printf '%s\\n' "$_sig"`),h.push(`}`),h.push(``),h.push(`__${r}_worker_matches_bin() {`),h.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),h.push(` [[ -f "$_worker" ]] || return 1`),h.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),h.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),h.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),h.push(`}`),h.push(``),h.push(`__${r}_apply_dynamic_output() {`),h.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),h.push(` COMPREPLY=()`),h.push(` local _directive=0`),h.push(` local -a _lines=() _exts=() _matchers=()`),h.push(` local _line`),h.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),h.push(" local _last=$((${#_lines[@]} - 1))"),h.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),h.push(` local -a _meta=()`),h.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),h.push(` unset '_lines[_last]'`),h.push(' _directive="${_meta[0]#:}"'),h.push(` local _m`),h.push(' for _m in "${_meta[@]:1}"; do'),h.push(` if [[ "$_m" == @ext:* ]]; then`),h.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),h.push(` elif [[ "$_m" == @matcher:* ]]; then`),h.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),h.push(` fi`),h.push(` done`),h.push(` fi`),h.push(' for _line in "${_lines[@]}"; do'),h.push(` [[ -z "$_line" ]] && continue`),h.push(` COMPREPLY+=("$_line")`),h.push(` done`),h.push(' local _ip="${_inline_prefix:-}"'),h.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _f _ext _pat _base _ok`),h.push(` while IFS= read -r _f; do`),h.push(` if [[ -d "$_f" ]]; then`),h.push(' COMPREPLY+=("${_ip}${_f}")'),h.push(` continue`),h.push(` fi`),h.push(` _ok=0`),h.push(" if (( ${#_exts[@]} > 0 )); then"),h.push(' for _ext in "${_exts[@]}"; do'),h.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),h.push(` done`),h.push(` fi`),h.push(" if (( ${#_matchers[@]} > 0 )); then"),h.push(' _base="${_f##*/}"'),h.push(' for _pat in "${_matchers[@]}"; do'),h.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),h.push(` done`),h.push(` fi`),h.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),h.push(` done < <(compgen -f -- "$_cur")`),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` elif (( _directive & ${m.DirectoryCompletion} )); then`),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _d`),h.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` elif (( _directive & ${m.FileCompletion} )); then`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _p`),h.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),h.push(` elif (( _directive & ${m.NoFileCompletion} )); then`),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` fi`),h.push(` if (( _directive & ${m.NoSpace} )); then`),h.push(` compopt -o nospace 2>/dev/null`),h.push(` fi`),h.push(`}`),h.push(``),h.push(`_${r}_completions() {`),h.push(` COMPREPLY=()`),h.push(` local -a _words=()`),h.push(` local _i=1`),h.push(` while (( _i <= COMP_CWORD )); do`),h.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),h.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),h.push(` (( _i += 2 ))`),h.push(` else`),h.push(' _words+=("${COMP_WORDS[_i]}")'),h.push(` (( _i++ ))`),h.push(` fi`),h.push(` done`),h.push(` local _cur="" _inline_prefix=""`),h.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),h.push(` local _after_dd=0 _di=0`),h.push(" while (( _di < ${#_words[@]} - 1 )); do"),h.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),h.push(` (( _di++ ))`),h.push(` done`),h.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),h.push(' _inline_prefix="${_cur%%=*}="'),h.push(' _cur="${_cur#*=}"'),h.push(` fi`),h.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),h.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),h.push(` [[ -n "$_bin" ]] || return 0`),h.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),h.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),h.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),h.push(` return 0`),h.push(` fi`),h.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),h.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),h.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),h.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),h.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),h.push(` fi`),h.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),h.push(` return 0`),h.push(` fi`),h.push(` fi`),h.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),h.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),h.push(`}`),h.push(``),h.push(`complete -o default -F _${r}_completions ${n}`),h.push(``),{script:h.join(`
|
|
18
|
+
`),shell:`bash`,installInstructions:`# To enable dispatcher bash completions, add this to your ~/.bashrc:
|
|
19
|
+
eval "$(${n} completion bash)"
|
|
20
|
+
|
|
21
|
+
# To save the dispatcher script instead:
|
|
22
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
23
|
+
${n} completion bash > ~/.local/share/bash-completion/completions/${n}
|
|
24
|
+
|
|
25
|
+
# To generate the older static script:
|
|
26
|
+
${n} completion bash --static`}}function xt(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=`_${n}`,l=`"\${funcstack[1]:-}" == "${c}"`,u=Y(`print -r --`,K(t.cacheDir),G(n)),d=Y(`print -r --`,q(t.cacheDir,`zsh`),J(n,`zsh`)),h=gt(t,`zsh`),g=yt(t),_=[];return _.push(`#compdef ${n}`),_.push(...z({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),_.push(`# Generated by politty`),_.push(`# politty-completion-mode: dispatcher`),_.push(``),_.push(`__${r}_resolve_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` if [[ -n "\${${o}:-}" ]]; then`),_.push(` print -r -- "\${${o}}"`),_.push(` return 0`),_.push(` fi`),_.push(` whence -p ${s} 2>/dev/null`),_.push(`}`),_.push(``),_.push(`__${r}_node_compile_cache_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),_.push(` print -r -- "$NODE_COMPILE_CACHE"`),_.push(` return 0`),_.push(` fi`),_.push(u),_.push(`}`),_.push(``),_.push(`__${r}_static_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(d),_.push(`}`),_.push(``),_.push(`__${r}_worker_file_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig`),_.push(` _sig=${f(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_is_worker_file() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head="$(<$_worker)" || return 1`),_.push(` _head=$'\\n'"$_head"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# shell: zsh"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_load_worker() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig _key`),_.push(` __${r}_is_worker_file "$_worker" || return 1`),_.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),_.push(` _key="$_worker:$_sig"`),_.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),_.push(` source "$_worker" 2>/dev/null || return 1`),_.push(` typeset -g __${r}_loaded_worker_key="$_key"`),_.push(` fi`),_.push(` (( $+functions[_${i}_completions] ))`),_.push(`}`),_.push(``),_.push(`__${r}_realpath() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _path="$1"`),_.push(` [[ -n "$_path" ]] || return 1`),_.push(' print -r -- "${_path:A}"'),_.push(`}`),_.push(``),_.push(`__${r}_worker_from_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _dir="$1" _rel _candidate`),h.length>0&&(_.push(` for _rel in ${h}; do`),_.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),_.push(` if __${r}_is_worker_file "$_candidate"; then`),_.push(` print -r -- "$_candidate"`),_.push(` return 0`),_.push(` fi`),_.push(` done`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cmd_shim_target() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` [[ -f "$1" ]] || return 0`),_.push(` local _l _t=""`),_.push(' for _l in "${(@f)$(<$1)}"; do'),_.push(' [[ "$_l" == "# cmd-shim-target="* ]] && _t="${_l#\\# cmd-shim-target=}"'),_.push(` done`),_.push(` [[ -n "$_t" ]] && print -r -- "$_t"`),_.push(`}`),_.push(``),_.push(`__${r}_bundled_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),_.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),_.push(` if [[ -n "$_real" ]]; then`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),_.push(' _dir="${_bin:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),_.push(` if [[ -n "$_target" ]]; then`),_.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),g&&(_.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),_.push(` print -r -- "\${__${r}_queried_worker}"`),_.push(` return 0`),_.push(` fi`),_.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path zsh 2>/dev/null)" || _reported=""`),_.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),_.push(` typeset -g __${r}_queried_bin="$_bin"`),_.push(` typeset -g __${r}_queried_worker="$_reported"`),_.push(` print -r -- "$_reported"`),_.push(` return 0`),_.push(` fi`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_bin_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin="$1" _sig`),_.push(` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_worker_matches_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head=$'\\n'"$(<$_worker)"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-sig: $_sig"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-path: $_bin"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cdescribe() {`),_.push(` _describe "$@" 2>/dev/null && return 0`),_.push(` shift`),_.push(` local _cd_arr="$1"`),_.push(` shift`),_.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),_.push(` compadd "$@" -a _cd_vals 2>/dev/null`),_.push(` return 0`),_.push(`}`),_.push(``),_.push(`__${r}_add_path_candidate() {`),_.push(` compadd -f -- "$1" 2>/dev/null && return 0`),_.push(` print -r -- "$1"`),_.push(`}`),_.push(``),_.push(`__${r}_apply_dynamic_output() {`),_.push(` local _raw="$1"`),_.push(` local _directive=0`),_.push(` local -a _vals _lines _exts _matchers`),_.push(` local _meta`),_.push(' _lines=("${(@f)_raw}")'),_.push(` local _last=$#_lines`),_.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<->* ]]; then'),_.push(' local _dline="${_lines[$_last]}"'),_.push(` _lines[$_last]=()`),_.push(` local -a _dfields`),_.push(' _dfields=("${(@ps:\\t:)_dline}")'),_.push(' _directive="${_dfields[1]#:}"'),_.push(` local _m`),_.push(' for _m in "${(@)_dfields[2,-1]}"; do'),_.push(` if [[ "$_m" == @ext:* ]]; then`),_.push(' _meta="${_m#@ext:}"'),_.push(' _exts=("${(@s:,:)_meta}")'),_.push(` elif [[ "$_m" == @matcher:* ]]; then`),_.push(' _meta="${_m#@matcher:}"'),_.push(' _matchers=("${(@s:,:)_meta}")'),_.push(` fi`),_.push(` done`),_.push(` fi`),_.push(` local _l`),_.push(' for _l in "${_lines[@]}"; do'),_.push(` [[ -z "$_l" ]] && continue`),_.push(` _vals+=("$_l")`),_.push(` done`),_.push(" if (( ${#_vals[@]} > 0 )); then"),_.push(` if (( _directive & ${m.NoSpace} )); then`),_.push(` __${r}_cdescribe 'completions' _vals -S ''`),_.push(` else`),_.push(` __${r}_cdescribe 'completions' _vals`),_.push(` fi`),_.push(` fi`),_.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),_.push(` setopt local_options null_glob`),_.push(' local _cur="${words[CURRENT]:-}" _dir _prefix _f _out _ext _pat'),_.push(` if [[ -z "$_cur" || "$_cur" != */* ]]; then`),_.push(` _dir="."`),_.push(` _prefix="$_cur"`),_.push(` elif [[ "$_cur" == */ ]]; then`),_.push(' _dir="${_cur%/}"'),_.push(` _prefix=""`),_.push(` else`),_.push(' _dir="${_cur%/*}"'),_.push(' _prefix="${_cur##*/}"'),_.push(` fi`),_.push(` for _f in "$_dir"/"$_prefix"*(N/); do`),_.push(' _out="${_f#./}"'),_.push(` __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` for _f in "$_dir"/"$_prefix"*(N.); do`),_.push(' _out="${_f#./}"'),_.push(' for _ext in "${_exts[@]}"; do'),_.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${r}_add_path_candidate "$_out"; break; }`),_.push(` done`),_.push(` done`),_.push(' for _pat in "${_matchers[@]}"; do'),_.push(` [[ -n "$_pat" ]] || continue`),_.push(' for _f in "$_dir"/${~_pat}(N.); do'),_.push(' _out="${_f#./}"'),_.push(` [[ "$_out" == "$_cur"* ]] && __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` done`),_.push(` elif (( _directive & ${m.DirectoryCompletion} )); then`),_.push(` _files -/`),_.push(` elif (( _directive & ${m.FileCompletion} )); then`),_.push(` _files`),_.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${m.NoFileCompletion} )); then`),_.push(` _files`),_.push(` fi`),_.push(`}`),_.push(``),_.push(`${c}() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),_.push(` _bin="$(__${r}_resolve_bin)"`),_.push(` [[ -n "$_bin" ]] || return 1`),_.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)"`),_.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")"`),_.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` _worker="$(__${r}_static_worker_path)"`),_.push(` _sig="$(__${r}_bin_sig "$_bin")"`),_.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),_.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),_.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion zsh "$_worker" --static --worker 2>/dev/null`),_.push(` fi`),_.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` fi`),_.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell zsh -- "${(@)words[2,CURRENT]}" 2>/dev/null) || return 1'),_.push(` __${r}_apply_dynamic_output "$_out"`),_.push(`}`),_.push(``),_.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),_.push(``),_.push(`if [[ ${l} ]]; then`),_.push(` ${c} "$@"`),_.push(`else`),_.push(` compdef ${c} ${n}`),_.push(`fi`),_.push(``),{script:_.join(`
|
|
27
|
+
`),shell:`zsh`,installInstructions:`# To enable dispatcher zsh completions, add this to your ~/.zshrc after compinit:
|
|
28
|
+
eval "$(${n} completion zsh)"
|
|
29
|
+
|
|
30
|
+
# To save the dispatcher script in your fpath:
|
|
31
|
+
mkdir -p ~/.zsh/completions
|
|
32
|
+
${n} completion zsh > ~/.zsh/completions/_${n}
|
|
33
|
+
|
|
34
|
+
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
35
|
+
fpath=(~/.zsh/completions $fpath)
|
|
36
|
+
autoload -Uz compinit && compinit
|
|
37
|
+
|
|
38
|
+
# To generate the older static script:
|
|
39
|
+
${n} completion zsh --static`}}function St(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=ht(K(t.cacheDir),G(n)),l=ht(q(t.cacheDir,`fish`),J(n,`fish`)),u=vt(t),d=yt(t),h=[];return h.push(...z({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),h.push(`# Generated by politty`),h.push(`# politty-completion-mode: dispatcher`),h.push(``),h.push(`function __${r}_resolve_bin`),h.push(` if set -q ${o}; and test -n "$${o}"`),h.push(` printf '%s\\n' "$${o}"`),h.push(` return 0`),h.push(` end`),h.push(` set -l _bin (command -v ${s})`),h.push(` test -n "$_bin"; and test -x "$_bin"; and not test -d "$_bin"; and printf '%s\\n' "$_bin"`),h.push(`end`),h.push(``),h.push(`function __${r}_node_compile_cache_dir`),h.push(` if set -q NODE_COMPILE_CACHE; and test -n "$NODE_COMPILE_CACHE"`),h.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),h.push(` return 0`),h.push(` end`),h.push(c),h.push(`end`),h.push(``),h.push(`function __${r}_static_worker_path`),h.push(l),h.push(`end`),h.push(``),h.push(`function __${r}_worker_file_sig`),h.push(` set -l _worker $argv[1]`),h.push(` set -l _sig ${f(`$_worker`,{shell:`fish`,withSize:!0})}`),h.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),h.push(`end`),h.push(``),h.push(`function __${r}_is_worker_file`),h.push(` set -l _worker $argv[1]`),h.push(` test -f "$_worker"; or return 1`),h.push(` set -l _head (head -n 24 "$_worker" 2>/dev/null)`),h.push(` string match -q -- "# politty-completion-version: 1" $_head; or return 1`),h.push(` string match -q -- "# program: ${n}" $_head; or return 1`),h.push(` string match -q -- "# shell: fish" $_head; or return 1`),h.push(` string match -q -- "# politty-completion-mode: worker" $_head; or return 1`),h.push(` string match -q -- "# politty-completion-worker: true" $_head; or return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_load_worker`),h.push(` set -l _worker $argv[1]`),h.push(` __${r}_is_worker_file "$_worker"; or return 1`),h.push(` set -l _sig (__${r}_worker_file_sig "$_worker")`),h.push(` test -n "$_sig"; or return 1`),h.push(` set -l _key "$_worker:$_sig"`),h.push(` if not set -q __${r}_loaded_worker_key; or test "$__${r}_loaded_worker_key" != "$_key"`),h.push(` source "$_worker" 2>/dev/null; or return 1`),h.push(` set -g __${r}_loaded_worker_key "$_key"`),h.push(` end`),h.push(` functions -q __fish_${i}_complete`),h.push(`end`),h.push(``),h.push(`function __${r}_realpath`),h.push(` set -l _path $argv[1]`),h.push(` set -l _old_pwd (pwd)`),h.push(` set -l _limit 0`),h.push(` while test -L "$_path"; and test $_limit -lt 40`),h.push(` set -l _dir (dirname "$_path")`),h.push(` if not cd "$_dir" 2>/dev/null`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` return 1`),h.push(` end`),h.push(` set -l _absdir (pwd -P)`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` test -n "$_absdir"; or return 1`),h.push(` set -l _target (readlink "$_path")`),h.push(` test -n "$_target"; or return 1`),h.push(` if string match -q '/*' -- "$_target"`),h.push(` set _path "$_target"`),h.push(` else`),h.push(` set _path "$_absdir/$_target"`),h.push(` end`),h.push(` set _limit (math $_limit + 1)`),h.push(` end`),h.push(` set -l _dir (dirname "$_path")`),h.push(` if not cd "$_dir" 2>/dev/null`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` return 1`),h.push(` end`),h.push(` set -l _absdir (pwd -P)`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` test -n "$_absdir"; or return 1`),h.push(` set -l _base (basename "$_path")`),h.push(` printf '%s\\n' "$_absdir/$_base"`),h.push(`end`),h.push(``),h.push(`function __${r}_worker_from_dir`),h.push(` set -l _dir $argv[1]`),u.length>0&&(h.push(` for _rel in ${u}`),h.push(` if string match -q '/*' -- "$_rel"`),h.push(` set _candidate "$_rel"`),h.push(` else`),h.push(` set _candidate "$_dir/$_rel"`),h.push(` end`),h.push(` if __${r}_is_worker_file "$_candidate"`),h.push(` printf '%s\\n' "$_candidate"`),h.push(` return 0`),h.push(` end`),h.push(` end`)),h.push(` return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_cmd_shim_target`),h.push(` sed -n 's/^# cmd-shim-target=//p' "$argv[1]" 2>/dev/null | tail -n 1`),h.push(`end`),h.push(``),h.push(`function __${r}_bundled_worker_path`),h.push(` set -l _bin $argv[1]`),h.push(` set -l _node_compile_cache $argv[2]`),h.push(` set -l _real (__${r}_realpath "$_bin" 2>/dev/null)`),h.push(` if test -n "$_real"`),h.push(` set -l _dir (dirname "$_real")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` end`),h.push(` set -l _dir (dirname "$_bin")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` set -l _target (__${r}_cmd_shim_target "$_bin")`),h.push(` if test -n "$_target"`),h.push(` set _real (__${r}_realpath "$_target" 2>/dev/null)`),h.push(` test -n "$_real"; or set _real "$_target"`),h.push(` set _dir (dirname "$_real")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` end`),d&&(h.push(` if set -q __${r}_queried_bin; and test "$__${r}_queried_bin" = "$_bin"; and test -n "$__${r}_queried_worker"; and __${r}_is_worker_file "$__${r}_queried_worker"`),h.push(` printf '%s\\n' "$__${r}_queried_worker"`),h.push(` return 0`),h.push(` end`),h.push(` set -l _reported (env NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path fish 2>/dev/null)`),h.push(` if test -n "$_reported"; and __${r}_is_worker_file "$_reported"`),h.push(` set -g __${r}_queried_bin "$_bin"`),h.push(` set -g __${r}_queried_worker "$_reported"`),h.push(` printf '%s\\n' "$_reported"`),h.push(` return 0`),h.push(` end`)),h.push(` return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_bin_sig`),h.push(` set -l _bin $argv[1]`),h.push(` set -l _sig ${f(`$_bin`,{shell:`fish`})}`),h.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),h.push(`end`),h.push(``),h.push(`function __${r}_worker_matches_bin`),h.push(` set -l _worker $argv[1]`),h.push(` set -l _sig $argv[2]`),h.push(` set -l _bin $argv[3]`),h.push(` test -f "$_worker"; or return 1`),h.push(` set -l _head (head -n 12 "$_worker" 2>/dev/null)`),h.push(` contains -- "# politty-bin-sig: $_sig" $_head; or return 1`),h.push(` contains -- "# politty-bin-path: $_bin" $_head; or return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_apply_dynamic_output`),h.push(` set -l _cur $argv[1]`),h.push(` set -l _directive 0`),h.push(` set -l _emitted 0`),h.push(` set -l _exts`),h.push(` set -l _matchers`),h.push(` set -l _lines`),h.push(` while read -l _l`),h.push(` set -a _lines $_l`),h.push(` end`),h.push(` set -l _n (count $_lines)`),h.push(` if test $_n -ge 1; and string match -qr '^:[0-9]+' -- $_lines[$_n]`),h.push(` set -l _fields (string split \\t -- $_lines[$_n])`),h.push(` set -e _lines[$_n]`),h.push(` set _directive (string sub -s 2 -- $_fields[1])`),h.push(` for _f in $_fields[2..-1]`),h.push(` if string match -q '@ext:*' -- $_f`),h.push(` set _exts (string split , -- (string sub -s 6 -- $_f))`),h.push(` else if string match -q '@matcher:*' -- $_f`),h.push(` set _matchers (string split , -- (string sub -s 10 -- $_f))`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` for _l in $_lines`),h.push(` if test -n "$_l"`),h.push(` printf '%s\\n' $_l`),h.push(` set _emitted 1`),h.push(` end`),h.push(` end`),h.push(` if test (count $_exts) -gt 0; or test (count $_matchers) -gt 0`),h.push(` __fish_complete_directories "$_cur"`),h.push(` set -l _dir ""`),h.push(` if string match -q '*/*' "$_cur"`),h.push(` set _dir (string replace -r '[^/]*$' '' "$_cur")`),h.push(` end`),h.push(` for _f in "$_cur"*`),h.push(` test -f "$_f"; or continue`),h.push(` for _ext in $_exts`),h.push(` if string match -q -- "*.$_ext" "$_f"`),h.push(` printf '%s\\n' "$_f"`),h.push(` break`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` for _pat in $_matchers`),h.push(` for _f in "$_dir"$_pat`),h.push(` test -f "$_f"; and string match -q "$_cur*" "$_f"; and printf '%s\\n' "$_f"`),h.push(` end`),h.push(` end`),h.push(` else if test (math "bitand($_directive, ${m.DirectoryCompletion})") -ne 0`),h.push(` __fish_complete_directories "$_cur"`),h.push(` else if test (math "bitand($_directive, ${m.FileCompletion})") -ne 0`),h.push(` __fish_complete_path "$_cur"`),h.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${m.NoFileCompletion})") -eq 0`),h.push(` __fish_complete_path "$_cur"`),h.push(` end`),h.push(`end`),h.push(``),h.push(`function __fish_${r}_complete`),h.push(` set -l _bin (__${r}_resolve_bin)`),h.push(` test -n "$_bin"; or return 0`),h.push(` set -l _node_compile_cache (__${r}_node_compile_cache_dir)`),h.push(` set -l _bundled_worker (__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")`),h.push(` if test -n "$_bundled_worker"; and __${r}_load_worker "$_bundled_worker"`),h.push(` set -lx ${a} "$_bin"`),h.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),h.push(` __fish_${i}_complete`),h.push(` return 0`),h.push(` end`),h.push(` set -l _worker (__${r}_static_worker_path)`),h.push(` set -l _sig (__${r}_bin_sig "$_bin")`),h.push(` if test -n "$_worker"; and test -n "$_sig"`),h.push(` if not __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),h.push(` mkdir -p (dirname "$_worker") 2>/dev/null`),h.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" $_bin __refresh-completion fish "$_worker" --static --worker 2>/dev/null`),h.push(` end`),h.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),h.push(` if __${r}_load_worker "$_worker"`),h.push(` set -lx ${a} "$_bin"`),h.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),h.push(` __fish_${i}_complete`),h.push(` return 0`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` set -l _args (commandline -opc)`),h.push(` set -l _cur (commandline -ct)`),h.push(` if test (count $_args) -gt 0`),h.push(` set _args $_args[2..]`),h.push(` end`),h.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" $_bin __complete --shell fish -- $_args "$_cur" 2>/dev/null | __${r}_apply_dynamic_output "$_cur"`),h.push(`end`),h.push(``),h.push(`complete -e -c ${n}`),h.push(`complete -c ${n} -f -a '(__fish_${r}_complete)'`),h.push(``),{script:h.join(`
|
|
40
|
+
`),shell:`fish`,installInstructions:`# To enable dispatcher fish completions, run:
|
|
41
|
+
${n} completion fish --install
|
|
42
|
+
|
|
43
|
+
# To generate the older static script:
|
|
44
|
+
${n} completion fish --static`}}function Ct(e,t){switch(I(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return bt(e,t);case`zsh`:return xt(e,t);case`fish`:return St(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function wt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function Tt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=D(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=D(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${wt(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Et(e.matcher):e.extensions?.length?Dt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Et(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Dt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Ot(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=Tt(i.valueCompletion,n,d(i,e,t));if(a.length===0)continue;let o=P(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Z(e,t,n=[]){if(e.length===0)return[];let r=[];for(let i of e){let a=Tt(i.valueCompletion,t,_(i,n,e));if(a.length!==0){i.variadic?r.push(` if test $_pos_count -ge ${i.position}`):r.push(` if test $_pos_count -eq ${i.position}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}}return r}function kt(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function At(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` __${t}_not_used "--help"; and echo "--help\tShow help"`),n}function jt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(D).join(`_`)}`,a=A(e.subcommands),o=[];for(let e of a)o.push(...jt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Ot(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...At(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=j(e.subcommands);o.push(...kt(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function Mt(e,t){let n=[];for(let r of Ce(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Nt(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=A(s.subcommands),l=je(s),u=Ne(s,l,r.globalOptions),d=l.length>0,p=l.filter(e=>e.isArrayOption),h=p.length>0,g=[];if(g.push(...z({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),g.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&g.push(`# politty-completion-worker: true`),g.push(`# Generated by politty`),g.push(``),!o){let e=R(n,t.binPath),r=L(e),o=O(i),s=`__${a}_refresh_completion`;g.push(`function ${s} --no-scope-shadowing`),g.push(` set -l _bin $${o}`),g.push(` test -z "$_bin"; and set _bin (command -v ${n})`),g.push(` test -z "$_bin"; and return 1`),g.push(` set -l _sig ${f(`$_bin`,{shell:`fish`})}`),g.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),g.push(` set -l _target (status current-filename)`),g.push(` test -n "$_target"; and test -f "$_target"; or return 1`),g.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),g.push(` and source "$_target" 2>/dev/null`),g.push(` and return 0`),g.push(` return 1`),g.push(`end`),g.push(`${s}`),g.push(`set -l _politty_refreshed $status`),g.push(`functions -e ${s}`),g.push(`test $_politty_refreshed -eq 0; and return`),g.push(``)}if(F(s)&&(g.push(`function __${a}_invoke_complete`),g.push(` set -l _shell $argv[1]`),g.push(` set -l _argv $argv[2..]`),g.push(` set -l _bin ${n}`),g.push(` if set -q ${O(a)}`),g.push(` set _bin $${O(a)}`),g.push(` end`),g.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),g.push(`end`),g.push(``),g.push(`function __${a}_apply_dynamic_output`),g.push(` set -l _cur $argv[1]`),g.push(` set -l _directive 0`),g.push(` set -l _emitted 0`),g.push(` set -l _prev ""`),g.push(` set -l _has_prev 0`),g.push(` while read -l _l`),g.push(` if test $_has_prev -eq 1`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` set _prev $_l`),g.push(` set _has_prev 1`),g.push(` end`),g.push(` if test $_has_prev -eq 1`),g.push(` if string match -qr '^:[0-9]+$' -- $_prev`),g.push(` set _directive (string sub -s 2 -- $_prev)`),g.push(` else`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` end`),g.push(` if test (math "bitand($_directive, ${m.DirectoryCompletion})") -ne 0`),g.push(` __fish_complete_directories "$_cur"`),g.push(` else if test (math "bitand($_directive, ${m.FileCompletion})") -ne 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${m.NoFileCompletion})") -eq 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` end`),g.push(`end`),g.push(``)),g.push(`function __${a}_not_used --no-scope-shadowing`),g.push(` for _chk in $argv`),g.push(` if contains -- "$_chk" $_used_opts`),g.push(` return 1`),g.push(` end`),g.push(` end`),g.push(` return 0`),g.push(`end`),g.push(``),g.push(`function __${a}_opt_takes_value`),g.push(` switch "$argv[1]:$argv[2]"`),g.push(...Mt(s,``)),g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${D(e.fieldName)}`;g.push(`function __${a}_track_opt --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``),g.push(`function __${a}_track_pos --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``)}if(h){g.push(`function __${a}_track_array_expand --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of p){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=D(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;g.push(` case ${t}`),g.push(` if string match -q '*=*' -- "$argv[3]"`),g.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),g.push(` if test -n "$_k"`),e.isGlobal?(g.push(` if not set -q _global_arr_seen_${n}`),g.push(` set -g ${r}${n} "$_k"`),g.push(` set -g _global_arr_seen_${n} 1`),g.push(` else if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)):(g.push(` if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)),g.push(` end`),g.push(` end`)}g.push(` end`),g.push(`end`),g.push(``)}let _=N(s);if(_.length>0){g.push(`function __${a}_is_subcmd`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of _)g.push(` case "${e.lookupPattern}"`),g.push(` return 0`);g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``)}for(let e of c)g.push(...jt(e,a,[]));if(g.push(`function __${a}_complete_root --no-scope-shadowing`),g.push(...Ot(s.options,s.positionals,a)),g.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(g.push(` if test $_after_dd -eq 1`),g.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),g.push(` return`),g.push(` end`)):g.push(` if test $_after_dd -eq 1; return; end`),g.push(` if string match -q -- '-*' "$_cur"`),g.push(...At(s.options,a)),c.length>0){g.push(` else`);let e=j(s.subcommands);g.push(...kt(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(g.push(` else`),g.push(...Z(s.positionals,a,s.options)));if(g.push(` end`),g.push(`end`),g.push(``),g.push(`function __fish_${a}_complete`),g.push(` set -l _args (commandline -opc)`),g.push(` set -e _args[1]`),g.push(``),g.push(` set -l _ct (commandline -ct)`),g.push(` if test (count $_ct) -eq 0`),g.push(` set -a _args ""`),g.push(` else`),g.push(` set -a _args $_ct`),g.push(` end`),g.push(``),g.push(` set -l _cur ""`),g.push(` if test (count $_args) -gt 0`),g.push(` set _cur "$_args[-1]"`),g.push(` end`),g.push(``),g.push(` set -l _prev ""`),g.push(` if test (count $_args) -gt 1`),g.push(` set _prev "$_args[-2]"`),g.push(` end`),g.push(``),g.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),g.push(` set -l _used_opts`),g.push(``),d)for(let e of u)g.push(` set -e _arg_values_${D(e.fieldName)}`),g.push(` set -e _global_arg_values_${D(e.fieldName)}`);if(h)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`);g.push(` set -l _j 1`),g.push(` set -l _limit (math (count $_args) - 1)`),g.push(` while test $_j -le $_limit`),g.push(` set -l _w "$_args[$_j]"`),g.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),g.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let v=d?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;if(g.push(` if test $_after_dd -eq 1; ${v}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),g.push(` if string match -q -- '-*=*' "$_w"`),g.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),g.push(` set -a _used_opts "$_opt"`),d&&(g.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),g.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),h&&g.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),g.push(` if string match -q -- '-*' "$_w"`),g.push(` set -a _used_opts "$_w"`),g.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),g.push(` set -l _next ""`),g.push(` set -l _next_idx (math $_j + 1)`),g.push(` if test $_next_idx -le (count $_args)`),g.push(` set _next "$_args[$_next_idx]"`),g.push(` end`),g.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),g.push(` set _skip_next 1`),d&&(g.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),h&&(g.push(` if test $_j -lt $_limit`),g.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),g.push(` end`))),g.push(` end`),g.push(` end`),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),_.length>0){if(g.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),g.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),g.push(` set _used_opts; set _pos_count 0`),d){for(let e of u)g.push(` set -e _arg_values_${D(e.fieldName)}`);if(h)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`)}g.push(` else`),d&&g.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`),g.push(` end`)}else d&&g.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`);g.push(` set _j (math $_j + 1)`),g.push(` end`),g.push(``),g.push(` switch "$_subcmd"`);for(let e of _)g.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return g.push(` case '*'; __${a}_complete_root`),g.push(` end`),g.push(`end`),g.push(``),o||(g.push(`# Clear existing completions`),g.push(`complete -e -c ${n}`),g.push(``),g.push(`# Register completion`),g.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),g.push(``),{script:g.join(`
|
|
45
|
+
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
|
+
${n} completion fish --install --static`}}function Pt(e,t){x(T(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;re(n,t),te(n,e)}function Ft(e,t){return nn(e.rootCommand,{shell:t,programName:e.programName,mode:e.completionMode??`dispatcher`,includeDescriptions:!0,...e.programVersion!==void 0&&{programVersion:e.programVersion},...e.binPath!==void 0&&{binPath:e.binPath},...e.cacheDir!==void 0&&{cacheDir:e.cacheDir},...e.globalArgsSchema!==void 0&&{globalArgsSchema:e.globalArgsSchema},...e.bundledWorker!==void 0&&{bundledWorker:e.bundledWorker},...e.staticWorker!==void 0&&{staticWorker:e.staticWorker}}).script}function It(e,t){let n=r(e.programName,t,e.cacheDir);return Pt(n,Ft(e,t)),n}function Lt(e){try{if(!b(e))return;let t=S(e,`utf8`).split(`
|
|
47
|
+
`,10).join(`
|
|
48
|
+
`).match(/^# politty-completion-mode: (dispatcher|static)$/m);return t?t[1]:void 0}catch{return}}function Rt(e){try{if(!b(e))return null;let t=S(e,`utf8`).split(`
|
|
49
|
+
`,10).join(`
|
|
50
|
+
`).match(/^# politty-bin-path: (.*)$/m);return t?t[1]:null}catch{return null}}function zt(e,t,n){try{if(!b(e))return!1;let r=S(e,`utf8`).split(`
|
|
51
|
+
`,8).map(e=>e.trimEnd());return r.some(e=>/^# politty-completion-version: \S+$/.test(e))&&r.includes(`# program: ${t}`)&&r.includes(`# shell: ${n}`)}catch{return!1}}function Bt(e,t){try{let n=e.targetPath?b(e.targetPath)?C(e.targetPath):e.targetPath:r(e.programName,t,e.cacheDir);if(e.targetPath&&b(n)&&!zt(n,e.programName,t)||e.targetPath&&!b(n)&&!e.allowTargetCreate)return;let i=R(e.programName,e.binPath);if(!i)return;let a;try{a=Math.floor(w(i).mtimeMs/1e3).toString()}catch{return}if(o(n)===a&&Rt(n)===i)return;let s=e.completionMode??Lt(n)??(b(n)?`static`:`dispatcher`);Pt(n,Ft({...e,completionMode:s},t))}catch{}}function Vt(e,t,n){return t?p(`${t}/completion.${n}`):`"\${XDG_CACHE_HOME:-$HOME/.cache}/${e}/completion.${n}"`}function Ht(e){let t=D(e.programName),n=O(t),r=Vt(e.programName,e.cacheDir,`bash`);return`__${t}_load_completion() {
|
|
52
|
+
local _bin _cache _sig _sig_hdr _path_hdr
|
|
53
|
+
_bin="\${${n}:-$(type -P ${e.programName} 2>/dev/null)}"
|
|
54
|
+
[[ -n "$_bin" ]] || return 0
|
|
55
|
+
_cache=${r}
|
|
56
|
+
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
57
|
+
_sig_hdr="# politty-bin-sig: $_sig"
|
|
58
|
+
_path_hdr="# politty-bin-path: $_bin"
|
|
59
|
+
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
60
|
+
# Use the hidden __refresh-completion subcommand instead of
|
|
61
|
+
# \`$_bin completion bash\`: the foreground completion command
|
|
62
|
+
# is subject to user setup/cleanup/prompt and required
|
|
63
|
+
# globalArgs validation, which can silently fail or block when
|
|
64
|
+
# invoked from rc; runMain bypasses those for __-prefixed
|
|
65
|
+
# internal subcommands.
|
|
66
|
+
"$_bin" __refresh-completion bash 2>/dev/null
|
|
67
|
+
fi
|
|
68
|
+
# If regen failed but a stale cache survived from a previous run,
|
|
69
|
+
# source it anyway — a stale completion is preferable to no
|
|
70
|
+
# completion at all.
|
|
71
|
+
[[ -f "$_cache" ]] || return 0
|
|
72
|
+
# shellcheck disable=SC1090
|
|
73
|
+
source "$_cache"
|
|
74
|
+
}
|
|
75
|
+
__${t}_load_completion
|
|
76
|
+
unset -f __${t}_load_completion
|
|
77
|
+
`}function Ut(e){let t=D(e.programName),n=O(t),r=Vt(e.programName,e.cacheDir,`zsh`);return`__${t}_load_completion() {
|
|
78
|
+
emulate -L zsh
|
|
79
|
+
setopt local_options no_aliases
|
|
80
|
+
local _bin _cache _sig _sig_hdr _path_hdr
|
|
81
|
+
_bin="\${${n}:-$(whence -p ${e.programName} 2>/dev/null)}"
|
|
82
|
+
[[ -n "$_bin" ]] || return 0
|
|
83
|
+
_cache=${r}
|
|
84
|
+
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
85
|
+
_sig_hdr="# politty-bin-sig: $_sig"
|
|
86
|
+
_path_hdr="# politty-bin-path: $_bin"
|
|
87
|
+
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
88
|
+
# See bash loader for why we use __refresh-completion instead
|
|
89
|
+
# of \`$_bin completion zsh\`.
|
|
90
|
+
"$_bin" __refresh-completion zsh 2>/dev/null
|
|
91
|
+
fi
|
|
92
|
+
# See bash loader: keep stale completion over no completion.
|
|
93
|
+
[[ -f "$_cache" ]] || return 0
|
|
94
|
+
source "$_cache"
|
|
95
|
+
}
|
|
96
|
+
__${t}_load_completion
|
|
97
|
+
unfunction __${t}_load_completion
|
|
98
|
+
`}function Wt(e){switch(e.shell){case`bash`:return Ht(e);case`zsh`:return Ut(e);case`fish`:throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.")}}function Q(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`").replace(/:/g,`\\:`)}function Gt(e){return e.replace(/\\/g,`\\\\`).replace(/:/g,`\\:`)}function Kt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function qt(e){return e.map(e=>`"${Kt(e)}"`).join(` `)}function Jt(e,t,n){let r=[`setopt local_options null_glob`,'local _cur="${words[CURRENT]:-}" _dir _prefix _f _out',`local -a ${t===`extensions`?`_exts`:`_matchers`}=(${qt(n)})`,`if [[ -z "$_cur" || "$_cur" != */* ]]; then`,` _dir="."`,` _prefix="$_cur"`,`elif [[ "$_cur" == */ ]]; then`,' _dir="${_cur%/}"',` _prefix=""`,`else`,' _dir="${_cur%/*}"',' _prefix="${_cur##*/}"',`fi`,`for _f in "$_dir"/"$_prefix"*(N/); do`,' _out="${_f#./}"',` __${e}_add_path_candidate "$_out"`,`done`];return t===`extensions`?(r.push(`local _ext`),r.push(`for _f in "$_dir"/"$_prefix"*(N.); do`),r.push(' _out="${_f#./}"'),r.push(' for _ext in "${_exts[@]}"; do'),r.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${e}_add_path_candidate "$_out"; break; }`),r.push(` done`),r.push(`done`)):(r.push(`local _pat`),r.push('for _pat in "${_matchers[@]}"; do'),r.push(` [[ -n "$_pat" ]] || continue`),r.push(' for _f in "$_dir"/${~_pat}(N.); do'),r.push(' _out="${_f#./}"'),r.push(` [[ "$_out" == "$_cur"* ]] && __${e}_add_path_candidate "$_out"`),r.push(` done`),r.push(`done`)),r}function Yt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`zshValueLines: expand variant requires a location`);let e=k(t,n.funcSuffix,n.fieldName),r=n.resolvedDeps.map(e=>e.isGlobal?`"\${_global_arg_values[${e.name}]:-}"`:`"\${_arg_values[${e.name}]:-}"`).join(`$'\\x1f'`),i=D(n.fieldName),a=n.isGlobal?`\${_global_used_field_keys[${i}]:-}`:`\${_used_field_keys[${i}]:-}`,o=n.isArrayOption?[` if [[ -n "$_ck" && " ${a} " == *" $_ck "* ]]; then continue; fi`]:[];return[`local _key=${r}`,`local _raw="\${${e}[$_key]:-}"`,`if [[ -n "$_raw" ]]; then`,' local -a _candidates=("${(@f)_raw}")',` _vals=()`,` local _c _ck _cke _vp _seen_keys=" " _desc _has_eq=0 _tmp`,' for _c in "${_candidates[@]}"; do',` _tmp="\${_c//\\\\:/$'\\x01'}"`,' _vp="${_tmp%%:*}"',` if [[ "$_vp" == *=* ]]; then`,' _cke="${_c%%=*}"',' _ck="${_cke//\\\\:/:}"',...o,' if [[ "${words[CURRENT]}" != *=* ]]; then',` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,` if [[ "$_tmp" == *:* ]]; then`,` _desc="\${\${_tmp#*:}//$'\\x01'/\\\\:}"`,' _c="${_cke}=:$_desc"',` else`,' _c="${_cke}="',` fi`,` _has_eq=1`,` else`,` [[ "$_vp" == *=?* ]] || continue`,` fi`,` fi`,` _vals+=("$_c")`,` done`,` if (( _has_eq )); then`,` __${t}_cdescribe 'completions' _vals -S ''`,` else`,` __${t}_cdescribe 'completions' _vals`,` fi`,`fi`]}case`dynamic`:return[`__${t}_apply_dynamic_output "$(__${t}_invoke_complete zsh "\${(@)words[2,CURRENT]}")"`];case`choices`:return[`_vals=(${e.choices.map(e=>`"${Q(e)}"`).join(` `)})`,`__${t}_cdescribe 'completions' _vals`];case`file`:return e.matcher?.length?Jt(t,`matchers`,e.matcher):e.extensions?.length?Jt(t,`extensions`,e.extensions):[`_files`];case`directory`:return[`_files -/`];case`command`:return[`_vals=("\${(@f)$(${e.shellCommand})}")`,`__${t}_cdescribe 'completions' _vals`];case`none`:return[];case`runtime-expand`:return[]}}function Xt(e,t,n,r){let i=[];for(let a of e){if(!a.takesValue||!a.valueCompletion)continue;let o=Yt(a.valueCompletion,n,{funcSuffix:r,...d(a,e,t)});if(o.length===0)continue;let s=P(a,e);if(s.length!==0){i.push(` ${s.join(`|`)})`);for(let e of o)i.push(` ${e}`);i.push(` return 0 ;;`)}}return i}function $(e,t,n,r=[]){if(e.length===0)return[];let i=[];i.push(` case "$_pos_count" in`);for(let a of e){a.variadic?i.push(` ${a.position}|*)`):i.push(` ${a.position})`);let o=Yt(a.valueCompletion,t,{funcSuffix:n,..._(a,r,e)});for(let e of o)i.push(` ${e}`);i.push(` ;;`)}return i.push(` esac`),i}function Zt(e,t,n,r,i){let a=[`local -a _subs=(${e.map(e=>{let t=e.description?`:${Q(e.description)}`:``;return`"${e.name}${t}"`}).join(` `)})`,`__${n}_cdescribe 'subcommands' _subs`];return t.length===0?a:[`local -a _sub_names=(${e.map(e=>`"${Kt(e.name)}"`).join(` `)})`,'local _cur_word="${words[CURRENT]:-}" _sub_name _sub_match=0','for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur_word"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...$(t,n,r,i),`fi`]}function Qt(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=Xt(e,t,n,r);return i.length===0?[]:[' case "${words[CURRENT-1]}" in',...i,` esac`]}function $t(e,t){let n=[];for(let r of e){let i=r.description?`:${Q(r.description)}`:``;if(r.valueType===`array`){n.push(` _opts+=("--${r.cliName}${i}")`);continue}let a=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?`:${Q(r.negationDescription)}`:i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o} && _opts+=("--${e.name}${e.desc}")`)}return n.push(` __${t}_not_used "--help" && _opts+=("--help:Show help")`),n}function en(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...en(e,t,r));s.push(`${a}() {`),s.push(` local -a _vals=()`),s.push(...Qt(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if __${t}_opt_takes_value "${c}" "\${words[CURRENT-1]}"; then return 0; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...$(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return 0`),s.push(` fi`)):s.push(` if (( _after_dd )); then return 0; fi`),s.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),s.push(` local -a _opts=()`),s.push(...$t(e.options,t)),s.push(` __${t}_cdescribe 'options' _opts`),s.push(` return 0`),s.push(` fi`),o.length>0){let n=j(e.subcommands);s.push(...Zt(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...$(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function tn(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=o?`_${a}_completions`:`_${n}`,c=`"\${funcstack[1]:-}" == "${Kt(s)}"`,u=r.command,d=A(u.subcommands),f=je(u),p=Ne(u,f,r.globalOptions),h=f.length>0,g=f.filter(e=>e.isArrayOption),_=g.length>0,v=[];o||(v.push(`#compdef ${n}`),v.push(``)),v.push(...z({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),v.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&v.push(`# politty-completion-worker: true`),v.push(`# Generated by politty`),v.push(``),o||v.push(...ze({programName:n,binPath:t.binPath}));for(let e of f){let t=k(a,e.funcSuffix,e.fieldName);if(e.vc.table.length===0)v.push(`typeset -gA ${t}=()`);else{v.push(`typeset -gA ${t}=(`);for(let t of e.vc.table){let e=t.key.join(``),n=t.candidates.map(e=>{let t=Gt(e.value);return e.description?`${t}:${e.description}`:t}).join(`
|
|
99
|
+
`);v.push(` ${l(e)} ${l(n)}`)}v.push(`)`)}v.push(``)}F(u)&&(v.push(...ge(a,n)),v.push(``),v.push(`__${a}_apply_dynamic_output() {`),v.push(` local _raw="$1"`),v.push(` local _directive=0`),v.push(` local -a _vals _lines`),v.push(' _lines=("${(@f)_raw}")'),v.push(` local _last=$#_lines`),v.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<-> ]]; then'),v.push(' _directive="${_lines[$_last]#:}"'),v.push(` _lines[$_last]=()`),v.push(` fi`),v.push(` local _l`),v.push(' for _l in "${_lines[@]}"; do'),v.push(` [[ -z "$_l" ]] && continue`),v.push(` _vals+=("$_l")`),v.push(` done`),v.push(" if (( ${#_vals[@]} > 0 )); then"),v.push(` if (( _directive & ${m.NoSpace} )); then`),v.push(` __${a}_cdescribe 'completions' _vals -S ''`),v.push(` else`),v.push(` __${a}_cdescribe 'completions' _vals`),v.push(` fi`),v.push(` fi`),v.push(` if (( _directive & ${m.DirectoryCompletion} )); then`),v.push(` _files -/`),v.push(` elif (( _directive & ${m.FileCompletion} )); then`),v.push(` _files`),v.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${m.NoFileCompletion} )); then`),v.push(` _files`),v.push(` fi`),v.push(`}`),v.push(``)),v.push(`__${a}_not_used() {`),v.push(` local _u _chk`),v.push(' for _u in "${_used_opts[@]}"; do'),v.push(` for _chk in "$@"; do`),v.push(` [[ "$_u" == "$_chk" ]] && return 1`),v.push(` done`),v.push(` done`),v.push(` return 0`),v.push(`}`),v.push(``),v.push(`__${a}_cdescribe() {`),v.push(` _describe "$@" 2>/dev/null && return 0`),v.push(` shift`),v.push(` local _cd_arr="$1"`),v.push(` shift`),v.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),v.push(` compadd "$@" -a _cd_vals 2>/dev/null`),v.push(` return 0`),v.push(`}`),v.push(``),v.push(`__${a}_add_path_candidate() {`),v.push(` compadd -f -- "$1" 2>/dev/null && return 0`),v.push(` print -r -- "$1"`),v.push(`}`),v.push(``),v.push(`__${a}_opt_takes_value() {`),v.push(` case "$1:$2" in`),v.push(...we(u,``)),v.push(` esac`),v.push(` return 1`),v.push(`}`),v.push(``),h&&(v.push(`__${a}_track_opt() {`),v.push(` case "$1:$2" in`),v.push(...Oe(p,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``),v.push(`__${a}_track_pos() {`),v.push(` case "$1:$2" in`),v.push(...ke(p,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``)),_&&(v.push(`__${a}_track_array_expand() {`),v.push(` case "$1:$2" in`),v.push(...Ae(g,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``));let y=N(u);y.length>0&&(v.push(`__${a}_is_subcmd() {`),v.push(` case "$1:$2" in`),v.push(...Te(y)),v.push(` esac`),v.push(` return 1`),v.push(`}`),v.push(``));for(let e of d)v.push(...en(e,a,[]));if(v.push(`__${a}_complete_root() {`),v.push(` local -a _vals=()`),v.push(...Qt(u.options,u.positionals,a,`root`)),v.push(` if __${a}_opt_takes_value "" "\${words[CURRENT-1]}"; then return 0; fi`),u.positionals.length>0?(v.push(` if (( _after_dd )); then`),v.push(...$(u.positionals,a,`root`,u.options).map(e=>` ${e}`)),v.push(` return 0`),v.push(` fi`)):v.push(` if (( _after_dd )); then return 0; fi`),v.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),v.push(` local -a _opts=()`),v.push(...$t(u.options,a)),v.push(` __${a}_cdescribe 'options' _opts`),d.length>0){v.push(` else`);let e=j(u.subcommands);v.push(...Zt(e,u.positionals,a,`root`,u.options).map(e=>` ${e}`))}else u.positionals.length>0&&(v.push(` else`),v.push(...$(u.positionals,a,`root`,u.options).map(e=>` ${e}`)));v.push(` fi`),v.push(`}`),v.push(``);let ee=Ee(y,a).join(`
|
|
100
|
+
`);v.push(`${s}() {`),v.push(" (( CURRENT )) || CURRENT=${#words}"),v.push(``),v.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),v.push(` local -a _used_opts=()`),h&&(v.push(` local -A _arg_values=()`),v.push(` local -A _global_arg_values=()`)),_&&(v.push(` local -A _used_field_keys=()`),v.push(` local -A _global_used_field_keys=()`),v.push(` local -A _global_arr_seen=()`)),v.push(``),v.push(` local _j=2`),v.push(` while (( _j < CURRENT )); do`),v.push(' local _w="${words[_j]}"'),v.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),v.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=h?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;v.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),v.push(` if [[ "$_w" == -*=* ]]; then`),v.push(' _used_opts+=("${_w%%=*}")'),h&&(v.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),_&&v.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),v.push(` (( _j++ )); continue`),v.push(` fi`),v.push(` if [[ "$_w" == -* ]]; then`),v.push(` _used_opts+=("$_w")`),v.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),v.push(' local _next="${words[_j+1]:-}"'),v.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),h&&(v.push(` if (( _skip_next )); then`),v.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),_&&(v.push(` if (( _j + 1 < CURRENT )); then`),v.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),v.push(` fi`)),v.push(` fi`)),v.push(` fi`),v.push(` (( _j++ )); continue`),v.push(` fi`);let x=_?`; _arg_values=(); _used_field_keys=(); _global_arr_seen=()`:h?`; _arg_values=()`:``,S=h?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;return y.length>0?v.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${x}; else ${S}(( _pos_count++ )); fi`):(h&&v.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),v.push(` (( _pos_count++ ))`)),v.push(` (( _j++ ))`),v.push(` done`),v.push(``),v.push(` case "$_subcmd" in`),v.push(ee),v.push(` *) __${a}_complete_root ;;`),v.push(` esac`),v.push(`}`),v.push(``),v.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),v.push(``),o||(v.push(`if [[ ${c} ]]; then`),v.push(` ${s} "$@"`),v.push(`else`),v.push(` compdef ${s} ${n}`),v.push(`fi`),v.push(``)),{script:v.join(`
|
|
101
|
+
`),shell:`zsh`,installInstructions:`# To enable auto-refreshing zsh completions, add this to your ~/.zshrc after compinit:
|
|
102
|
+
eval "$(${n} completion zsh --static)"
|
|
103
|
+
|
|
104
|
+
# For faster shell startup, save the script in your fpath:
|
|
105
|
+
mkdir -p ~/.zsh/completions
|
|
106
|
+
${n} completion zsh --static > ~/.zsh/completions/_${n}
|
|
107
|
+
|
|
108
|
+
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
109
|
+
fpath=(~/.zsh/completions $fpath)
|
|
110
|
+
autoload -Uz compinit && compinit
|
|
111
|
+
|
|
112
|
+
# If ~/.zshrc already calls compinit, add only the fpath line before
|
|
113
|
+
# the existing compinit call.
|
|
114
|
+
|
|
115
|
+
# Then reload your shell or run:
|
|
116
|
+
source ~/.zshrc`}}function nn(e,t){if(t.mode===`dispatcher`)return Ct(e,t);switch(t.shell){case`bash`:return Ye(e,t);case`zsh`:return tn(e,t);case`fish`:return Nt(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function rn(){return[`bash`,`zsh`,`fish`]}function an(e,t){console.error(``),console.error(`Configure zsh fpath with:`),console.error(``),console.error(` mkdir -p ~/.zsh/completions`),console.error(` ln -sf ${p(t)} ~/.zsh/completions/_${e}`),console.error(``),console.error(`Add only this block to your ~/.zshrc before compinit:`),console.error(``),console.error(` fpath=(~/.zsh/completions $fpath)`),console.error(` autoload -Uz compinit && compinit`)}function on(e,n,r,i={}){let o=n??e.name,{cacheDir:s,programVersion:l}=i,u={...s!==void 0&&{cacheDir:s},...l!==void 0&&{programVersion:l},...r!==void 0&&{globalArgsSchema:r},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker}},d={programName:o,...u},f={programName:o,...s!==void 0&&{cacheDir:s}};return e.subCommands?.__complete||(e.subCommands={...e.subCommands,__complete:y(e,o,r)}),e.subCommands?.[`__refresh-completion`]||(e.subCommands={...e.subCommands,"__refresh-completion":sn(e,o,u)}),e.subCommands?.[`__completion-worker-path`]||(e.subCommands={...e.subCommands,"__completion-worker-path":cn(o,u)}),t({name:`completion`,description:`Generate shell completion script`,args:a,run(t){let n=t.shell||c();if(!n){console.error(`Could not detect shell type. Please specify one of: bash, zsh, fish`),process.exitCode=1;return}if(t.static&&t.dispatcher)throw Error(`Choose only one completion mode: --dispatcher or --static.`);if(t.worker&&!t.static)throw Error("`--worker` requires `--static`.");if(t.worker&&(t.install||t.loader||t.instructions))throw Error("`--worker` can only print a worker artifact.");let a=t.static?`static`:`dispatcher`;if(t.install){let t;try{t=It({rootCommand:e,...d,completionMode:a},n)}catch(e){throw Error(`install failed: ${e instanceof Error?e.message:String(e)}`)}console.error(`installed: ${t}`),n===`bash`?(console.error(``),console.error(`Add to your ~/.${n}rc:`),console.error(``),console.error(Wt({...f,shell:n}).trim().replace(/^/gm,` `))):n===`zsh`&&an(o,t);return}if(t.loader){if(n===`fish`)throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.");process.stdout.write(Wt({...f,shell:n}));return}let u=nn(e,{shell:n,programName:o,mode:a,includeDescriptions:!0,...r!==void 0&&{globalArgsSchema:r},...l!==void 0&&{programVersion:l},...s!==void 0&&{cacheDir:s},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker},...t.worker&&{staticWorker:{functionSuffix:`worker`}}});t.instructions?console.log(u.installInstructions):console.log(u.script)}})}function sn(e,n,r={}){return t({name:`__refresh-completion`,description:`(internal) Refresh the on-disk completion cache if stale.`,args:s,run(t){Bt({rootCommand:e,programName:n,...r,completionMode:t.static||t.worker?`static`:void 0,...t.worker&&{staticWorker:{functionSuffix:`worker`}},...t.worker&&{allowTargetCreate:!0},...t.target!==void 0&&{targetPath:t.target}},t.shell)}})}function cn(e,n={}){return t({name:`__completion-worker-path`,description:`(internal) Print the bundled completion worker path when available.`,args:i,run(t){let r=ct({programName:e,shell:t.shell,...n.binPath!==void 0&&{binPath:n.binPath},...n.bundledWorker!==void 0&&{bundledWorker:n.bundledWorker}});if(!r)throw Error(`No bundled completion worker found for ${e} (${t.shell}).`);console.log(r)}})}export{rn as a,mt as c,ve as d,nn as i,U as l,cn as n,$e as o,sn as r,et as s,on as t,I as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./with-completion-command-DDohm8U6.js";import"./dynamic-CrnlveHj.js";import{c as e,n as t,r as n,t as r}from"./completion-D8DMrPqg.js";export{r as createCompletionCommand,t as createCompletionWorkerPathCommand,n as createRefreshCompletionCommand,e as generateBundledCompletionWorker};
|