@bomb.sh/tab 0.0.12 → 0.0.13
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/bin/cli.js +1 -1
- package/dist/{cac.d.ts → cac-C7ZgM1oP.d.ts} +2 -2
- package/dist/cac.js +1 -1
- package/dist/{citty.d.ts → citty-CqlIQqSR.d.ts} +2 -2
- package/dist/citty.js +1 -1
- package/dist/{commander.d.ts → commander-B_9OxySh.d.ts} +1 -1
- package/dist/commander.js +1 -1
- package/dist/{t-DYl0qC9V.js → powershell-BbJLZFR-.js} +163 -163
- package/dist/{shared-Bzh57-vW.d.ts → shared-Cst8Kh7c.d.ts} +1 -1
- package/dist/{t-Cao2EVMz.d.ts → t-D9C2bp96.d.ts} +1 -1
- package/dist/t.js +1 -1
- package/package.json +3 -3
- package/dist/t.d.ts +0 -2
- /package/dist/bin/{cli.d.ts → cli-DhDIpcdm.d.ts} +0 -0
- /package/dist/{shared-BE1U9MBi.js → shared-Botddo9c.js} +0 -0
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import"../powershell-BbJLZFR-.js";import{RootCommand as e,script as t}from"../t.js";import{readFileSync as n}from"node:fs";import{promisify as r}from"node:util";import i from"node:child_process";import{readFileSync as a}from"fs";import{spawnSync as o}from"child_process";function s(){try{let e;try{e=n(`pnpm-workspace.yaml`,`utf8`)}catch{e=n(`pnpm-workspace.yml`,`utf8`)}let t=e.match(/packages:\s*\n((?:\s*-\s*.+\n?)*)/);return t?t[1].split(`
|
|
3
3
|
`).map(e=>e.trim()).filter(e=>e.startsWith(`-`)).map(e=>e.substring(1).trim()).filter(e=>e&&!e.startsWith(`#`)):[]}catch{return[]}}function c(){try{let e=JSON.parse(a(`package.json`,`utf8`));return Object.keys(e.scripts||{})}catch{return[]}}function l(){try{let e=JSON.parse(a(`package.json`,`utf8`)),t={...e.dependencies,...e.devDependencies,...e.peerDependencies,...e.optionalDependencies};return Object.keys(t)}catch{return[]}}const ee=async e=>{c().forEach(t=>{e(t.replace(/:/g,`\\:`),` `)})},te=async e=>{l().forEach(t=>e(t,``))},ne=r(i.exec),{execSync:re}=i,u={workspace(e){s().forEach(t=>e(t,`Workspace pattern: ${t}`))}};function d(e,t,n,r){e._lazyCommand=t,e._optionsLoaded=!1;let i=e.options;e.optionsRaw=i,Object.defineProperty(e,`options`,{get(){return this._optionsLoaded||(this._optionsLoaded=!0,r(this,this._lazyCommand)),i},configurable:!0})}function f(e,t,n){[`remove`,`rm`,`uninstall`,`un`,`update`,`up`].includes(t)&&e.argument(`package`,te),[`run`,`run-script`].includes(t)&&e.argument(`script`,ee,!0)}async function p(e,t={}){try{let{stdout:n}=await ne(e,{encoding:`utf8`,timeout:500,maxBuffer:4*1024*1024,...t});return n}catch(e){return e instanceof Error&&`stdout`in e?e.stdout:``}}function m(e,t={}){try{return re(e,{encoding:`utf8`,timeout:500,...t})}catch(e){return e?.stdout?e.stdout:``}}function h(e){return t=>e.forEach(e=>t(e,` `))}const ie=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g,g=/^\s+([a-z][a-z\s,-]*?)\s{2,}(\S.*)$/i,_=/^\s*(?:-(?<short>[A-Za-z]),\s*)?--(?<long>[a-z0-9-]+)(?<val>\s+(?:<[^>]+>|\[[^\]]+\]))?\s{2,}(?<desc>\S.*)$/i,ae=/^\s*(?:-[A-Za-z],\s*)?--[a-z0-9-]+/i,v=e=>e.replace(ie,``),y=e=>(e.match(/^\s*/)||[``])[0].length,oe=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),b=/^\s*Options:/i,x=/(?:levels?|options?|values?)[^:]*:\s*([^.]+)/i,S=/\r?\n/,se=/[,\s]+/,C=/^\s*(?:-\w,?\s*)?--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*)\s+(.+)$/,w=/^\s*-\w,?\s*--\w+(?:,\s*--(\w+(?:-\w+)*)\s+(\w+(?:-\w+)*))?\s+(.+)$/,T=/^\s{20,}/,E=/^\s*[A-Z][^:]*:\s*$/;function D(e){return v(e).split(S)}function ce(e){let t=1/0;for(let n of e){let e=n.match(g);if(!e)continue;let r=n.indexOf(e[2]);r>=0&&r<t&&(t=r)}return t}function le(e,t){let n=1/0;for(let r of e){let e=r.match(_);if(!e||t&&e.groups?.val)continue;let i=r.indexOf(e.groups.desc);i>=0&&i<n&&(n=i)}return n}function O(e,t){let n=D(e),r=[];for(let e=0;e<n.length;e++){let i=n[e],a=i.match(C);if(a){let[,i,o,s]=a;if(i===t){let t=s.trim(),i=e+1;for(;i<n.length;){let e=n[i],r=T.test(e),a=C.test(e)||w.test(e),o=!e.trim()||E.test(e);if(r&&!a&&!o)t+=` `+e.trim(),i++;else break}r.push({value:o,desc:t})}}let o=i.match(w);if(o){let[,i,a,s]=o;if(i===t&&a){let t=s.trim(),i=e+1;for(;i<n.length;){let e=n[i],r=T.test(e),a=C.test(e)||w.test(e),o=!e.trim()||E.test(e);if(r&&!a&&!o)t+=` `+e.trim(),i++;else break}r.push({value:a,desc:t})}}}if(r.length)return r;for(let e=0;e<n.length;e++){let r=n[e];if(r.includes(`--${t}`)||r.includes(`${t}:`))for(let t=e;t<Math.min(e+3,n.length);t++){let e=n[t].match(x);if(e)return e[1].split(se).map(e=>e.trim()).filter(e=>e&&!e.includes(`(`)&&!e.includes(`)`)).map(e=>({value:e,desc:`Log level: ${e}`}))}}return[]}const k={...u,loglevel(e){let t=O(m(`pnpm install --help`),`loglevel`);t.length?t.forEach(({value:t,desc:n})=>e(t,n)):h([`debug`,`info`,`warn`,`error`,`silent`])(e)},reporter(e){let t=O(m(`pnpm install --help`),`reporter`);t.length?t.forEach(({value:t,desc:n})=>e(t,n)):h([`default`,`append-only`,`ndjson`,`silent`])(e)},filter(e){e(`.`,`Current working directory`),e(`!<selector>`,`Exclude packages matching selector`),s().forEach(t=>{e(t,`Workspace pattern: ${t}`),e(`${t}...`,`Include dependencies of ${t}`)}),e(`@*/*`,`All scoped packages`),e(`...<pattern>`,`Include dependencies of pattern`),e(`<pattern>...`,`Include dependents of pattern`)}};function ue(e){let t=D(e),n=ce(t);if(!Number.isFinite(n))return{};let r=null,i=new Map,a=()=>{if(!r)return;let e=r.desc.trim();for(let t of r.names)i.set(t,e);r=null};for(let e of t){if(b.test(e))break;let t=e.match(g);if(t){a(),r={names:oe(t[1]),desc:t[2].trim()};continue}r&&y(e)>=n&&e.trim()&&(r.desc+=` `+e.trim())}return a(),Object.fromEntries(i)}async function de(){let e=await p(`pnpm --help`);return e?ue(e):{}}function fe(e,{flagsOnly:t=!0}={}){let n=D(e),r=le(n,t);if(!Number.isFinite(r))return[];let i=[],a=null,o=()=>{a&&=(a.desc=a.desc.trim(),i.push(a),null)};for(let e of n){let n=e.match(_);if(n){if(t&&n.groups?.val)continue;o(),a={short:n.groups?.short||void 0,long:n.groups.long,desc:n.groups.desc.trim()};continue}if(a){let t=y(e),n=ae.test(e);t>=r&&e.trim()&&!n&&(a.desc+=` `+e.trim())}}return o(),i}function A(e,t){let n=m(`pnpm ${t} --help`);if(!n)return;let r=fe(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=k[t];r?e.option(t,i,r,n):e.option(t,i,n)}for(let[t,r]of Object.entries(k))e.optionsRaw?.get?.(t)||O(n,t).length>0&&e.option(t,` `,r)}async function j(e){try{let t=await de();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);f(t,n,`pnpm`),d(t,n,`pnpm`,A)}}catch{}}const M=/^All commands:\s*$/i,N=/^Options:\s*$/i,P=/^(aliases|run|more)/i,F=/^[a-z][a-z0-9-]*$/,I=/(?:\[)?(?:-([a-z])\|)?--([a-z][a-z0-9-]+)(?:\s+<[^>]+>)?(?:\])?/gi,L=/<[^>]+>/,R=/^\s/;function z(e){return v(e).split(/\r?\n/)}function B(e,t){let n=e.findIndex(e=>t.test(e.trim()));if(n===-1)return``;let r=``;for(let t=n+1;t<e.length;t++){let n=e[t];if(!R.test(n)&&n.trim()&&!n.includes(`,`))break;R.test(n)&&(r+=` `+n.trim())}return r}const V=(e,t=()=>` `)=>n=>e.forEach(e=>n(e,t(e))),pe={...u,loglevel:h([`silent`,`error`,`warn`,`notice`,`http`,`info`,`verbose`,`silly`]),"install-strategy":V([`hoisted`,`nested`,`shallow`,`linked`],()=>` `),omit:V([`dev`,`optional`,`peer`],()=>` `),include:V([`prod`,`dev`,`optional`,`peer`],()=>` `)};function me(e){let t=B(z(e),M);if(!t)return{};let n={};return t.split(`,`).map(e=>e.trim()).filter(e=>e&&F.test(e)).forEach(e=>{n[e]=` `}),n.run=` `,n}async function he(){let e=await p(`npm --help`);return e?me(e):{}}function ge(e,{flagsOnly:t=!0}={}){let n=z(e),r=n.findIndex(e=>N.test(e.trim()));if(r===-1)return[];let i=[];for(let e of n.slice(r+1)){let n=e.trim();if(P.test(n))break;let r=e.matchAll(I);for(let e of r){let n=e[1]||void 0,r=e[2],a=L.test(e[0]);t&&a||i.push({short:n,long:r,desc:` `})}}return i}function _e(e,t){let n=m(`npm ${t} --help`);if(!n)return;let r=ge(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=pe[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function ve(e){try{let t=await he();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);f(t,n,`npm`),d(t,n,`npm`,_e)}}catch{}}const ye=/^\s*Options:\s*$/i,be=/^\s*Commands:\s*$/i,H=/^(Run `yarn help|Visit https:\/\/)/i,xe=/\r?\n/,Se=/^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:\s+<[^>]+>|\s+\[[^\]]+\])?\s+(.+)$/,Ce=/^\s*-\s+([a-z][a-z0-9-]*(?:\s*\/\s*[a-z][a-zA-Z]*)*)/;function U(e){return v(e).split(xe)}function W(e,t){for(let n=0;n<e.length;n++)if(t.test(e[n].trim()))return n+1;return-1}const we={...u,emoji(e){e(`true`,` `),e(`false`,` `)},production(e){e(`true`,` `),e(`false`,` `)},"scripts-prepend-node-path"(e){e(`true`,` `),e(`false`,` `)}};function Te(e){let t=U(e),n={},r=W(t,be);if(r===-1)return n;for(let e=r;e<t.length;e++){let r=t[e];if(H.test(r))break;if(!r.trim())continue;let i=r.match(Ce);if(i){let[,e]=i,t=e.split(/\s*\/\s*/),r=t[0].trim();if(r){n[r]=``;for(let e=1;e<t.length;e++){let r=t[e].trim();r&&(n[r]=``)}}}}return n}async function Ee(){let e=await p(`yarn --help`);return e?Te(e):{}}function De(e,{flagsOnly:t=!0}={}){let n=U(e),r=[],i=W(n,ye);if(i===-1)return r;for(let e=i;e<n.length;e++){let i=n[e];if(H.test(i.trim()))break;let a=i.match(Se);if(!a)continue;let[,o,s,c]=a,l=i.includes(`<`)||i.includes(`[`);t&&l||r.push({short:o||void 0,long:s,desc:c.trim()})}return r}function Oe(e,t){let n=m(`yarn ${t} --help`);if(!n)return;let r=De(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=we[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function ke(e){try{let t=await Ee();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);f(t,n,`yarn`),d(t,n,`yarn`,Oe)}}catch{}}const Ae=/^Commands:\s*$/i,G=/^Flags:\s*$/i,je=/^(Examples|Full documentation|Learn more)/i,K=/^[a-z][a-z0-9-]*$/,Me=/^\s*(?:-([a-zA-Z]),?\s*)?--([a-z][a-z0-9-]*)(?:=<[^>]+>)?\s+(.+)$/,Ne=/^ ([a-z][a-z0-9-]*)\s+(.+)$/,Pe=/^\s{12,}([a-z][a-z0-9-]*)\s+(.+)$/,Fe=/^\s+[a-z]/,Ie=/\s{2,}/,q=/^[A-Z]/,Le=/\r?\n/;function J(e){return v(e).split(Le)}function Y(e,t){for(let n=0;n<e.length;n++)if(t.test(e[n].trim()))return n+1;return-1}const Re={...u,backend(e){e(`clonefile`,` `),e(`hardlink`,` `),e(`symlink`,` `),e(`copyfile`,` `)},linker(e){e(`isolated`,` `),e(`hoisted`,` `)},omit(e){e(`dev`,` `),e(`optional`,` `),e(`peer`,` `)},shell(e){e(`bun`,` `),e(`system`,` `)},"unhandled-rejections"(e){e(`strict`,` `),e(`throw`,` `),e(`warn`,` `),e(`none`,` `),e(`warn-with-error-code`,` `)}};function ze(e){let t=J(e),n=Y(t,Ae);if(n===-1)return{};let r={};for(let e=n;e<t.length;e++){let n=t[e];if(G.test(n.trim())||n.trim()===``&&e+1<t.length&&!t[e+1].match(Fe))break;if(!n.trim())continue;let i=n.match(Ne);if(i){let[,e,t]=i;if(K.test(e)){let n=t.split(Ie),i=n[n.length-1];if(i&&q.test(i))r[e]=i.trim();else if(n.length>1){for(let t of n)if(q.test(t)){r[e]=t.trim();break}}}}let a=n.match(Pe);if(a){let[,e,t]=a;K.test(e)&&(r[e]=t.trim())}}return r}async function Be(){let e=await p(`bun --help`);return e?ze(e):{}}function Ve(e,{flagsOnly:t=!0}={}){let n=J(e),r=[],i=Y(n,G);if(i===-1)return r;for(let e=i;e<n.length;e++){let i=n[e];if(je.test(i.trim()))break;let a=i.match(Me);if(!a)continue;let[,o,s,c]=a,l=i.includes(`=<`);t&&l||r.push({short:o||void 0,long:s,desc:c.trim()})}return r}function He(e,t){let n=m(`bun ${t} --help`);if(!n)return;let r=Ve(n,{flagsOnly:!1});for(let{long:t,short:n,desc:i}of r){if(e.optionsRaw?.get?.(t))continue;let r=Re[t];r?e.option(t,i,r,n):e.option(t,i,n)}}async function Ue(e){try{let t=await Be();for(let[n,r]of Object.entries(t)){let t=e.command(n,r);f(t,n,`bun`),d(t,n,`bun`,He)}}catch{}}async function We(e,t){switch(e){case`pnpm`:await j(t);break;case`npm`:await ve(t);break;case`yarn`:await ke(t);break;case`bun`:await Ue(t);break;default:break}}function X(...e){process.env.DEBUG&&console.error(`[DEBUG]`,...e)}const Ge={encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],timeout:1e3};function Z(e,t,n){let r=o(e,[...t,`complete`,`--`,...n],Ge);if(r.error)throw r.error;if(typeof r.status==`number`&&r.status!==0)throw Error(`Completion command "${e}" exited with code ${r.status}`);return(r.stdout??``).trim()}async function Ke(e,t){try{if(Z(e,[],[]))return!0}catch{}try{return!!Z(t,[e],[])}catch{return!1}}async function qe(e,t,n){try{let t=Z(e,[],n);if(t)return t.split(`
|
|
4
4
|
`).filter(Boolean)}catch{}try{return Z(t,[e],n).split(`
|
|
5
5
|
`).filter(Boolean)}catch{return[]}}var Je=class extends e{packageManager;constructor(e){super(),this.packageManager=e}stripPackageManagerCommands(e){return e.length===0?e:[`exec`,`x`,`run`,`dlx`].includes(e[0])?e.slice(1):e}async parse(e){let t=this.stripPackageManagerCommands(e);if(t.length>=1&&t[0].trim()!==``){let e=t[0];if(![...this.commands.keys()].includes(e)&&await Ke(e,this.packageManager)){let n=t.slice(1),r=await qe(e,this.packageManager,n);if(r.length>0){X(`Returning ${r.length} completions for ${e}`);for(let e of r)if(!e.startsWith(`:`))if(e.includes(` `)){let[t,n]=e.split(` `);console.log(`${t}\t${n}`)}else console.log(e);console.log(`:4`);return}}}return super.parse(e)}};const Q=[`npm`,`pnpm`,`yarn`,`bun`],$=[`zsh`,`bash`,`fish`,`powershell`];async function Ye(){let e=process.argv.slice(2),t=process.platform===`win32`&&process.env.PSModulePath;if(e.length>=2&&e[1]===`complete`){let n=e[0];Q.includes(n)||(console.error(`Error: Unsupported package manager "${n}"`),console.error(`Supported package managers: ${Q.join(`, `)}`),process.exit(1));let r=process.argv.indexOf(`--`),i=r!==-1&&(!t||r<process.argv.length-1)?process.argv.slice(r+1):t?e.slice(2):null;i||(console.error(`Error: Expected '--' followed by command to complete`),process.exit(1));let a=new Je(n);await We(n,a),await a.parse(i),process.exit(0)}if(e.length===2){let[t,n]=e;Q.includes(t)||(console.error(`Error: Unsupported package manager "${t}"`),console.error(`Supported package managers: ${Q.join(`, `)}`),process.exit(1)),$.includes(n)||(console.error(`Error: Unsupported shell "${n}"`),console.error(`Supported shells: ${$.join(`, `)}`),process.exit(1)),Xe(t,n),process.exit(0)}console.error(`Usage: tab <packageManager> <shell>`),console.error(` tab <packageManager> complete -- <args>`),process.exit(1)}function Xe(e,n){t(n,e,process.argv[1].endsWith(`dist/bin/cli.js`)?`node ${process.argv[1]} ${e}`:`tab ${e}`)}Ye().catch(console.error);export{};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as CompletionConfig } from "./shared-
|
|
1
|
+
import { RootCommand } from "./t-D9C2bp96.js";
|
|
2
|
+
import { t as CompletionConfig } from "./shared-Cst8Kh7c.js";
|
|
3
3
|
import { CAC } from "cac";
|
|
4
4
|
|
|
5
5
|
//#region src/cac.d.ts
|
package/dist/cac.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./powershell-BbJLZFR-.js";import i from"./t.js";import{t as a}from"./shared-Botddo9c.js";const o=process.execPath,s=process.argv.slice(1),c=f(o),l=s.map(f),u=`${c} ${process.execArgv.map(f).join(` `)} ${l[0]}`,d=/<[^>]+>|\[[^\]]+\]/;function f(e){return e.includes(` `)?`'${e}'`:e}async function p(c,l){for(let e of[c.globalCommand,...c.commands]){if(e.name===`complete`)continue;let t=(e.rawName.match(/\[.*?\]|<.*?>/g)||[]).map(e=>e.startsWith(`[`)),n=e.name===`@@global@@`,r=n?l:l?.subCommands?.[e.name],a=n?``:e.name,o=n?i:i.command(a,e.description||``);if(o){let n=(e.rawName.match(/<([^>]+)>|\[\.\.\.([^\]]+)\]/g)||[]).map(e=>e.startsWith(`<`)&&e.endsWith(`>`)?e.slice(1,-1):e.startsWith(`[...`)&&e.endsWith(`]`)?e.slice(4,-1):e);t.forEach((e,t)=>{let i=n[t]||`arg${t}`,a=r?.args?.[i];a?o.argument(i,a,e):o.argument(i,void 0,e)})}for(let t of[...c.globalCommand.options,...e.options]){let e=t.rawName.match(/^-([a-zA-Z]), --/)?.[1],a=t.name,s=n?i:o;if(s){let n=r?.options?.[a],i=t.required||d.test(t.rawName);n?e?s.option(a,t.description||``,n,e):s.option(a,t.description||``,n):i?e?s.option(a,t.description||``,async()=>[],e):s.option(a,t.description||``,async()=>[]):e?s.option(a,t.description||``,e):s.option(a,t.description||``)}}}return c.command(`complete [shell]`).action(async(l,d)=>{switch(l){case`zsh`:{let t=e(c.name,u);console.log(t);break}case`bash`:{let e=n(c.name,u);console.log(e);break}case`fish`:{let e=t(c.name,u);console.log(e);break}case`powershell`:{let e=r(c.name,u);console.log(e);break}default:{a(c.name);let e=d[`--`]||[];return c.showHelpOnExit=!1,c.unsetMatchedCommand(),c.parse([o,s[0],...e],{run:!1}),i.parse(e)}}}),i}export{p as default};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as CompletionConfig } from "./shared-
|
|
1
|
+
import { RootCommand } from "./t-D9C2bp96.js";
|
|
2
|
+
import { t as CompletionConfig } from "./shared-Cst8Kh7c.js";
|
|
3
3
|
import { ArgsDef, CommandDef } from "citty";
|
|
4
4
|
|
|
5
5
|
//#region src/citty.d.ts
|
package/dist/citty.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./powershell-BbJLZFR-.js";import i from"./t.js";import{t as a}from"./shared-Botddo9c.js";import{defineCommand as o}from"citty";async function s(e){let t=[],n=[];for(let[r,i]of Object.entries(e))if(i.type===`positional`){let e=i;n.push({name:r,description:e.description,isOptional:!e.required,isVariadic:r.startsWith(`[...`)||r.startsWith(`<...`)})}else{let e={name:`--${r}`,description:i.description||``,isRequired:i.required};`alias`in i&&i.alias&&(Array.isArray(i.alias)?i.alias:[i.alias]).forEach(n=>{t.push({...e,name:`-${n}`})}),t.push(e)}return{options:t,args:n}}async function c(e,t=``){let n=await Promise.resolve(e.meta),r=await Promise.resolve(e.subCommands);if(!n||!n.name)throw Error(`Command meta or name is missing`);let i={name:t?`${t} ${n.name}`:n.name,description:n.description||``};if(e.args){let{options:t,args:n}=await s(await Promise.resolve(e.args));t.length>0&&(i.options=t),n.length>0&&(i.args=n)}return r&&(i.subcommands=await Promise.all(Object.entries(r).map(async([e,t])=>c(await Promise.resolve(t),i.name)))),i}async function l(e){let t=await c(e);return JSON.stringify(t,null,2)}function u(e){return e.includes(` `)?`'${e}'`:e}const d=process.execPath,f=process.argv.slice(1),p=u(d),m=f.map(u),h=`${p} ${process.execArgv.map(u).join(` `)} ${m[0]}`;function g(e){return e.args&&Object.values(e.args).some(e=>e.type===`positional`)}async function _(e,t,n){for(let[r,a]of Object.entries(e)){let e=await y(a),o=await y(e.meta),s=await y(e.subCommands),c=n?.[r];if(!o||typeof o?.description!=`string`)throw Error(`Invalid meta or missing description.`);let l=g(e),u=t?`${t} ${r}`:r,d=i.command(u,o.description);if(l&&e.args)for(let[t,n]of Object.entries(e.args)){let e=n;if(e.type===`positional`){let n=e.required===!1,r=c?.args?.[t];r?d.argument(t,r,n):d.argument(t,void 0,n)}}if(s&&await _(s,u,c?.subCommands),e.args)for(let[t,n]of Object.entries(e.args)){let e=n,r=typeof e==`object`&&`alias`in e?Array.isArray(e.alias)?e.alias[0]:e.alias:void 0,i=c?.options?.[t];i?r?d.option(t,e.description??``,i,r):d.option(t,e.description??``,i):r?d.option(t,e.description??``,r):d.option(t,e.description??``)}}}async function v(s,c){let u=await y(s.meta);if(!u)throw Error(`Invalid meta.`);let d=u.name;if(!d)throw Error(`Invalid meta or missing name.`);let f=await y(s.subCommands);if(g(s)&&s.args)for(let[e,t]of Object.entries(s.args)){let n=t;if(n.type===`positional`){let t=n.required===!1,r=c?.args?.[e];r?i.argument(e,r,t):i.argument(e,void 0,t)}}if(f&&await _(f,void 0,c?.subCommands),s.args)for(let[e,t]of Object.entries(s.args)){let n=t,r=typeof n==`object`&&`alias`in n?Array.isArray(n.alias)?n.alias[0]:n.alias:void 0,a=c?.options?.[e];a?r?i.option(e,n.description??``,a,r):i.option(e,n.description??``,a):r?i.option(e,n.description??``,r):i.option(e,n.description??``)}let p=o({meta:{name:`complete`,description:`Generate shell completion scripts`},args:{shell:{type:`positional`,description:`Shell type (zsh, bash, fish, powershell, fig)`,required:!1}},async run(o){let c=o.rawArgs[0];switch(c===`--`&&(c=void 0),c){case`zsh`:{let t=e(d,h);console.log(t);break}case`bash`:{let e=n(d,h);console.log(e);break}case`fish`:{let e=t(d,h);console.log(e);break}case`powershell`:{let e=r(d,h);console.log(e);break}case`fig`:{let e=await l(s);console.log(e);break}default:{a(d);let e=o.rawArgs.slice(o.rawArgs.indexOf(`--`)+1);return i.parse(e)}}}});return f?f.complete=p:s.subCommands={complete:p},i}async function y(e){return e instanceof Function?await e():await e}export{v as default};
|
package/dist/commander.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./powershell-BbJLZFR-.js";import i from"./t.js";import{t as a}from"./shared-Botddo9c.js";const o=process.execPath,s=process.argv.slice(1),c=d(o),l=s.map(d),u=`${c} ${process.execArgv.map(d).join(` `)} ${l[0]}`;function d(e){return e.includes(` `)?`'${e}'`:e}function f(o){let s=o.name();p(o),m(o),o.command(`complete [shell]`).description(`Generate shell completion scripts`).action(async i=>{switch(i){case`zsh`:{let t=e(s,u);console.log(t);break}case`bash`:{let e=n(s,u);console.log(e);break}case`fish`:{let e=t(s,u);console.log(e);break}case`powershell`:{let e=r(s,u);console.log(e);break}case`debug`:{let e=new Map;h(o,``,e),console.log(`Collected commands:`);for(let[t,n]of e.entries())console.log(`- ${t||`<root>`}: ${n.description()||`No description`}`);break}default:console.error(`Unknown shell: ${i}`),console.error(`Supported shells: zsh, bash, fish, powershell`),process.exit(1)}});let c=o.parse.bind(o);return o.parse=function(e,t){let n=e||process.argv,r=n.findIndex(e=>e===`complete`),l=n.findIndex(e=>e===`--`);if(r!==-1&&l!==-1&&l>r){let e=n.slice(l+1);return a(s),i.parse(e),o}return c(e,t)},i}function p(e){for(let t of e.options){let e=t.flags,n=e.match(/^-([a-zA-Z]), --/)?.[1],r=e.match(/--([a-zA-Z0-9-]+)/)?.[1];r&&(n?i.option(r,t.description||``,n):i.option(r,t.description||``))}}function m(e){let t=new Map;h(e,``,t);for(let[e,n]of t.entries()){if(e===``)continue;let t=i.command(e,n.description()||``);for(let e of n.options){let n=e.flags,r=n.match(/^-([a-zA-Z]), --/)?.[1],i=n.match(/--([a-zA-Z0-9-]+)/)?.[1];i&&(r?t.option(i,e.description||``,r):t.option(i,e.description||``))}}}function h(e,t,n){n.set(t,e);for(let r of e.commands)r.name()!==`complete`&&h(r,t?`${t} ${r.name()}`:r.name(),n)}export{f as default};
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import e
|
|
2
|
-
compdef _${
|
|
1
|
+
import{ShellCompDirective as e}from"./t.js";function t(t,n){return`#compdef ${t}
|
|
2
|
+
compdef _${t} ${t}
|
|
3
3
|
|
|
4
|
-
# zsh completion for ${
|
|
4
|
+
# zsh completion for ${t} -*- shell-script -*-
|
|
5
5
|
|
|
6
|
-
__${
|
|
6
|
+
__${t}_debug() {
|
|
7
7
|
local file="$BASH_COMP_DEBUG_FILE"
|
|
8
8
|
if [[ -n \${file} ]]; then
|
|
9
9
|
echo "$*" >> "\${file}"
|
|
10
10
|
fi
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
_${
|
|
14
|
-
local shellCompDirectiveError=${
|
|
15
|
-
local shellCompDirectiveNoSpace=${
|
|
16
|
-
local shellCompDirectiveNoFileComp=${
|
|
17
|
-
local shellCompDirectiveFilterFileExt=${
|
|
18
|
-
local shellCompDirectiveFilterDirs=${
|
|
19
|
-
local shellCompDirectiveKeepOrder=${
|
|
13
|
+
_${t}() {
|
|
14
|
+
local shellCompDirectiveError=${e.ShellCompDirectiveError}
|
|
15
|
+
local shellCompDirectiveNoSpace=${e.ShellCompDirectiveNoSpace}
|
|
16
|
+
local shellCompDirectiveNoFileComp=${e.ShellCompDirectiveNoFileComp}
|
|
17
|
+
local shellCompDirectiveFilterFileExt=${e.ShellCompDirectiveFilterFileExt}
|
|
18
|
+
local shellCompDirectiveFilterDirs=${e.ShellCompDirectiveFilterDirs}
|
|
19
|
+
local shellCompDirectiveKeepOrder=${e.ShellCompDirectiveKeepOrder}
|
|
20
20
|
|
|
21
21
|
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
22
22
|
local -a completions
|
|
23
23
|
|
|
24
|
-
__${
|
|
25
|
-
__${
|
|
24
|
+
__${t}_debug "\\n========= starting completion logic =========="
|
|
25
|
+
__${t}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
|
|
26
26
|
|
|
27
27
|
# The user could have moved the cursor backwards on the command-line.
|
|
28
28
|
# We need to trigger completion from the $CURRENT location, so we need
|
|
29
29
|
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
30
30
|
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
31
31
|
words=( "\${=words[1,CURRENT]}" )
|
|
32
|
-
__${
|
|
32
|
+
__${t}_debug "Truncated words[*]: \${words[*]},"
|
|
33
33
|
|
|
34
34
|
lastParam=\${words[-1]}
|
|
35
35
|
lastChar=\${lastParam[-1]}
|
|
36
|
-
__${
|
|
36
|
+
__${t}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
|
|
37
37
|
|
|
38
|
-
# For zsh, when completing a flag with an = (e.g., ${
|
|
38
|
+
# For zsh, when completing a flag with an = (e.g., ${t} -n=<TAB>)
|
|
39
39
|
# completions must be prefixed with the flag
|
|
40
40
|
setopt local_options BASH_REMATCH
|
|
41
41
|
if [[ "\${lastParam}" =~ '-.*=' ]]; then
|
|
@@ -48,7 +48,7 @@ _${e}() {
|
|
|
48
48
|
if [ "\${lastChar}" = "" ]; then
|
|
49
49
|
# If the last parameter is complete (there is a space following it)
|
|
50
50
|
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
51
|
-
__${
|
|
51
|
+
__${t}_debug "Adding extra empty parameter"
|
|
52
52
|
args_to_quote+=("")
|
|
53
53
|
fi
|
|
54
54
|
|
|
@@ -56,20 +56,20 @@ _${e}() {
|
|
|
56
56
|
local quoted_args=("\${(@q)args_to_quote}")
|
|
57
57
|
|
|
58
58
|
# Join the main command and the quoted arguments into a single string for eval
|
|
59
|
-
requestComp="${
|
|
59
|
+
requestComp="${n} complete -- \${quoted_args[*]}"
|
|
60
60
|
|
|
61
|
-
__${
|
|
61
|
+
__${t}_debug "About to call: eval \${requestComp}"
|
|
62
62
|
|
|
63
63
|
# Use eval to handle any environment variables and such
|
|
64
64
|
out=$(eval \${requestComp} 2>/dev/null)
|
|
65
|
-
__${
|
|
65
|
+
__${t}_debug "completion output: \${out}"
|
|
66
66
|
|
|
67
67
|
# Extract the directive integer following a : from the last line
|
|
68
68
|
local lastLine
|
|
69
69
|
while IFS='\n' read -r line; do
|
|
70
70
|
lastLine=\${line}
|
|
71
71
|
done < <(printf "%s\n" "\${out[@]}")
|
|
72
|
-
__${
|
|
72
|
+
__${t}_debug "last line: \${lastLine}"
|
|
73
73
|
|
|
74
74
|
if [ "\${lastLine[1]}" = : ]; then
|
|
75
75
|
directive=\${lastLine[2,-1]}
|
|
@@ -79,16 +79,16 @@ _${e}() {
|
|
|
79
79
|
out=\${out[1,-$suffix]}
|
|
80
80
|
else
|
|
81
81
|
# There is no directive specified. Leave $out as is.
|
|
82
|
-
__${
|
|
82
|
+
__${t}_debug "No directive found. Setting to default"
|
|
83
83
|
directive=0
|
|
84
84
|
fi
|
|
85
85
|
|
|
86
|
-
__${
|
|
87
|
-
__${
|
|
88
|
-
__${
|
|
86
|
+
__${t}_debug "directive: \${directive}"
|
|
87
|
+
__${t}_debug "completions: \${out}"
|
|
88
|
+
__${t}_debug "flagPrefix: \${flagPrefix}"
|
|
89
89
|
|
|
90
90
|
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
91
|
-
__${
|
|
91
|
+
__${t}_debug "Completion received error. Ignoring completions."
|
|
92
92
|
return
|
|
93
93
|
fi
|
|
94
94
|
|
|
@@ -99,11 +99,11 @@ _${e}() {
|
|
|
99
99
|
while IFS='\n' read -r comp; do
|
|
100
100
|
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
101
101
|
if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
102
|
-
__${
|
|
102
|
+
__${t}_debug "ActiveHelp found: $comp"
|
|
103
103
|
comp="\${comp[$startIndex,-1]}"
|
|
104
104
|
if [ -n "$comp" ]; then
|
|
105
105
|
compadd -x "\${comp}"
|
|
106
|
-
__${
|
|
106
|
+
__${t}_debug "ActiveHelp will need delimiter"
|
|
107
107
|
hasActiveHelp=1
|
|
108
108
|
fi
|
|
109
109
|
continue
|
|
@@ -119,7 +119,7 @@ _${e}() {
|
|
|
119
119
|
local tab="$(printf '\\t')"
|
|
120
120
|
comp=\${comp//$tab/:}
|
|
121
121
|
|
|
122
|
-
__${
|
|
122
|
+
__${t}_debug "Adding completion: \${comp}"
|
|
123
123
|
completions+=\${comp}
|
|
124
124
|
lastComp=$comp
|
|
125
125
|
fi
|
|
@@ -130,19 +130,19 @@ _${e}() {
|
|
|
130
130
|
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
131
131
|
if [ $hasActiveHelp -eq 1 ]; then
|
|
132
132
|
if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
133
|
-
__${
|
|
133
|
+
__${t}_debug "Adding activeHelp delimiter"
|
|
134
134
|
compadd -x "--"
|
|
135
135
|
hasActiveHelp=0
|
|
136
136
|
fi
|
|
137
137
|
fi
|
|
138
138
|
|
|
139
139
|
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
140
|
-
__${
|
|
140
|
+
__${t}_debug "Activating nospace."
|
|
141
141
|
noSpace="-S ''"
|
|
142
142
|
fi
|
|
143
143
|
|
|
144
144
|
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
145
|
-
__${
|
|
145
|
+
__${t}_debug "Activating keep order."
|
|
146
146
|
keepOrder="-V"
|
|
147
147
|
fi
|
|
148
148
|
|
|
@@ -159,17 +159,17 @@ _${e}() {
|
|
|
159
159
|
done
|
|
160
160
|
filteringCmd+=" \${flagPrefix}"
|
|
161
161
|
|
|
162
|
-
__${
|
|
162
|
+
__${t}_debug "File filtering command: $filteringCmd"
|
|
163
163
|
_arguments '*:filename:'"$filteringCmd"
|
|
164
164
|
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
165
165
|
# File completion for directories only
|
|
166
166
|
local subdir
|
|
167
167
|
subdir="\${completions[1]}"
|
|
168
168
|
if [ -n "$subdir" ]; then
|
|
169
|
-
__${
|
|
169
|
+
__${t}_debug "Listing directories in $subdir"
|
|
170
170
|
pushd "\${subdir}" >/dev/null 2>&1
|
|
171
171
|
else
|
|
172
|
-
__${
|
|
172
|
+
__${t}_debug "Listing directories in ."
|
|
173
173
|
fi
|
|
174
174
|
|
|
175
175
|
local result
|
|
@@ -180,17 +180,17 @@ _${e}() {
|
|
|
180
180
|
fi
|
|
181
181
|
return $result
|
|
182
182
|
else
|
|
183
|
-
__${
|
|
183
|
+
__${t}_debug "Calling _describe"
|
|
184
184
|
if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
|
|
185
|
-
__${
|
|
185
|
+
__${t}_debug "_describe found some completions"
|
|
186
186
|
|
|
187
187
|
# Return the success of having called _describe
|
|
188
188
|
return 0
|
|
189
189
|
else
|
|
190
|
-
__${
|
|
191
|
-
__${
|
|
190
|
+
__${t}_debug "_describe did not find completions."
|
|
191
|
+
__${t}_debug "Checking if we should do file completion."
|
|
192
192
|
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
193
|
-
__${
|
|
193
|
+
__${t}_debug "deactivating file completion"
|
|
194
194
|
|
|
195
195
|
# Return 0 to indicate completion is finished and prevent zsh from
|
|
196
196
|
# trying other completion algorithms (which could cause hanging).
|
|
@@ -198,7 +198,7 @@ _${e}() {
|
|
|
198
198
|
return 0
|
|
199
199
|
else
|
|
200
200
|
# Perform file completion
|
|
201
|
-
__${
|
|
201
|
+
__${t}_debug "Activating file completion"
|
|
202
202
|
|
|
203
203
|
# We must return the result of this command, so it must be the
|
|
204
204
|
# last command, or else we must store its result to return it.
|
|
@@ -209,35 +209,35 @@ _${e}() {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
# don't run the completion function when being sourced or eval-ed
|
|
212
|
-
if [ "\${funcstack[1]}" = "_${
|
|
213
|
-
_${
|
|
212
|
+
if [ "\${funcstack[1]}" = "_${t}" ]; then
|
|
213
|
+
_${t}
|
|
214
214
|
fi
|
|
215
|
-
`}function n(
|
|
215
|
+
`}function n(t,n){let r=t.replace(/[-:]/g,`_`);return`# bash completion for ${t}
|
|
216
216
|
|
|
217
217
|
# Define shell completion directives
|
|
218
|
-
readonly ShellCompDirectiveError=${
|
|
219
|
-
readonly ShellCompDirectiveNoSpace=${
|
|
220
|
-
readonly ShellCompDirectiveNoFileComp=${
|
|
221
|
-
readonly ShellCompDirectiveFilterFileExt=${
|
|
222
|
-
readonly ShellCompDirectiveFilterDirs=${
|
|
223
|
-
readonly ShellCompDirectiveKeepOrder=${
|
|
218
|
+
readonly ShellCompDirectiveError=${e.ShellCompDirectiveError}
|
|
219
|
+
readonly ShellCompDirectiveNoSpace=${e.ShellCompDirectiveNoSpace}
|
|
220
|
+
readonly ShellCompDirectiveNoFileComp=${e.ShellCompDirectiveNoFileComp}
|
|
221
|
+
readonly ShellCompDirectiveFilterFileExt=${e.ShellCompDirectiveFilterFileExt}
|
|
222
|
+
readonly ShellCompDirectiveFilterDirs=${e.ShellCompDirectiveFilterDirs}
|
|
223
|
+
readonly ShellCompDirectiveKeepOrder=${e.ShellCompDirectiveKeepOrder}
|
|
224
224
|
|
|
225
225
|
# Function to debug completion
|
|
226
|
-
__${
|
|
226
|
+
__${r}_debug() {
|
|
227
227
|
if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
|
|
228
228
|
echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
|
|
229
229
|
fi
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
# Function to handle completions
|
|
233
|
-
__${
|
|
233
|
+
__${r}_complete() {
|
|
234
234
|
local cur prev words cword
|
|
235
235
|
_get_comp_words_by_ref -n "=:" cur prev words cword
|
|
236
236
|
|
|
237
237
|
local requestComp out directive
|
|
238
238
|
|
|
239
239
|
# Build the command to get completions
|
|
240
|
-
requestComp="${
|
|
240
|
+
requestComp="${n} complete -- \${words[@]:1}"
|
|
241
241
|
|
|
242
242
|
# Add an empty parameter if the last parameter is complete
|
|
243
243
|
if [[ -z "$cur" ]]; then
|
|
@@ -312,31 +312,31 @@ __${n}_complete() {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
# Register completion function
|
|
315
|
-
complete -F __${
|
|
316
|
-
`}function r(
|
|
315
|
+
complete -F __${r}_complete ${t}
|
|
316
|
+
`}function r(t,n){let r=t.replace(/[-:]/g,`_`),i=e.ShellCompDirectiveError,a=e.ShellCompDirectiveNoSpace,o=e.ShellCompDirectiveNoFileComp,s=e.ShellCompDirectiveFilterFileExt,c=e.ShellCompDirectiveFilterDirs;return`# fish completion for ${t} -*- shell-script -*-
|
|
317
317
|
|
|
318
|
-
function __${
|
|
318
|
+
function __${r}_debug
|
|
319
319
|
set -l file "$BASH_COMP_DEBUG_FILE"
|
|
320
320
|
if test -n "$file"
|
|
321
321
|
echo "$argv" >> $file
|
|
322
322
|
end
|
|
323
323
|
end
|
|
324
324
|
|
|
325
|
-
function __${
|
|
326
|
-
__${
|
|
325
|
+
function __${r}_perform_completion
|
|
326
|
+
__${r}_debug "Starting __${r}_perform_completion"
|
|
327
327
|
|
|
328
328
|
# Extract all args except the last one
|
|
329
329
|
set -l args (commandline -opc)
|
|
330
330
|
# Extract the last arg and escape it in case it is a space or wildcard
|
|
331
331
|
set -l lastArg (string escape -- (commandline -ct))
|
|
332
332
|
|
|
333
|
-
__${
|
|
334
|
-
__${
|
|
333
|
+
__${r}_debug "args: $args"
|
|
334
|
+
__${r}_debug "last arg: $lastArg"
|
|
335
335
|
|
|
336
336
|
# Build the completion request command
|
|
337
|
-
set -l requestComp "${
|
|
337
|
+
set -l requestComp "${n} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg"
|
|
338
338
|
|
|
339
|
-
__${
|
|
339
|
+
__${r}_debug "Calling $requestComp"
|
|
340
340
|
set -l results (eval $requestComp 2> /dev/null)
|
|
341
341
|
|
|
342
342
|
# Some programs may output extra empty lines after the directive.
|
|
@@ -359,9 +359,9 @@ function __${n}_perform_completion
|
|
|
359
359
|
# completions must be prefixed with the flag
|
|
360
360
|
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
|
361
361
|
|
|
362
|
-
__${
|
|
363
|
-
__${
|
|
364
|
-
__${
|
|
362
|
+
__${r}_debug "Comps: $comps"
|
|
363
|
+
__${r}_debug "DirectiveLine: $directiveLine"
|
|
364
|
+
__${r}_debug "flagPrefix: $flagPrefix"
|
|
365
365
|
|
|
366
366
|
for comp in $comps
|
|
367
367
|
printf "%s%s\\n" "$flagPrefix" "$comp"
|
|
@@ -370,86 +370,86 @@ function __${n}_perform_completion
|
|
|
370
370
|
printf "%s\\n" "$directiveLine"
|
|
371
371
|
end
|
|
372
372
|
|
|
373
|
-
# This function limits calls to __${
|
|
374
|
-
function __${
|
|
375
|
-
__${
|
|
373
|
+
# This function limits calls to __${r}_perform_completion, by caching the result
|
|
374
|
+
function __${r}_perform_completion_once
|
|
375
|
+
__${r}_debug "Starting __${r}_perform_completion_once"
|
|
376
376
|
|
|
377
|
-
if test -n "$__${
|
|
378
|
-
__${
|
|
377
|
+
if test -n "$__${r}_perform_completion_once_result"
|
|
378
|
+
__${r}_debug "Seems like a valid result already exists, skipping __${r}_perform_completion"
|
|
379
379
|
return 0
|
|
380
380
|
end
|
|
381
381
|
|
|
382
|
-
set --global __${
|
|
383
|
-
if test -z "$__${
|
|
384
|
-
__${
|
|
382
|
+
set --global __${r}_perform_completion_once_result (__${r}_perform_completion)
|
|
383
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
384
|
+
__${r}_debug "No completions, probably due to a failure"
|
|
385
385
|
return 1
|
|
386
386
|
end
|
|
387
387
|
|
|
388
|
-
__${
|
|
388
|
+
__${r}_debug "Performed completions and set __${r}_perform_completion_once_result"
|
|
389
389
|
return 0
|
|
390
390
|
end
|
|
391
391
|
|
|
392
392
|
# This function is used to clear the cached result after completions are run
|
|
393
|
-
function __${
|
|
394
|
-
__${
|
|
395
|
-
__${
|
|
396
|
-
set --erase __${
|
|
397
|
-
__${
|
|
393
|
+
function __${r}_clear_perform_completion_once_result
|
|
394
|
+
__${r}_debug ""
|
|
395
|
+
__${r}_debug "========= clearing previously set __${r}_perform_completion_once_result variable =========="
|
|
396
|
+
set --erase __${r}_perform_completion_once_result
|
|
397
|
+
__${r}_debug "Successfully erased the variable __${r}_perform_completion_once_result"
|
|
398
398
|
end
|
|
399
399
|
|
|
400
|
-
function __${
|
|
401
|
-
__${
|
|
402
|
-
__${
|
|
400
|
+
function __${r}_requires_order_preservation
|
|
401
|
+
__${r}_debug ""
|
|
402
|
+
__${r}_debug "========= checking if order preservation is required =========="
|
|
403
403
|
|
|
404
|
-
__${
|
|
405
|
-
if test -z "$__${
|
|
406
|
-
__${
|
|
404
|
+
__${r}_perform_completion_once
|
|
405
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
406
|
+
__${r}_debug "Error determining if order preservation is required"
|
|
407
407
|
return 1
|
|
408
408
|
end
|
|
409
409
|
|
|
410
|
-
set -l directive (string sub --start 2 $__${
|
|
411
|
-
__${
|
|
410
|
+
set -l directive (string sub --start 2 $__${r}_perform_completion_once_result[-1])
|
|
411
|
+
__${r}_debug "Directive is: $directive"
|
|
412
412
|
|
|
413
|
-
set -l shellCompDirectiveKeepOrder ${
|
|
413
|
+
set -l shellCompDirectiveKeepOrder ${e.ShellCompDirectiveKeepOrder}
|
|
414
414
|
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
|
415
|
-
__${
|
|
415
|
+
__${r}_debug "Keeporder is: $keeporder"
|
|
416
416
|
|
|
417
417
|
if test $keeporder -ne 0
|
|
418
|
-
__${
|
|
418
|
+
__${r}_debug "This does require order preservation"
|
|
419
419
|
return 0
|
|
420
420
|
end
|
|
421
421
|
|
|
422
|
-
__${
|
|
422
|
+
__${r}_debug "This doesn't require order preservation"
|
|
423
423
|
return 1
|
|
424
424
|
end
|
|
425
425
|
|
|
426
426
|
# This function does two things:
|
|
427
|
-
# - Obtain the completions and store them in the global __${
|
|
427
|
+
# - Obtain the completions and store them in the global __${r}_comp_results
|
|
428
428
|
# - Return false if file completion should be performed
|
|
429
|
-
function __${
|
|
430
|
-
__${
|
|
431
|
-
__${
|
|
429
|
+
function __${r}_prepare_completions
|
|
430
|
+
__${r}_debug ""
|
|
431
|
+
__${r}_debug "========= starting completion logic =========="
|
|
432
432
|
|
|
433
433
|
# Start fresh
|
|
434
|
-
set --erase __${
|
|
434
|
+
set --erase __${r}_comp_results
|
|
435
435
|
|
|
436
|
-
__${
|
|
437
|
-
__${
|
|
436
|
+
__${r}_perform_completion_once
|
|
437
|
+
__${r}_debug "Completion results: $__${r}_perform_completion_once_result"
|
|
438
438
|
|
|
439
|
-
if test -z "$__${
|
|
440
|
-
__${
|
|
439
|
+
if test -z "$__${r}_perform_completion_once_result"
|
|
440
|
+
__${r}_debug "No completion, probably due to a failure"
|
|
441
441
|
# Might as well do file completion, in case it helps
|
|
442
442
|
return 1
|
|
443
443
|
end
|
|
444
444
|
|
|
445
|
-
set -l directive (string sub --start 2 $__${
|
|
446
|
-
set --global __${
|
|
445
|
+
set -l directive (string sub --start 2 $__${r}_perform_completion_once_result[-1])
|
|
446
|
+
set --global __${r}_comp_results $__${r}_perform_completion_once_result[1..-2]
|
|
447
447
|
|
|
448
|
-
__${
|
|
449
|
-
__${
|
|
448
|
+
__${r}_debug "Completions are: $__${r}_comp_results"
|
|
449
|
+
__${r}_debug "Directive is: $directive"
|
|
450
450
|
|
|
451
|
-
set -l shellCompDirectiveError ${
|
|
452
|
-
set -l shellCompDirectiveNoSpace ${
|
|
451
|
+
set -l shellCompDirectiveError ${i}
|
|
452
|
+
set -l shellCompDirectiveNoSpace ${a}
|
|
453
453
|
set -l shellCompDirectiveNoFileComp ${o}
|
|
454
454
|
set -l shellCompDirectiveFilterFileExt ${s}
|
|
455
455
|
set -l shellCompDirectiveFilterDirs ${c}
|
|
@@ -460,7 +460,7 @@ function __${n}_prepare_completions
|
|
|
460
460
|
|
|
461
461
|
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
|
462
462
|
if test $compErr -eq 1
|
|
463
|
-
__${
|
|
463
|
+
__${r}_debug "Received error directive: aborting."
|
|
464
464
|
# Might as well do file completion, in case it helps
|
|
465
465
|
return 1
|
|
466
466
|
end
|
|
@@ -468,7 +468,7 @@ function __${n}_prepare_completions
|
|
|
468
468
|
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
|
469
469
|
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
|
470
470
|
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
|
471
|
-
__${
|
|
471
|
+
__${r}_debug "File extension filtering or directory filtering not supported"
|
|
472
472
|
# Do full file completion instead
|
|
473
473
|
return 1
|
|
474
474
|
end
|
|
@@ -476,7 +476,7 @@ function __${n}_prepare_completions
|
|
|
476
476
|
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
|
477
477
|
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
|
478
478
|
|
|
479
|
-
__${
|
|
479
|
+
__${r}_debug "nospace: $nospace, nofiles: $nofiles"
|
|
480
480
|
|
|
481
481
|
# If we want to prevent a space, or if file completion is NOT disabled,
|
|
482
482
|
# we need to count the number of valid completions.
|
|
@@ -485,22 +485,22 @@ function __${n}_prepare_completions
|
|
|
485
485
|
# criteria than the prefix.
|
|
486
486
|
if test $nospace -ne 0; or test $nofiles -eq 0
|
|
487
487
|
set -l prefix (commandline -t | string escape --style=regex)
|
|
488
|
-
__${
|
|
488
|
+
__${r}_debug "prefix: $prefix"
|
|
489
489
|
|
|
490
|
-
set -l completions (string match -r -- "^$prefix.*" $__${
|
|
491
|
-
set --global __${
|
|
492
|
-
__${
|
|
490
|
+
set -l completions (string match -r -- "^$prefix.*" $__${r}_comp_results)
|
|
491
|
+
set --global __${r}_comp_results $completions
|
|
492
|
+
__${r}_debug "Filtered completions are: $__${r}_comp_results"
|
|
493
493
|
|
|
494
494
|
# Important not to quote the variable for count to work
|
|
495
|
-
set -l numComps (count $__${
|
|
496
|
-
__${
|
|
495
|
+
set -l numComps (count $__${r}_comp_results)
|
|
496
|
+
__${r}_debug "numComps: $numComps"
|
|
497
497
|
|
|
498
498
|
if test $numComps -eq 1; and test $nospace -ne 0
|
|
499
499
|
# We must first split on \\t to get rid of the descriptions to be
|
|
500
500
|
# able to check what the actual completion will be.
|
|
501
501
|
# We don't need descriptions anyway since there is only a single
|
|
502
502
|
# real completion which the shell will expand immediately.
|
|
503
|
-
set -l split (string split --max 1 "\\t" $__${
|
|
503
|
+
set -l split (string split --max 1 "\\t" $__${r}_comp_results[1])
|
|
504
504
|
|
|
505
505
|
# Fish won't add a space if the completion ends with any
|
|
506
506
|
# of the following characters: @=/:.,
|
|
@@ -508,16 +508,16 @@ function __${n}_prepare_completions
|
|
|
508
508
|
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
|
509
509
|
# In other cases, to support the "nospace" directive we trick the shell
|
|
510
510
|
# by outputting an extra, longer completion.
|
|
511
|
-
__${
|
|
512
|
-
set --global __${
|
|
513
|
-
__${
|
|
511
|
+
__${r}_debug "Adding second completion to perform nospace directive"
|
|
512
|
+
set --global __${r}_comp_results $split[1] $split[1].
|
|
513
|
+
__${r}_debug "Completions are now: $__${r}_comp_results"
|
|
514
514
|
end
|
|
515
515
|
end
|
|
516
516
|
|
|
517
517
|
if test $numComps -eq 0; and test $nofiles -eq 0
|
|
518
518
|
# To be consistent with bash and zsh, we only trigger file
|
|
519
519
|
# completion when there are no other completions
|
|
520
|
-
__${
|
|
520
|
+
__${r}_debug "Requesting file completion"
|
|
521
521
|
return 1
|
|
522
522
|
end
|
|
523
523
|
end
|
|
@@ -529,38 +529,38 @@ end
|
|
|
529
529
|
# so we can properly delete any completions provided by another script.
|
|
530
530
|
# Only do this if the program can be found, or else fish may print some errors; besides,
|
|
531
531
|
# the existing completions will only be loaded if the program can be found.
|
|
532
|
-
if type -q "${
|
|
532
|
+
if type -q "${t}"
|
|
533
533
|
# The space after the program name is essential to trigger completion for the program
|
|
534
534
|
# and not completion of the program name itself.
|
|
535
535
|
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
|
536
|
-
complete --do-complete "${
|
|
536
|
+
complete --do-complete "${t} " > /dev/null 2>&1
|
|
537
537
|
end
|
|
538
538
|
|
|
539
539
|
# Remove any pre-existing completions for the program since we will be handling all of them.
|
|
540
|
-
complete -c ${
|
|
540
|
+
complete -c ${t} -e
|
|
541
541
|
|
|
542
542
|
# This will get called after the two calls below and clear the cached result
|
|
543
|
-
complete -c ${
|
|
544
|
-
# The call to __${
|
|
543
|
+
complete -c ${t} -n '__${r}_clear_perform_completion_once_result'
|
|
544
|
+
# The call to __${r}_prepare_completions will setup __${r}_comp_results
|
|
545
545
|
# which provides the program's completion choices.
|
|
546
546
|
# If this doesn't require order preservation, we don't use the -k flag
|
|
547
|
-
complete -c ${
|
|
547
|
+
complete -c ${t} -n 'not __${r}_requires_order_preservation && __${r}_prepare_completions' -f -a '$__${r}_comp_results'
|
|
548
548
|
# Otherwise we use the -k flag
|
|
549
|
-
complete -k -c ${
|
|
550
|
-
`}function i(
|
|
549
|
+
complete -k -c ${t} -n '__${r}_requires_order_preservation && __${r}_prepare_completions' -f -a '$__${r}_comp_results'
|
|
550
|
+
`}function i(t,n){let r=t.replace(/[-:]/g,`_`);return`# powershell completion for ${t} -*- shell-script -*-
|
|
551
551
|
|
|
552
552
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
553
|
-
function __${
|
|
553
|
+
function __${t}_debug {
|
|
554
554
|
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
555
555
|
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
558
|
|
|
559
|
-
filter __${
|
|
559
|
+
filter __${t}_escapeStringWithSpecialChars {
|
|
560
560
|
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
[scriptblock]$__${
|
|
563
|
+
[scriptblock]$__${r}CompleterBlock = {
|
|
564
564
|
param(
|
|
565
565
|
$WordToComplete,
|
|
566
566
|
$CommandAst,
|
|
@@ -571,9 +571,9 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
571
571
|
$Command = $CommandAst.CommandElements
|
|
572
572
|
$Command = "$Command"
|
|
573
573
|
|
|
574
|
-
__${
|
|
575
|
-
__${
|
|
576
|
-
__${
|
|
574
|
+
__${t}_debug ""
|
|
575
|
+
__${t}_debug "========= starting completion logic =========="
|
|
576
|
+
__${t}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
577
577
|
|
|
578
578
|
# The user could have moved the cursor backwards on the command-line.
|
|
579
579
|
# We need to trigger completion from the $CursorPosition location, so we need
|
|
@@ -583,24 +583,24 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
583
583
|
if ($Command.Length -gt $CursorPosition) {
|
|
584
584
|
$Command = $Command.Substring(0, $CursorPosition)
|
|
585
585
|
}
|
|
586
|
-
__${
|
|
586
|
+
__${t}_debug "Truncated command: $Command"
|
|
587
587
|
|
|
588
|
-
$ShellCompDirectiveError=${
|
|
589
|
-
$ShellCompDirectiveNoSpace=${
|
|
590
|
-
$ShellCompDirectiveNoFileComp=${
|
|
591
|
-
$ShellCompDirectiveFilterFileExt=${
|
|
592
|
-
$ShellCompDirectiveFilterDirs=${
|
|
593
|
-
$ShellCompDirectiveKeepOrder=${
|
|
588
|
+
$ShellCompDirectiveError=${e.ShellCompDirectiveError}
|
|
589
|
+
$ShellCompDirectiveNoSpace=${e.ShellCompDirectiveNoSpace}
|
|
590
|
+
$ShellCompDirectiveNoFileComp=${e.ShellCompDirectiveNoFileComp}
|
|
591
|
+
$ShellCompDirectiveFilterFileExt=${e.ShellCompDirectiveFilterFileExt}
|
|
592
|
+
$ShellCompDirectiveFilterDirs=${e.ShellCompDirectiveFilterDirs}
|
|
593
|
+
$ShellCompDirectiveKeepOrder=${e.ShellCompDirectiveKeepOrder}
|
|
594
594
|
|
|
595
595
|
# Prepare the command to request completions for the program.
|
|
596
596
|
# Split the command at the first space to separate the program and arguments.
|
|
597
597
|
$Program, $Arguments = $Command.Split(" ", 2)
|
|
598
598
|
|
|
599
599
|
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
600
|
-
__${
|
|
600
|
+
__${t}_debug "QuotedArgs: $QuotedArgs"
|
|
601
601
|
|
|
602
|
-
$RequestComp = "& ${
|
|
603
|
-
__${
|
|
602
|
+
$RequestComp = "& ${n} complete '--' $QuotedArgs"
|
|
603
|
+
__${t}_debug "RequestComp: $RequestComp"
|
|
604
604
|
|
|
605
605
|
# we cannot use $WordToComplete because it
|
|
606
606
|
# has the wrong values if the cursor was moved
|
|
@@ -608,13 +608,13 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
608
608
|
if ($WordToComplete -ne "" ) {
|
|
609
609
|
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
610
610
|
}
|
|
611
|
-
__${
|
|
611
|
+
__${t}_debug "New WordToComplete: $WordToComplete"
|
|
612
612
|
|
|
613
613
|
|
|
614
614
|
# Check for flag with equal sign
|
|
615
615
|
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
616
616
|
if ( $IsEqualFlag ) {
|
|
617
|
-
__${
|
|
617
|
+
__${t}_debug "Completing equal sign flag"
|
|
618
618
|
# Remove the flag part
|
|
619
619
|
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
620
620
|
}
|
|
@@ -622,7 +622,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
622
622
|
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
623
623
|
# If the last parameter is complete (there is a space following it)
|
|
624
624
|
# We add an extra empty parameter so we can indicate this to the go method.
|
|
625
|
-
__${
|
|
625
|
+
__${t}_debug "Adding extra empty parameter"
|
|
626
626
|
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
627
627
|
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
628
628
|
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
@@ -635,7 +635,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
635
635
|
}
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
__${
|
|
638
|
+
__${t}_debug "Calling $RequestComp"
|
|
639
639
|
# First disable ActiveHelp which is not supported for Powershell
|
|
640
640
|
$env:ActiveHelp = 0
|
|
641
641
|
|
|
@@ -649,15 +649,15 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
649
649
|
# There is no directive specified
|
|
650
650
|
$Directive = 0
|
|
651
651
|
}
|
|
652
|
-
__${
|
|
652
|
+
__${t}_debug "The completion directive is: $Directive"
|
|
653
653
|
|
|
654
654
|
# remove directive (last element) from out
|
|
655
655
|
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
656
|
-
__${
|
|
656
|
+
__${t}_debug "The completions are: $Out"
|
|
657
657
|
|
|
658
658
|
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
659
659
|
# Error code. No completion.
|
|
660
|
-
__${
|
|
660
|
+
__${t}_debug "Received error from custom completion go code"
|
|
661
661
|
return
|
|
662
662
|
}
|
|
663
663
|
|
|
@@ -665,7 +665,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
665
665
|
[Array]$Values = $Out | ForEach-Object {
|
|
666
666
|
# Split the output in name and description
|
|
667
667
|
$Name, $Description = $_.Split("\`t", 2)
|
|
668
|
-
__${
|
|
668
|
+
__${t}_debug "Name: $Name Description: $Description"
|
|
669
669
|
|
|
670
670
|
# Look for the longest completion so that we can format things nicely
|
|
671
671
|
if ($Longest -lt $Name.Length) {
|
|
@@ -684,13 +684,13 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
684
684
|
$Space = " "
|
|
685
685
|
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
686
686
|
# remove the space here
|
|
687
|
-
__${
|
|
687
|
+
__${t}_debug "ShellCompDirectiveNoSpace is called"
|
|
688
688
|
$Space = ""
|
|
689
689
|
}
|
|
690
690
|
|
|
691
691
|
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
692
692
|
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
693
|
-
__${
|
|
693
|
+
__${t}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
694
694
|
|
|
695
695
|
# return here to prevent the completion of the extensions
|
|
696
696
|
return
|
|
@@ -702,7 +702,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
702
702
|
|
|
703
703
|
# Join the flag back if we have an equal sign flag
|
|
704
704
|
if ( $IsEqualFlag ) {
|
|
705
|
-
__${
|
|
705
|
+
__${t}_debug "Join the equal sign flag back to the completion value"
|
|
706
706
|
$_.Name = $Flag + "=" + $_.Name
|
|
707
707
|
}
|
|
708
708
|
}
|
|
@@ -713,7 +713,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
716
|
-
__${
|
|
716
|
+
__${t}_debug "ShellCompDirectiveNoFileComp is called"
|
|
717
717
|
|
|
718
718
|
if ($Values.Length -eq 0) {
|
|
719
719
|
# Just print an empty string here so the
|
|
@@ -727,7 +727,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
727
727
|
|
|
728
728
|
# Get the current mode
|
|
729
729
|
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
730
|
-
__${
|
|
730
|
+
__${t}_debug "Mode: $Mode"
|
|
731
731
|
|
|
732
732
|
$Values | ForEach-Object {
|
|
733
733
|
|
|
@@ -752,10 +752,10 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
752
752
|
"Complete" {
|
|
753
753
|
|
|
754
754
|
if ($Values.Length -eq 1) {
|
|
755
|
-
__${
|
|
755
|
+
__${t}_debug "Only one completion left"
|
|
756
756
|
|
|
757
757
|
# insert space after value
|
|
758
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${
|
|
758
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
759
759
|
|
|
760
760
|
} else {
|
|
761
761
|
# Add the proper number of spaces to align the descriptions
|
|
@@ -779,7 +779,7 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
779
779
|
# insert space after value
|
|
780
780
|
# MenuComplete will automatically show the ToolTip of
|
|
781
781
|
# the highlighted value at the bottom of the suggestions.
|
|
782
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${
|
|
782
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
783
783
|
}
|
|
784
784
|
|
|
785
785
|
# TabCompleteNext and in case we get something unknown
|
|
@@ -787,12 +787,12 @@ complete -k -c ${e} -n '__${n}_requires_order_preservation && __${n}_prepare_com
|
|
|
787
787
|
# Like MenuComplete but we don't want to add a space here because
|
|
788
788
|
# the user need to press space anyway to get the completion.
|
|
789
789
|
# Description will not be shown because that's not possible with TabCompleteNext
|
|
790
|
-
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${
|
|
790
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
|
|
794
794
|
}
|
|
795
795
|
}
|
|
796
796
|
|
|
797
|
-
Register-ArgumentCompleter -CommandName '${
|
|
798
|
-
`}
|
|
797
|
+
Register-ArgumentCompleter -CommandName '${t}' -ScriptBlock $__${r}CompleterBlock
|
|
798
|
+
`}export{t as i,r as n,n as r,i as t};
|
|
@@ -64,4 +64,4 @@ declare class RootCommand extends Command {
|
|
|
64
64
|
declare const t: RootCommand;
|
|
65
65
|
declare function script(shell: string, name: string, executable: string): void;
|
|
66
66
|
//#endregion
|
|
67
|
-
export {
|
|
67
|
+
export { Argument, ArgumentHandler, Command, Complete, Completion, Option, OptionHandler, OptionsMap, RootCommand, ShellCompDirective, t as default, script };
|
package/dist/t.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./powershell-BbJLZFR-.js";import i from"node:assert";const a={ShellCompDirectiveError:1,ShellCompDirectiveNoSpace:2,ShellCompDirectiveNoFileComp:4,ShellCompDirectiveFilterFileExt:8,ShellCompDirectiveFilterDirs:16,ShellCompDirectiveKeepOrder:32,shellCompDirectiveMaxValue:64,ShellCompDirectiveDefault:0};var o=class{name;variadic;command;handler;constructor(e,t,n,r=!1){this.command=e,this.name=t,this.handler=n,this.variadic=r}},s=class{value;description;command;handler;alias;isBoolean;constructor(e,t,n,r,i,a){this.command=e,this.value=t,this.description=n,this.handler=r,this.alias=i,this.isBoolean=a}},c=class{value;description;options=new Map;arguments=new Map;parent;constructor(e,t){this.value=e,this.description=t}option(e,t,n,r){let i,a,o;typeof n==`function`?(i=n,a=r,o=!1):typeof n==`string`?(i=void 0,a=n,o=!0):(i=void 0,a=void 0,o=!0);let c=new s(this,e,t,i,a,o);return this.options.set(e,c),this}argument(e,t,n=!1){let r=new o(this,e,t,n);return this.arguments.set(e,r),this}},l=class extends c{commands=new Map;completions=[];directive=a.ShellCompDirectiveDefault;constructor(){super(``,``)}command(e,t){let n=new c(e,t);return this.commands.set(e,n),n}stripOptions(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.startsWith(`-`)){n++;let t=!1,i=this.findOption(this,r);if(i)t=i.isBoolean??!1;else for(let[,e]of this.commands){let n=this.findOption(e,r);if(n){t=n.isBoolean??!1;break}}!t&&n<e.length&&!e[n].startsWith(`-`)&&n++}else t.push(r),n++}return t}matchCommand(e){e=this.stripOptions(e);let t=[],n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];t.push(a);let o=this.commands.get(t.join(` `));if(o)r=o;else{n=e.slice(i,e.length);break}}return[r||this,n]}shouldCompleteFlags(e,t){if(t.startsWith(`-`))return!0;if(e?.startsWith(`-`)){let t=this.findOption(this,e);if(!t){for(let[,n]of this.commands)if(t=this.findOption(n,e),t)break}return!(t&&t.isBoolean)}return!1}shouldCompleteCommands(e){return!e.startsWith(`-`)}handleFlagCompletion(e,t,n,r){let i;if(n.includes(`=`)){let[e]=n.split(`=`);i=e}else if(r?.startsWith(`-`)){let t=this.findOption(e,r);t&&!t.isBoolean&&(i=r)}if(i){let t=this.findOption(e,i);if(t?.handler){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions=n}return}if(n.startsWith(`-`)){let t=n.startsWith(`-`)&&!n.startsWith(`--`),r=n.replace(/^-+/,``);for(let[i,a]of e.options)t&&a.alias&&`-${a.alias}`.startsWith(n)?this.completions.push({value:`-${a.alias}`,description:a.description}):!t&&i.startsWith(r)&&this.completions.push({value:`--${i}`,description:a.description})}}findOption(e,t){let n=e.options.get(t);if(n||(n=e.options.get(t.replace(/^-+/,``)),n))return n;for(let[n,r]of e.options)if(r.alias&&`-${r.alias}`===t)return r}handleCommandCompletion(e,t){let n=this.stripOptions(e);for(let[e,r]of this.commands){if(e===``)continue;let i=e.split(` `);i.slice(0,n.length).every((e,t)=>e===n[t])&&i[n.length]?.startsWith(t)&&this.completions.push({value:i[n.length],description:r.description})}}handlePositionalCompletion(e,t){let n=e.value.split(` `).length,r=Math.max(0,t.length-n),i=Array.from(e.arguments.entries());if(i.length>0){let t;if(r<i.length){let[e,n]=i[r];t=n}else{let e=i[i.length-1][1];e.variadic&&(t=e)}if(t&&t.handler&&typeof t.handler==`function`){let n=[];t.handler.call(t,(e,t)=>n.push({value:e,description:t}),e.options),this.completions.push(...n)}}}complete(e){this.directive=a.ShellCompDirectiveNoFileComp;let t=new Set;this.completions.filter(e=>t.has(e.value)?!1:(t.add(e.value),!0)).filter(t=>{if(e.includes(`=`)){let[,n]=e.split(`=`);return t.value.startsWith(n)}return t.value.startsWith(e)}).forEach(e=>console.log(`${e.value}\t${e.description??``}`)),console.log(`:${this.directive}`)}parse(e){this.completions=[];let t=e[e.length-1]===``;t&&e.pop();let n=e[e.length-1]||``,r=e.slice(0,-1);t&&(n!==``&&r.push(n),n=``);let[i]=this.matchCommand(r),a=r[r.length-1];if(this.shouldCompleteFlags(a,n))this.handleFlagCompletion(i,r,n,a);else{if(a?.startsWith(`-`)&&n===``&&t){let e=this.findOption(this,a);if(!e){for(let[,t]of this.commands)if(e=this.findOption(t,a),e)break}if(e&&e.isBoolean){this.complete(n);return}}this.shouldCompleteCommands(n)&&this.handleCommandCompletion(r,n),i&&i.arguments.size>0&&this.handlePositionalCompletion(i,r)}this.complete(n)}setup(a,o,s){switch(i(s===`zsh`||s===`bash`||s===`fish`||s===`powershell`,`Unsupported shell`),s){case`zsh`:{let t=e(a,o);console.log(t);break}case`bash`:{let e=n(a,o);console.log(e);break}case`fish`:{let e=t(a,o);console.log(e);break}case`powershell`:{let e=r(a,o);console.log(e);break}}}};const u=new l;function d(e,t,n){u.setup(t,n,e)}export{o as Argument,c as Command,s as Option,l as RootCommand,a as ShellCompDirective,u as default,d as script};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bomb.sh/tab",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"main": "./dist/t.js",
|
|
5
5
|
"types": "./dist/t.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@eslint/js": "^9.33.0",
|
|
32
32
|
"@types/node": "^22.7.4",
|
|
33
33
|
"cac": "^6.7.14",
|
|
34
|
-
"citty": "^0.
|
|
34
|
+
"citty": "^0.2.0",
|
|
35
35
|
"commander": "^13.1.0",
|
|
36
36
|
"eslint": "^9.33.0",
|
|
37
37
|
"eslint-config-prettier": "^10.0.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"cac": "^6.7.14",
|
|
48
|
-
"citty": "^0.1.6",
|
|
48
|
+
"citty": "^0.1.6 || ^0.2.0",
|
|
49
49
|
"commander": "^13.1.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
package/dist/t.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as Completion, c as OptionsMap, d as script, f as t, i as Complete, l as RootCommand, n as ArgumentHandler, o as Option, r as Command, s as OptionHandler, t as Argument, u as ShellCompDirective } from "./t-Cao2EVMz.js";
|
|
2
|
-
export { Argument, ArgumentHandler, Command, Complete, Completion, Option, OptionHandler, OptionsMap, RootCommand, ShellCompDirective, t as default, script };
|
|
File without changes
|
|
File without changes
|