politty 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/completion/index.cjs +1 -1
- package/dist/completion/index.d.cts +1 -1
- package/dist/completion/index.d.ts +1 -1
- package/dist/completion/index.js +1 -1
- package/dist/{completion-Cqs1Ja7C.cjs → completion-BFOAOg95.cjs} +167 -42
- package/dist/completion-BFOAOg95.cjs.map +1 -0
- package/dist/{completion-BA5JMvVG.js → completion-K5LGh1hO.js} +168 -43
- package/dist/completion-K5LGh1hO.js.map +1 -0
- package/dist/{index-DJp8k5Bq.d.cts → index-Cg8qstsT.d.cts} +2 -1
- package/dist/{index-DJp8k5Bq.d.cts.map → index-Cg8qstsT.d.cts.map} +1 -1
- package/dist/{index-DBMfKZ34.d.ts → index-O3yn97Ed.d.ts} +2 -1
- package/dist/{index-DBMfKZ34.d.ts.map → index-O3yn97Ed.d.ts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/dist/completion-BA5JMvVG.js.map +0 -1
- package/dist/completion-Cqs1Ja7C.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_completion = require('../completion-
|
|
2
|
+
const require_completion = require('../completion-BFOAOg95.cjs');
|
|
3
3
|
|
|
4
4
|
exports.CompletionDirective = require_completion.CompletionDirective;
|
|
5
5
|
exports.createCompletionCommand = require_completion.createCompletionCommand;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { f as CompletionDirectiveMask, g as DynamicCompletionResult, h as DynamicCompletionResolver, m as DynamicCompletionContext, p as DynamicCompletionCandidate } from "../arg-registry--NRaNFJM.cjs";
|
|
2
|
-
import { C as CompletableOption, D as CompletionOptions, E as CompletionGenerator, O as CompletionResult, S as parseCompletionContext, T as CompletionData, _ as CompletionCandidate, a as generateCompletion, b as CompletionContext, c as ValueCompletionField, d as extractPositionals, f as ShellFormatOptions, g as CandidateResult, h as hasCompleteCommand, i as detectShell, k as ShellType, l as resolveValueCompletion, m as createDynamicCompleteCommand, n as createCompletionCommand, o as getSupportedShells, p as formatForShell, r as createRefreshCompletionCommand, s as withCompletionCommand, t as WithCompletionOptions, u as extractCompletionData, v as CompletionDirective, w as CompletableSubcommand, x as CompletionType, y as generateCandidates } from "../index-
|
|
2
|
+
import { C as CompletableOption, D as CompletionOptions, E as CompletionGenerator, O as CompletionResult, S as parseCompletionContext, T as CompletionData, _ as CompletionCandidate, a as generateCompletion, b as CompletionContext, c as ValueCompletionField, d as extractPositionals, f as ShellFormatOptions, g as CandidateResult, h as hasCompleteCommand, i as detectShell, k as ShellType, l as resolveValueCompletion, m as createDynamicCompleteCommand, n as createCompletionCommand, o as getSupportedShells, p as formatForShell, r as createRefreshCompletionCommand, s as withCompletionCommand, t as WithCompletionOptions, u as extractCompletionData, v as CompletionDirective, w as CompletableSubcommand, x as CompletionType, y as generateCandidates } from "../index-Cg8qstsT.cjs";
|
|
3
3
|
export { type CandidateResult, type CompletableOption, type CompletableSubcommand, type CompletionCandidate, type CompletionContext, type CompletionData, CompletionDirective, type CompletionDirectiveMask, type CompletionGenerator, type CompletionOptions, type CompletionResult, type CompletionType, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type ShellFormatOptions, type ShellType, type ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, createRefreshCompletionCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { f as CompletionDirectiveMask, g as DynamicCompletionResult, h as DynamicCompletionResolver, m as DynamicCompletionContext, p as DynamicCompletionCandidate } from "../arg-registry-6E0WHOh_.js";
|
|
2
|
-
import { C as CompletableOption, D as CompletionOptions, E as CompletionGenerator, O as CompletionResult, S as parseCompletionContext, T as CompletionData, _ as CompletionCandidate, a as generateCompletion, b as CompletionContext, c as ValueCompletionField, d as extractPositionals, f as ShellFormatOptions, g as CandidateResult, h as hasCompleteCommand, i as detectShell, k as ShellType, l as resolveValueCompletion, m as createDynamicCompleteCommand, n as createCompletionCommand, o as getSupportedShells, p as formatForShell, r as createRefreshCompletionCommand, s as withCompletionCommand, t as WithCompletionOptions, u as extractCompletionData, v as CompletionDirective, w as CompletableSubcommand, x as CompletionType, y as generateCandidates } from "../index-
|
|
2
|
+
import { C as CompletableOption, D as CompletionOptions, E as CompletionGenerator, O as CompletionResult, S as parseCompletionContext, T as CompletionData, _ as CompletionCandidate, a as generateCompletion, b as CompletionContext, c as ValueCompletionField, d as extractPositionals, f as ShellFormatOptions, g as CandidateResult, h as hasCompleteCommand, i as detectShell, k as ShellType, l as resolveValueCompletion, m as createDynamicCompleteCommand, n as createCompletionCommand, o as getSupportedShells, p as formatForShell, r as createRefreshCompletionCommand, s as withCompletionCommand, t as WithCompletionOptions, u as extractCompletionData, v as CompletionDirective, w as CompletableSubcommand, x as CompletionType, y as generateCandidates } from "../index-O3yn97Ed.js";
|
|
3
3
|
export { type CandidateResult, type CompletableOption, type CompletableSubcommand, type CompletionCandidate, type CompletionContext, type CompletionData, CompletionDirective, type CompletionDirectiveMask, type CompletionGenerator, type CompletionOptions, type CompletionResult, type CompletionType, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type ShellFormatOptions, type ShellType, type ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, createRefreshCompletionCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
|
package/dist/completion/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as getSupportedShells, c as hasCompleteCommand, d as extractPositionals, f as CompletionDirective, h as resolveValueCompletion, i as generateCompletion, l as formatForShell, m as parseCompletionContext, n as createRefreshCompletionCommand, o as withCompletionCommand, p as generateCandidates, r as detectShell, s as createDynamicCompleteCommand, t as createCompletionCommand, u as extractCompletionData } from "../completion-
|
|
1
|
+
import { a as getSupportedShells, c as hasCompleteCommand, d as extractPositionals, f as CompletionDirective, h as resolveValueCompletion, i as generateCompletion, l as formatForShell, m as parseCompletionContext, n as createRefreshCompletionCommand, o as withCompletionCommand, p as generateCandidates, r as detectShell, s as createDynamicCompleteCommand, t as createCompletionCommand, u as extractCompletionData } from "../completion-K5LGh1hO.js";
|
|
2
2
|
|
|
3
3
|
export { CompletionDirective, createCompletionCommand, createDynamicCompleteCommand, createRefreshCompletionCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
|
|
@@ -1924,6 +1924,87 @@ function buildHeaderLines(opts) {
|
|
|
1924
1924
|
return lines;
|
|
1925
1925
|
}
|
|
1926
1926
|
|
|
1927
|
+
//#endregion
|
|
1928
|
+
//#region src/completion/self-refresh.ts
|
|
1929
|
+
/**
|
|
1930
|
+
* Self-refresh guards embedded in generated bash/zsh scripts.
|
|
1931
|
+
*
|
|
1932
|
+
* These guards make the default `completion <shell>` output safe to
|
|
1933
|
+
* save as a static completion file: when the CLI binary changes, the
|
|
1934
|
+
* script asks the hidden refresh subcommand to rewrite the sourced
|
|
1935
|
+
* file in place, then sources the fresh file and stops executing the
|
|
1936
|
+
* stale body.
|
|
1937
|
+
*/
|
|
1938
|
+
function statSigExpr() {
|
|
1939
|
+
return `$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null)`;
|
|
1940
|
+
}
|
|
1941
|
+
function generateBashSelfRefresh(opts) {
|
|
1942
|
+
const { programName, binPath } = opts;
|
|
1943
|
+
const fn = sanitize(programName);
|
|
1944
|
+
const sig = computeBinSig(resolveBinPath(programName, binPath));
|
|
1945
|
+
const refreshFn = `__${fn}_self_refresh`;
|
|
1946
|
+
return [
|
|
1947
|
+
`${refreshFn}() {`,
|
|
1948
|
+
` local _self _bin _sig`,
|
|
1949
|
+
` _self=\${BASH_SOURCE[0]:-}`,
|
|
1950
|
+
` [[ -n "$_self" && -f "$_self" ]] || return 1`,
|
|
1951
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,
|
|
1952
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# program: ${programName}" || return 1`,
|
|
1953
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# shell: bash" || return 1`,
|
|
1954
|
+
` _bin=$(type -P ${programName} 2>/dev/null)`,
|
|
1955
|
+
` [[ -n "$_bin" ]] || return 1`,
|
|
1956
|
+
` _sig=${statSigExpr()} || return 1`,
|
|
1957
|
+
` [[ "$_sig" != "${sig}" ]] || return 1`,
|
|
1958
|
+
` "$_bin" __refresh-completion bash "$_self" 2>/dev/null || return 1`,
|
|
1959
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-bin-sig: $_sig" || return 1`,
|
|
1960
|
+
` source "$_self" 2>/dev/null || return 1`,
|
|
1961
|
+
` return 0`,
|
|
1962
|
+
`}`,
|
|
1963
|
+
`if ${refreshFn}; then`,
|
|
1964
|
+
` unset -f ${refreshFn}`,
|
|
1965
|
+
` return 0 2>/dev/null || true`,
|
|
1966
|
+
`else`,
|
|
1967
|
+
` unset -f ${refreshFn}`,
|
|
1968
|
+
`fi`,
|
|
1969
|
+
``
|
|
1970
|
+
];
|
|
1971
|
+
}
|
|
1972
|
+
function generateZshSelfRefresh(opts) {
|
|
1973
|
+
const { programName, binPath } = opts;
|
|
1974
|
+
const fn = sanitize(programName);
|
|
1975
|
+
const completionFn = `_${programName}`;
|
|
1976
|
+
const sig = computeBinSig(resolveBinPath(programName, binPath));
|
|
1977
|
+
const refreshFn = `__${fn}_self_refresh`;
|
|
1978
|
+
return [
|
|
1979
|
+
`${refreshFn}() {`,
|
|
1980
|
+
` emulate -L zsh`,
|
|
1981
|
+
` setopt local_options no_aliases`,
|
|
1982
|
+
` local _self _bin _sig`,
|
|
1983
|
+
` _self="\${(%):-%x}"`,
|
|
1984
|
+
` [[ -n "$_self" && -f "$_self" ]] || return 1`,
|
|
1985
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,
|
|
1986
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# program: ${programName}" || return 1`,
|
|
1987
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# shell: zsh" || return 1`,
|
|
1988
|
+
` _bin=$(whence -p ${programName} 2>/dev/null)`,
|
|
1989
|
+
` [[ -n "$_bin" ]] || return 1`,
|
|
1990
|
+
` _sig=${statSigExpr()} || return 1`,
|
|
1991
|
+
` [[ "$_sig" != "${sig}" ]] || return 1`,
|
|
1992
|
+
` "$_bin" __refresh-completion zsh "$_self" 2>/dev/null || return 1`,
|
|
1993
|
+
` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-bin-sig: $_sig" || return 1`,
|
|
1994
|
+
` source "$_self" 2>/dev/null || return 1`,
|
|
1995
|
+
` ${completionFn} "$@"`,
|
|
1996
|
+
` return 0`,
|
|
1997
|
+
`}`,
|
|
1998
|
+
`if ${refreshFn} "$@"; then`,
|
|
1999
|
+
` unfunction ${refreshFn} 2>/dev/null`,
|
|
2000
|
+
` return 0 2>/dev/null || true`,
|
|
2001
|
+
`else`,
|
|
2002
|
+
` unfunction ${refreshFn} 2>/dev/null`,
|
|
2003
|
+
`fi`,
|
|
2004
|
+
``
|
|
2005
|
+
];
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1927
2008
|
//#endregion
|
|
1928
2009
|
//#region src/completion/bash.ts
|
|
1929
2010
|
/** Escape a string for use inside bash double-quotes */
|
|
@@ -2186,6 +2267,10 @@ function generateBashCompletion(command, options) {
|
|
|
2186
2267
|
}));
|
|
2187
2268
|
lines.push(`# Generated by politty`);
|
|
2188
2269
|
lines.push(``);
|
|
2270
|
+
lines.push(...generateBashSelfRefresh({
|
|
2271
|
+
programName,
|
|
2272
|
+
binPath: options.binPath
|
|
2273
|
+
}));
|
|
2189
2274
|
const hasExpand = expandSpecs.length > 0;
|
|
2190
2275
|
const arrayExpandSpecs = expandSpecs.filter((s) => s.isArrayOption);
|
|
2191
2276
|
const hasArrayExpand = arrayExpandSpecs.length > 0;
|
|
@@ -2430,12 +2515,11 @@ function generateBashCompletion(command, options) {
|
|
|
2430
2515
|
return {
|
|
2431
2516
|
script: lines.join("\n"),
|
|
2432
2517
|
shell: "bash",
|
|
2433
|
-
installInstructions: `# To enable completions, add
|
|
2434
|
-
|
|
2435
|
-
# Option 1: Source directly
|
|
2518
|
+
installInstructions: `# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
2436
2519
|
eval "$(${programName} completion bash)"
|
|
2437
2520
|
|
|
2438
|
-
#
|
|
2521
|
+
# For faster shell startup, save the script instead:
|
|
2522
|
+
mkdir -p ~/.local/share/bash-completion/completions
|
|
2439
2523
|
${programName} completion bash > ~/.local/share/bash-completion/completions/${programName}
|
|
2440
2524
|
|
|
2441
2525
|
# Then reload your shell or run:
|
|
@@ -2819,8 +2903,9 @@ function generateFishCompletion(command, options) {
|
|
|
2819
2903
|
lines.push(` test -z "$_bin"; and return 1`);
|
|
2820
2904
|
lines.push(` set -l _sig (stat -L -c '%Y' "$_bin" 2>/dev/null; or stat -L -f '%m' "$_bin" 2>/dev/null)`);
|
|
2821
2905
|
lines.push(` test "$_sig" = "${sig}"; and return 1`);
|
|
2822
|
-
lines.push(` set -l _target
|
|
2823
|
-
lines.push(` "$
|
|
2906
|
+
lines.push(` set -l _target (status current-filename)`);
|
|
2907
|
+
lines.push(` test -n "$_target"; and test -f "$_target"; or return 1`);
|
|
2908
|
+
lines.push(` "$_bin" __refresh-completion fish "$_target" 2>/dev/null`);
|
|
2824
2909
|
lines.push(` and source "$_target" 2>/dev/null`);
|
|
2825
2910
|
lines.push(` and return 0`);
|
|
2826
2911
|
lines.push(` return 1`);
|
|
@@ -3097,17 +3182,8 @@ function generateFishCompletion(command, options) {
|
|
|
3097
3182
|
return {
|
|
3098
3183
|
script: lines.join("\n"),
|
|
3099
3184
|
shell: "fish",
|
|
3100
|
-
installInstructions: `# To enable completions, run
|
|
3101
|
-
|
|
3102
|
-
# Option 1: Source directly
|
|
3103
|
-
${programName} completion fish | source
|
|
3104
|
-
|
|
3105
|
-
# Option 2: Save to the fish completions directory
|
|
3106
|
-
${programName} completion fish > ~/.config/fish/completions/${programName}.fish
|
|
3107
|
-
|
|
3108
|
-
# The completion will be available immediately in new shell sessions.
|
|
3109
|
-
# To use in the current session, run:
|
|
3110
|
-
source ~/.config/fish/completions/${programName}.fish`
|
|
3185
|
+
installInstructions: `# To enable auto-refreshing fish completions, run:
|
|
3186
|
+
${programName} completion fish --install`
|
|
3111
3187
|
};
|
|
3112
3188
|
}
|
|
3113
3189
|
|
|
@@ -3136,11 +3212,11 @@ source ~/.config/fish/completions/${programName}.fish`
|
|
|
3136
3212
|
* from env / config — we must not let metachars in the path execute as
|
|
3137
3213
|
* commands when the rc snippet is sourced.
|
|
3138
3214
|
*/
|
|
3139
|
-
function shSingleQuote(s) {
|
|
3215
|
+
function shSingleQuote$1(s) {
|
|
3140
3216
|
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
3141
3217
|
}
|
|
3142
3218
|
function bashCachePathExpr(programName, cacheDir, shell) {
|
|
3143
|
-
if (cacheDir) return shSingleQuote(`${cacheDir}/completion.${shell}`);
|
|
3219
|
+
if (cacheDir) return shSingleQuote$1(`${cacheDir}/completion.${shell}`);
|
|
3144
3220
|
return `"\${XDG_CACHE_HOME:-$HOME/.cache}/${programName}/completion.${shell}"`;
|
|
3145
3221
|
}
|
|
3146
3222
|
function generateBashLoader(opts) {
|
|
@@ -3284,6 +3360,15 @@ function readCachedSig(path) {
|
|
|
3284
3360
|
return null;
|
|
3285
3361
|
}
|
|
3286
3362
|
}
|
|
3363
|
+
function isManagedTarget(path, programName, shell) {
|
|
3364
|
+
try {
|
|
3365
|
+
if (!(0, node_fs.existsSync)(path)) return false;
|
|
3366
|
+
const head = (0, node_fs.readFileSync)(path, "utf8").split("\n", 8).join("\n");
|
|
3367
|
+
return /^# politty-completion-version: \S+/m.test(head) && head.includes(`# program: ${programName}`) && head.includes(`# shell: ${shell}`);
|
|
3368
|
+
} catch {
|
|
3369
|
+
return false;
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3287
3372
|
/**
|
|
3288
3373
|
* Rewrite the cache only when stale. Used by:
|
|
3289
3374
|
* - `<program> __refresh-completion <shell>` (the hidden subcommand
|
|
@@ -3299,7 +3384,8 @@ function readCachedSig(path) {
|
|
|
3299
3384
|
*/
|
|
3300
3385
|
function refreshIfStale(ctx, shell) {
|
|
3301
3386
|
try {
|
|
3302
|
-
const target = installPath(ctx.programName, shell, ctx.cacheDir);
|
|
3387
|
+
const target = ctx.targetPath ? (0, node_fs.realpathSync)(ctx.targetPath) : installPath(ctx.programName, shell, ctx.cacheDir);
|
|
3388
|
+
if (ctx.targetPath && !isManagedTarget(target, ctx.programName, shell)) return;
|
|
3303
3389
|
const binPath = resolveBinPath(ctx.programName, ctx.binPath);
|
|
3304
3390
|
if (!binPath) return;
|
|
3305
3391
|
let currentSig;
|
|
@@ -3361,6 +3447,10 @@ function escapeDesc(s) {
|
|
|
3361
3447
|
function escapeDescribeValue(s) {
|
|
3362
3448
|
return s.replace(/\\/g, "\\\\").replace(/:/g, "\\:");
|
|
3363
3449
|
}
|
|
3450
|
+
/** Escape a string for use inside zsh double-quotes. */
|
|
3451
|
+
function escapeZshDQ(s) {
|
|
3452
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\$/g, "\\$").replace(/`/g, "\\`");
|
|
3453
|
+
}
|
|
3364
3454
|
/**
|
|
3365
3455
|
* Generate zsh value completion lines for a ValueCompletion spec.
|
|
3366
3456
|
* Uses `_vals` array (must be declared in the calling function scope).
|
|
@@ -3547,6 +3637,8 @@ function generateZshCompletion(command, options) {
|
|
|
3547
3637
|
const { programName } = options;
|
|
3548
3638
|
const data = extractCompletionData(command, programName, options.globalArgsSchema);
|
|
3549
3639
|
const fn = sanitize(programName);
|
|
3640
|
+
const completionFn = `_${programName}`;
|
|
3641
|
+
const autoloadCheck = `"\${funcstack[1]:-}" == "${escapeZshDQ(completionFn)}"`;
|
|
3550
3642
|
const root = data.command;
|
|
3551
3643
|
const visibleSubs = getVisibleSubs(root.subcommands);
|
|
3552
3644
|
const expandSpecs = collectExpandSpecs(root);
|
|
@@ -3565,6 +3657,10 @@ function generateZshCompletion(command, options) {
|
|
|
3565
3657
|
}));
|
|
3566
3658
|
lines.push(`# Generated by politty`);
|
|
3567
3659
|
lines.push(``);
|
|
3660
|
+
lines.push(...generateZshSelfRefresh({
|
|
3661
|
+
programName,
|
|
3662
|
+
binPath: options.binPath
|
|
3663
|
+
}));
|
|
3568
3664
|
for (const spec of expandSpecs) {
|
|
3569
3665
|
const varName = expandTableVarName(fn, spec.funcSuffix, spec.fieldName);
|
|
3570
3666
|
if (spec.vc.table.length === 0) lines.push(`typeset -gA ${varName}=()`);
|
|
@@ -3707,7 +3803,7 @@ function generateZshCompletion(command, options) {
|
|
|
3707
3803
|
lines.push(`}`);
|
|
3708
3804
|
lines.push(``);
|
|
3709
3805
|
const subRouting = subDispatchCaseLines(routeEntries, fn).join("\n");
|
|
3710
|
-
lines.push(
|
|
3806
|
+
lines.push(`${completionFn}() {`);
|
|
3711
3807
|
lines.push(` (( CURRENT )) || CURRENT=\${#words}`);
|
|
3712
3808
|
lines.push(``);
|
|
3713
3809
|
lines.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`);
|
|
@@ -3773,22 +3869,28 @@ function generateZshCompletion(command, options) {
|
|
|
3773
3869
|
lines.push(``);
|
|
3774
3870
|
lines.push(`zstyle ':completion:*:*:${programName}:*' file-patterns '%p:globbed-files *(-/):directories'`);
|
|
3775
3871
|
lines.push(``);
|
|
3776
|
-
lines.push(`
|
|
3872
|
+
lines.push(`if [[ ${autoloadCheck} ]]; then`);
|
|
3873
|
+
lines.push(` ${completionFn} "$@"`);
|
|
3874
|
+
lines.push(`else`);
|
|
3875
|
+
lines.push(` compdef ${completionFn} ${programName}`);
|
|
3876
|
+
lines.push(`fi`);
|
|
3777
3877
|
lines.push(``);
|
|
3778
3878
|
return {
|
|
3779
3879
|
script: lines.join("\n"),
|
|
3780
3880
|
shell: "zsh",
|
|
3781
|
-
installInstructions: `# To enable completions, add
|
|
3782
|
-
|
|
3783
|
-
# Option 1: Source directly (add before compinit)
|
|
3881
|
+
installInstructions: `# To enable auto-refreshing zsh completions, add this to your ~/.zshrc after compinit:
|
|
3784
3882
|
eval "$(${programName} completion zsh)"
|
|
3785
3883
|
|
|
3786
|
-
#
|
|
3884
|
+
# For faster shell startup, save the script in your fpath:
|
|
3885
|
+
mkdir -p ~/.zsh/completions
|
|
3787
3886
|
${programName} completion zsh > ~/.zsh/completions/_${programName}
|
|
3788
3887
|
|
|
3789
|
-
# Make sure your
|
|
3790
|
-
|
|
3791
|
-
|
|
3888
|
+
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
3889
|
+
fpath=(~/.zsh/completions $fpath)
|
|
3890
|
+
autoload -Uz compinit && compinit
|
|
3891
|
+
|
|
3892
|
+
# If ~/.zshrc already calls compinit, add only the fpath line before
|
|
3893
|
+
# the existing compinit call.
|
|
3792
3894
|
|
|
3793
3895
|
# Then reload your shell or run:
|
|
3794
3896
|
source ~/.zshrc`
|
|
@@ -3843,6 +3945,21 @@ function getSupportedShells() {
|
|
|
3843
3945
|
"fish"
|
|
3844
3946
|
];
|
|
3845
3947
|
}
|
|
3948
|
+
function shSingleQuote(s) {
|
|
3949
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
3950
|
+
}
|
|
3951
|
+
function printZshFpathSetup(programName, target) {
|
|
3952
|
+
console.error("");
|
|
3953
|
+
console.error("Configure zsh fpath with:");
|
|
3954
|
+
console.error("");
|
|
3955
|
+
console.error(" mkdir -p ~/.zsh/completions");
|
|
3956
|
+
console.error(` ln -sf ${shSingleQuote(target)} ~/.zsh/completions/_${programName}`);
|
|
3957
|
+
console.error("");
|
|
3958
|
+
console.error("Add only this block to your ~/.zshrc before compinit:");
|
|
3959
|
+
console.error("");
|
|
3960
|
+
console.error(" fpath=(~/.zsh/completions $fpath)");
|
|
3961
|
+
console.error(" autoload -Uz compinit && compinit");
|
|
3962
|
+
}
|
|
3846
3963
|
/**
|
|
3847
3964
|
* Detect the current shell from environment
|
|
3848
3965
|
*/
|
|
@@ -3873,15 +3990,22 @@ const completionArgsSchema = zod.z.object({
|
|
|
3873
3990
|
loader: require_schema_extractor.arg(zod.z.boolean().default(false), { description: "Print just the rc loader snippet (bash/zsh). Add it to ~/.bashrc or ~/.zshrc; it auto-regenerates the cache when the binary changes." }),
|
|
3874
3991
|
install: require_schema_extractor.arg(zod.z.boolean().default(false), { description: "Write the completion script to its on-disk cache (bash/zsh) or autoload location (fish) instead of printing it." })
|
|
3875
3992
|
});
|
|
3876
|
-
const refreshArgsSchema = zod.z.object({
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3993
|
+
const refreshArgsSchema = zod.z.object({
|
|
3994
|
+
shell: require_schema_extractor.arg(zod.z.enum([
|
|
3995
|
+
"bash",
|
|
3996
|
+
"zsh",
|
|
3997
|
+
"fish"
|
|
3998
|
+
]), {
|
|
3999
|
+
positional: true,
|
|
4000
|
+
description: "Shell to refresh",
|
|
4001
|
+
placeholder: "SHELL"
|
|
4002
|
+
}),
|
|
4003
|
+
target: require_schema_extractor.arg(zod.z.string().optional(), {
|
|
4004
|
+
positional: true,
|
|
4005
|
+
description: "Existing politty-generated completion file to refresh",
|
|
4006
|
+
placeholder: "TARGET"
|
|
4007
|
+
})
|
|
4008
|
+
});
|
|
3885
4009
|
/**
|
|
3886
4010
|
* Create a completion subcommand for your CLI
|
|
3887
4011
|
*
|
|
@@ -3943,7 +4067,7 @@ function createCompletionCommand(rootCommand, programName, globalArgsSchema, ext
|
|
|
3943
4067
|
throw new Error(`install failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
3944
4068
|
}
|
|
3945
4069
|
console.error(`installed: ${target}`);
|
|
3946
|
-
if (shellType
|
|
4070
|
+
if (shellType === "bash") {
|
|
3947
4071
|
console.error("");
|
|
3948
4072
|
console.error(`Add to your ~/.${shellType}rc:`);
|
|
3949
4073
|
console.error("");
|
|
@@ -3951,7 +4075,7 @@ function createCompletionCommand(rootCommand, programName, globalArgsSchema, ext
|
|
|
3951
4075
|
...loaderOptsBase,
|
|
3952
4076
|
shell: shellType
|
|
3953
4077
|
}).trim().replace(/^/gm, " "));
|
|
3954
|
-
}
|
|
4078
|
+
} else if (shellType === "zsh") printZshFpathSetup(resolvedProgramName, target);
|
|
3955
4079
|
return;
|
|
3956
4080
|
}
|
|
3957
4081
|
if (args.loader) {
|
|
@@ -3989,7 +4113,8 @@ function createRefreshCompletionCommand(rootCommand, programName, extra = {}) {
|
|
|
3989
4113
|
refreshIfStale({
|
|
3990
4114
|
rootCommand,
|
|
3991
4115
|
programName,
|
|
3992
|
-
...extra
|
|
4116
|
+
...extra,
|
|
4117
|
+
...args.target !== void 0 && { targetPath: args.target }
|
|
3993
4118
|
}, args.shell);
|
|
3994
4119
|
}
|
|
3995
4120
|
});
|
|
@@ -4166,4 +4291,4 @@ Object.defineProperty(exports, 'withCompletionCommand', {
|
|
|
4166
4291
|
return withCompletionCommand;
|
|
4167
4292
|
}
|
|
4168
4293
|
});
|
|
4169
|
-
//# sourceMappingURL=completion-
|
|
4294
|
+
//# sourceMappingURL=completion-BFOAOg95.cjs.map
|