just-bash 2.3.3 → 2.4.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/bin/chunks/cat-ZEMMQGY5.js +6 -0
- package/dist/bin/chunks/chunk-45SNFRCY.js +3 -0
- package/dist/bin/chunks/chunk-OBH7XN5N.js +1 -0
- package/dist/bin/{shell/chunks/chunk-OQRRF62X.js → chunks/chunk-UUQYHLBO.js} +3 -3
- package/dist/bin/chunks/cut-WWPJ2PYT.js +6 -0
- package/dist/bin/chunks/du-XQPYLN3H.js +8 -0
- package/dist/bin/chunks/find-4D6S5MQR.js +11 -0
- package/dist/bin/chunks/grep-U2RCKOEG.js +15 -0
- package/dist/bin/chunks/jq-XH2PXRWE.js +13 -0
- package/dist/bin/chunks/ls-BEHQBUMC.js +26 -0
- package/dist/bin/chunks/sort-C3F6LCNY.js +16 -0
- package/dist/bin/chunks/tree-DQBEJH47.js +12 -0
- package/dist/bin/chunks/uniq-DKS7RIAE.js +5 -0
- package/dist/bin/chunks/wc-4LMTC3QD.js +6 -0
- package/dist/bin/chunks/{xan-ASGSTJP4.js → xan-WNN2ZOAX.js} +48 -48
- package/dist/bin/chunks/{xan-view-YGORUYA2.js → xan-view-6Z6TWXMY.js} +1 -1
- package/dist/bin/chunks/xargs-IWT2HHEA.js +5 -0
- package/dist/bin/just-bash.js +83 -83
- package/dist/bin/shell/chunks/cat-ZEMMQGY5.js +6 -0
- package/dist/bin/shell/chunks/chunk-45SNFRCY.js +3 -0
- package/dist/bin/shell/chunks/chunk-OBH7XN5N.js +1 -0
- package/dist/bin/{chunks/chunk-OQRRF62X.js → shell/chunks/chunk-UUQYHLBO.js} +3 -3
- package/dist/bin/shell/chunks/cut-WWPJ2PYT.js +6 -0
- package/dist/bin/shell/chunks/du-XQPYLN3H.js +8 -0
- package/dist/bin/shell/chunks/find-4D6S5MQR.js +11 -0
- package/dist/bin/shell/chunks/grep-U2RCKOEG.js +15 -0
- package/dist/bin/shell/chunks/jq-XH2PXRWE.js +13 -0
- package/dist/bin/shell/chunks/ls-BEHQBUMC.js +26 -0
- package/dist/bin/shell/chunks/sort-C3F6LCNY.js +16 -0
- package/dist/bin/shell/chunks/tree-DQBEJH47.js +12 -0
- package/dist/bin/shell/chunks/uniq-DKS7RIAE.js +5 -0
- package/dist/bin/shell/chunks/wc-4LMTC3QD.js +6 -0
- package/dist/bin/shell/chunks/{xan-ASGSTJP4.js → xan-WNN2ZOAX.js} +48 -48
- package/dist/bin/shell/chunks/{xan-view-YGORUYA2.js → xan-view-6Z6TWXMY.js} +1 -1
- package/dist/bin/shell/chunks/xargs-IWT2HHEA.js +5 -0
- package/dist/bin/shell/shell.js +72 -72
- package/dist/bundle/browser.js +431 -433
- package/dist/bundle/chunks/cat-W5XITXDC.js +5 -0
- package/dist/bundle/chunks/chunk-4ACWXGKW.js +2 -0
- package/dist/bundle/chunks/{chunk-U4UYWYTO.js → chunk-A263W2RD.js} +3 -3
- package/dist/bundle/chunks/chunk-NUFRM6SI.js +0 -0
- package/dist/bundle/chunks/cut-KKAAQJVD.js +5 -0
- package/dist/bundle/chunks/du-NQXEC3EF.js +7 -0
- package/dist/bundle/chunks/find-GPKJFOPK.js +10 -0
- package/dist/bundle/chunks/grep-CTJRP2G3.js +14 -0
- package/dist/bundle/chunks/jq-AAWVUTC4.js +12 -0
- package/dist/bundle/chunks/ls-5W3NU5OJ.js +23 -0
- package/dist/bundle/chunks/sort-JHO22QVO.js +15 -0
- package/dist/bundle/chunks/tree-MEM64BW3.js +11 -0
- package/dist/bundle/chunks/uniq-SEKCFR7B.js +4 -0
- package/dist/bundle/chunks/wc-52FZ4QGS.js +5 -0
- package/dist/bundle/chunks/{xan-B3RI2BDO.js → xan-ZHXYF6B4.js} +48 -48
- package/dist/bundle/chunks/{xan-view-33AU6NPN.js → xan-view-DMFUMZG7.js} +1 -1
- package/dist/bundle/chunks/xargs-4FRA6OJ7.js +4 -0
- package/dist/bundle/index.js +65 -65
- package/dist/commands/find/matcher.d.ts +5 -0
- package/dist/commands/xan/csv.d.ts +5 -0
- package/dist/utils/constants.d.ts +15 -0
- package/dist/utils/file-reader.d.ts +4 -1
- package/package.json +1 -1
- package/dist/bin/chunks/cat-7TVSOZLU.js +0 -6
- package/dist/bin/chunks/chunk-J7MJV6WO.js +0 -3
- package/dist/bin/chunks/cut-VCKWLT2T.js +0 -6
- package/dist/bin/chunks/du-ZONJJZUK.js +0 -8
- package/dist/bin/chunks/find-P6UQXFKX.js +0 -11
- package/dist/bin/chunks/grep-L5HBHEEQ.js +0 -15
- package/dist/bin/chunks/jq-MTQKMJJI.js +0 -16
- package/dist/bin/chunks/ls-FSSC77F4.js +0 -26
- package/dist/bin/chunks/sort-J5ARYV56.js +0 -16
- package/dist/bin/chunks/tree-ESVATRDW.js +0 -12
- package/dist/bin/chunks/uniq-7JNZWE5D.js +0 -5
- package/dist/bin/chunks/wc-OFU3HUEZ.js +0 -6
- package/dist/bin/chunks/xargs-WIJC4RTG.js +0 -4
- package/dist/bin/shell/chunks/cat-7TVSOZLU.js +0 -6
- package/dist/bin/shell/chunks/chunk-J7MJV6WO.js +0 -3
- package/dist/bin/shell/chunks/cut-VCKWLT2T.js +0 -6
- package/dist/bin/shell/chunks/du-ZONJJZUK.js +0 -8
- package/dist/bin/shell/chunks/find-P6UQXFKX.js +0 -11
- package/dist/bin/shell/chunks/grep-L5HBHEEQ.js +0 -15
- package/dist/bin/shell/chunks/jq-MTQKMJJI.js +0 -16
- package/dist/bin/shell/chunks/ls-FSSC77F4.js +0 -26
- package/dist/bin/shell/chunks/sort-J5ARYV56.js +0 -16
- package/dist/bin/shell/chunks/tree-ESVATRDW.js +0 -12
- package/dist/bin/shell/chunks/uniq-7JNZWE5D.js +0 -5
- package/dist/bin/shell/chunks/wc-OFU3HUEZ.js +0 -6
- package/dist/bin/shell/chunks/xargs-WIJC4RTG.js +0 -4
- package/dist/bundle/chunks/cat-CE7XIAD2.js +0 -5
- package/dist/bundle/chunks/chunk-3YNHMZ5M.js +0 -2
- package/dist/bundle/chunks/cut-MCCSW2TZ.js +0 -5
- package/dist/bundle/chunks/du-3NURMGXT.js +0 -7
- package/dist/bundle/chunks/find-QJDJJ5KW.js +0 -10
- package/dist/bundle/chunks/grep-4K5T3MYL.js +0 -14
- package/dist/bundle/chunks/jq-QAA4WF2O.js +0 -15
- package/dist/bundle/chunks/ls-CS3TIKWR.js +0 -23
- package/dist/bundle/chunks/sort-PMLMEZ4E.js +0 -15
- package/dist/bundle/chunks/tree-5TYW7S7K.js +0 -11
- package/dist/bundle/chunks/uniq-ONGDGSEB.js +0 -4
- package/dist/bundle/chunks/wc-Y5MNUNQQ.js +0 -5
- package/dist/bundle/chunks/xargs-2IMBHM4N.js +0 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as p}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as d}from"./chunk-TA7RUHGQ.js";import{a as c,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var f={name:"cat",summary:"concatenate files and print on the standard output",usage:"cat [OPTION]... [FILE]...",options:["-n, --number number all output lines"," --help display this help and exit"]},b={number:{short:"n",long:"number",type:"boolean"}},w={name:"cat",async execute(t,r){if(m(t))return c(f);let e=d("cat",t,b);if(!e.ok)return e.error;let s=e.result.flags.number,o=e.result.positional,a=await p(r,o,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),n="",i=1;for(let{content:l}of a.files)if(s){let u=h(l,i);n+=u.content,i=u.nextLineNumber}else n+=l;return{stdout:n,stderr:a.stderr,exitCode:a.exitCode}}};function h(t,r){let e=t.split(`
|
|
3
|
+
`),s=t.endsWith(`
|
|
4
|
+
`),o=s?e.slice(0,-1):e;return{content:o.map((n,i)=>`${String(r+i).padStart(6," ")} ${n}`).join(`
|
|
5
|
+
`)+(s?`
|
|
6
|
+
`:""),nextLineNumber:r+o.length}}export{w as catCommand};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
async function w(t,n,s){let{cmdName:r,allowStdinMarker:f=!0,stopOnError:a=!1,batchSize:u=100}=s;if(n.length===0)return{files:[{filename:"",content:t.stdin}],stderr:"",exitCode:0};let i=[],c="",l=0;for(let o=0;o<n.length;o+=u){let d=n.slice(o,o+u),m=await Promise.all(d.map(async e=>{if(f&&e==="-")return{filename:"-",content:t.stdin,error:null};try{let h=t.fs.resolvePath(t.cwd,e),p=await t.fs.readFile(h);return{filename:e,content:p,error:null}}catch{return{filename:e,content:"",error:`${r}: ${e}: No such file or directory
|
|
3
|
+
`}}}));for(let e of m)if(e.error){if(c+=e.error,l=1,a)return{files:i,stderr:c,exitCode:l}}else i.push({filename:e.filename,content:e.content})}return{files:i,stderr:c,exitCode:l}}async function E(t,n,s){let r=await w(t,n,{...s,stopOnError:!0});return r.exitCode!==0?{ok:!1,error:{stdout:"",stderr:r.stderr,exitCode:r.exitCode}}:{ok:!0,content:r.files.map(a=>a.content).join("")}}export{w as a,E as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as y}from"./chunk-QSDVMMYI.js";import{e as x}from"./chunk-KGOUQS5A.js";var g=x(y(),1);function j(n){let r=g.default.parse(n.trim(),{header:!0,dynamicTyping:!0,skipEmptyLines:!0});return{headers:r.meta.fields||[],data:r.data}}function C(n,r){return r.length===0?`${n.join(",")}
|
|
3
3
|
`:`${g.default.unparse(r,{columns:n}).replace(/\r\n/g,`
|
|
4
4
|
`)}
|
|
5
5
|
`}async function w(n,r){let s=n.find(p=>!p.startsWith("-")),i;if(!s||s==="-")i=r.stdin;else try{let p=r.fs.resolvePath(r.cwd,s);i=await r.fs.readFile(p)}catch{return{headers:[],data:[],error:{stdout:"",stderr:`xan: ${s}: No such file or directory
|
|
6
|
-
`,exitCode:1}}}let{headers:a,data:d}=
|
|
6
|
+
`,exitCode:1}}}let{headers:a,data:d}=j(i);return{headers:a,data:d}}async function S(n,r){let s=0,i=[],a=[];for(let t=0;t<n.length;t++){let e=n[t];(e==="-l"||e==="--limit")&&t+1<n.length?s=Number.parseInt(n[++t],10):(e==="-s"||e==="--select")&&t+1<n.length?i=n[++t].split(","):e.startsWith("-")||a.push(e)}let{headers:d,data:p,error:h}=await w(a,r);if(h)return h;let l=i.length>0?i.filter(t=>d.includes(t)):d,c=s>0?p.slice(0,s):p,f=Math.max(...l.map(t=>t.length)),o=[],$="\u2500".repeat(80);for(let t=0;t<c.length;t++){let e=c[t];o.push(`Row n\xB0${t}`),o.push($);for(let u of l){let m=e[u],v=m==null?"":String(m);o.push(`${u.padEnd(f)} ${v}`)}t<c.length-1&&o.push("")}return{stdout:`${o.join(`
|
|
7
7
|
`)}
|
|
8
8
|
`,stderr:"",exitCode:0}}async function W(n,r){let s=0,i=[];for(let t=0;t<n.length;t++){let e=n[t];e==="-n"&&t+1<n.length?s=Number.parseInt(n[++t],10):e.startsWith("-")||i.push(e)}let{headers:a,data:d,error:p}=await w(i,r);if(p)return p;let h=s>0?d.slice(0,s):d,l=a.map(t=>t.length);for(let t of h)for(let e=0;e<a.length;e++){let u=String(t[a[e]]??"");l[e]=Math.max(l[e],u.length)}let c=[],f="\u2500",o="\u2502";c.push(`\u250C${l.map(t=>f.repeat(t+2)).join("\u252C")}\u2510`);let $=a.map((t,e)=>` ${t.padEnd(l[e])} `).join(o);c.push(`${o}${$}${o}`),c.push(`\u251C${l.map(t=>f.repeat(t+2)).join("\u253C")}\u2524`);for(let t of h){let e=a.map((u,m)=>` ${String(t[u]??"").padEnd(l[m])} `).join(o);c.push(`${o}${e}${o}`)}return c.push(`\u2514${l.map(t=>f.repeat(t+2)).join("\u2534")}\u2518`),{stdout:`${c.join(`
|
|
9
9
|
`)}
|
|
10
|
-
`,stderr:"",exitCode:0}}export{
|
|
10
|
+
`,stderr:"",exitCode:0}}export{j as a,C as b,w as c,S as d,W as e};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as x}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as y,b as I,c as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var W={name:"cut",summary:"remove sections from each line of files",usage:"cut [OPTION]... [FILE]...",options:["-c LIST select only these characters","-d DELIM use DELIM instead of TAB for field delimiter","-f LIST select only these fields","-s, --only-delimited do not print lines without delimiters"," --help display this help and exit"]};function k(t){let c=[],l=t.split(",");for(let n of l)if(n.includes("-")){let[s,r]=n.split("-");c.push({start:s?parseInt(s,10):1,end:r?parseInt(r,10):null})}else{let s=parseInt(n,10);c.push({start:s,end:s})}return c}function C(t,c){let l=[];for(let n of c){let s=n.start-1,r=n.end===null?t.length:n.end;for(let i=s;i<r&&i<t.length;i++)i>=0&&!l.includes(t[i])&&l.push(t[i])}return l}var E={name:"cut",async execute(t,c){if(I(t))return y(W);let l=" ",n=null,s=null,r=!1,i=[];for(let o=0;o<t.length;o++){let e=t[o];if(e==="-d")l=t[++o]||" ";else if(e.startsWith("-d"))l=e.slice(2);else if(e==="-f")n=t[++o];else if(e.startsWith("-f"))n=e.slice(2);else if(e==="-c")s=t[++o];else if(e.startsWith("-c"))s=e.slice(2);else if(e==="-s"||e==="--only-delimited")r=!0;else{if(e.startsWith("--"))return m("cut",e);if(e.startsWith("-")){let f=!1;for(let u of e.slice(1))if(u==="s")r=!0;else if(!"dfc".includes(u)){f=!0;break}if(f)return m("cut",e)}else i.push(e)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
|
|
3
|
+
`,exitCode:1};let p=await x(c,i,{cmdName:"cut"});if(!p.ok)return p.error;let a=p.content.split(`
|
|
4
|
+
`);a.length>0&&a[a.length-1]===""&&a.pop();let g=k(n||s||"1"),h="";for(let o of a)if(s){let e=o.split(""),f=[];for(let u of g){let w=u.start-1,L=u.end===null?e.length:u.end;for(let d=w;d<L&&d<e.length;d++)d>=0&&f.push(e[d])}h+=`${f.join("")}
|
|
5
|
+
`}else{if(r&&!o.includes(l))continue;let e=o.split(l),f=C(e,g);h+=`${f.join(l)}
|
|
6
|
+
`}return{stdout:h,stderr:"",exitCode:0}}};export{E as cutCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-OBH7XN5N.js";import{a as F}from"./chunk-TA7RUHGQ.js";import{a as $,b as w}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var R={name:"du",summary:"estimate file space usage",usage:"du [OPTION]... [FILE]...",options:["-a write counts for all files, not just directories","-h print sizes in human readable format","-s display only a total for each argument","-c produce a grand total","--max-depth=N print total for directory only if N or fewer levels deep"," --help display this help and exit"]},x={allFiles:{short:"a",type:"boolean"},humanReadable:{short:"h",type:"boolean"},summarize:{short:"s",type:"boolean"},grandTotal:{short:"c",type:"boolean"},maxDepth:{long:"max-depth",type:"number"}},H={name:"du",async execute(a,s){if(w(a))return $(R);let n=F("du",a,x);if(!n.ok)return n.error;let r={allFiles:n.result.flags.allFiles,humanReadable:n.result.flags.humanReadable,summarize:n.result.flags.summarize,grandTotal:n.result.flags.grandTotal,maxDepth:n.result.flags.maxDepth??null},c=n.result.positional;c.length===0&&c.push(".");let o="",m="",h=0;for(let l of c){let z=s.fs.resolvePath(s.cwd,l);try{await s.fs.stat(z);let p=await b(s,z,l,r,0);o+=p.output,h+=p.totalSize,m+=p.stderr}catch{m+=`du: cannot access '${l}': No such file or directory
|
|
3
|
+
`}}return r.grandTotal&&c.length>0&&(o+=`${D(h,r.humanReadable)} total
|
|
4
|
+
`),{stdout:o,stderr:m,exitCode:m?1:0}}};async function b(a,s,n,r,c){let o={output:"",totalSize:0,stderr:""};try{let m=await a.fs.stat(s);if(!m.isDirectory)return o.totalSize=m.size,(r.allFiles||c===0)&&(o.output=D(m.size,r.humanReadable)+" "+n+`
|
|
5
|
+
`),o;let h=0,l=[];if(a.fs.readdirWithFileTypes){let t=await a.fs.readdirWithFileTypes(s),i=t.filter(e=>e.isFile),f=t.filter(e=>e.isDirectory);for(let e=0;e<i.length;e+=100){let u=i.slice(e,e+100),g=await Promise.all(u.map(async d=>{let T=s==="/"?`/${d.name}`:`${s}/${d.name}`;try{let S=await a.fs.stat(T);return{name:d.name,isDirectory:!1,size:S.size}}catch{return{name:d.name,isDirectory:!1,size:0}}}));l.push(...g)}l.push(...f.map(e=>({name:e.name,isDirectory:!0})))}else{let t=await a.fs.readdir(s);for(let i=0;i<t.length;i+=100){let f=t.slice(i,i+100),e=await Promise.all(f.map(async u=>{let g=s==="/"?`/${u}`:`${s}/${u}`;try{let d=await a.fs.stat(g);return{name:u,isDirectory:d.isDirectory,size:d.isDirectory?void 0:d.size}}catch{return{name:u,isDirectory:!1,size:0}}}));l.push(...e)}}l.sort((t,i)=>t.name.localeCompare(i.name));let z=l.filter(t=>!t.isDirectory);for(let t of z){let i=t.size??0;if(h+=i,r.allFiles&&!r.summarize){let f=n==="."?t.name:`${n}/${t.name}`;o.output+=D(i,r.humanReadable)+" "+f+`
|
|
6
|
+
`}}let p=l.filter(t=>t.isDirectory);for(let t=0;t<p.length;t+=100){let i=p.slice(t,t+100),f=await Promise.all(i.map(async e=>{let u=s==="/"?`/${e.name}`:`${s}/${e.name}`,g=n==="."?e.name:`${n}/${e.name}`;return{name:e.name,result:await b(a,u,g,r,c+1)}}));f.sort((e,u)=>e.name.localeCompare(u.name));for(let{result:e}of f)h+=e.totalSize,r.summarize||(r.maxDepth===null||c+1<=r.maxDepth)&&(o.output+=e.output)}o.totalSize=h,(r.summarize||r.maxDepth===null||c<=r.maxDepth)&&(o.output+=`${D(h,r.humanReadable)} ${n}
|
|
7
|
+
`)}catch{o.stderr=`du: cannot read directory '${n}': Permission denied
|
|
8
|
+
`}return o}function D(a,s){return s?a<1024?`${a}`:a<1024*1024?`${(a/1024).toFixed(1)}K`:a<1024*1024*1024?`${(a/(1024*1024)).toFixed(1)}M`:`${(a/(1024*1024*1024)).toFixed(1)}G`:String(Math.ceil(a/1024)||1)}export{H as duCommand};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as H}from"./chunk-26Q3PZQ6.js";import{a as J,b as U,c as q}from"./chunk-PM2DS2YW.js";import"./chunk-OBH7XN5N.js";import{a as _,b as V}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function F(e,s){switch(e.type){case"name":return{matches:H(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:H(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=r>e.days:e.comparison==="less"?t=r<e.days:t=Math.floor(r)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let r;return e.comparison==="more"?r=s.size>n:e.comparison==="less"?r=s.size<n:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,r=e.mode&511,t;return e.matchType==="exact"?t=n===r:e.matchType==="all"?t=(n&r)===r:t=(n&r)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=F(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=F(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=F(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=F(e.left,s);if(n.matches)return n;let r=F(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function z(e){if(!e)return!1;switch(e.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!1;case"empty":case"mtime":case"newer":case"size":case"perm":return!0;case"not":return z(e.expr);case"and":case"or":return z(e.left)||z(e.right)}}function K(e){let s=[],n=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(e),s}function Q(e,s){let n=[],r=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let i=e[++t];if(i==="f"||i==="d")n.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${i}
|
|
3
|
+
`,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("+")?(c="more",p=i.slice(1)):i.startsWith("-")&&(c="less",p=i.slice(1));let u=parseInt(p,10);Number.isNaN(u)||n.push({type:"expr",expr:{type:"mtime",days:u,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let i=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(a==="-size"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("+")?(c="more",p=i.slice(1)):i.startsWith("-")&&(c="less",p=i.slice(1));let u=p.match(/^(\d+)([ckMGb])?$/);if(u){let W=parseInt(u[1],10),E=u[2]||"b";n.push({type:"expr",expr:{type:"size",value:W,unit:E,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("-")?(c="all",p=i.slice(1)):i.startsWith("/")&&(c="any",p=i.slice(1));let u=parseInt(p,8);Number.isNaN(u)||n.push({type:"expr",expr:{type:"perm",mode:u,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let i=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)i.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";r.push({type:"exec",command:i,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(a==="-print0")r.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let i=e[++t];r.push({type:"printf",format:i})}else if(a==="-delete")r.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
|
|
4
|
+
`,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:r};let D=te(n);return D.error?{expr:null,pathIndex:t,error:D.error,actions:r}:{expr:D.expr,pathIndex:t,actions:r}}function te(e){let s=0;function n(){let i=r();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let p=r();if(!p)return i;i={type:"or",left:i,right:p}}else break}return i}function r(){let i=t();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let p=t();if(!p)return i;i={type:"and",left:i,right:p}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let p=t();if(!p)return i;i={type:"and",left:i,right:p}}else break}return i}function t(){if(s<e.length&&e[s].type==="not"){s++;let i=t();return i?{type:"not",expr:i}:null}return D()}function D(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:n()}}var ne={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},se=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),ge={name:"find",async execute(e,s){if(V(e))return _(ne);let n=[],r=null,t=null,D=!1,a=!1;for(let o=0;o<e.length;o++){let l=e[o];if(l==="-maxdepth"&&o+1<e.length)a=!0,r=parseInt(e[++o],10);else if(l==="-mindepth"&&o+1<e.length)a=!0,t=parseInt(e[++o],10);else if(l==="-depth")a=!0,D=!0;else if(l==="-exec")for(a=!0,o++;o<e.length&&e[o]!==";"&&e[o]!=="+";)o++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):se.has(l)?(a=!0,o++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:p}=Q(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let u=p.some(o=>o.type==="print"),W=p.length===0,E=[],j=p.some(o=>o.type==="printf"),Y=[],A="",C=0,Z=K(i),L=new Map;for(let o of Z){let l=s.fs.resolvePath(s.cwd,o);try{let I=await s.fs.stat(l);L.set(o,I.mtime?.getTime()??Date.now())}catch{}}let X=z(i)||j,ee=typeof s.fs.readdirWithFileTypes=="function";for(let o of n){let b=function(h){let d=t===null||h.depth>=t,T=!1;if(d&&i!==null){let m={name:h.name,relativePath:h.relativePath,isFile:h.isFile,isDirectory:h.isDirectory,isEmpty:h.isEmpty,mtime:h.stat?.mtime?.getTime()??Date.now(),size:h.stat?.size??0,mode:h.stat?.mode??420,newerRefTimes:L},f=F(i,m);d=f.matches,T=u?f.printed:d}else d&&(T=!0);return T?{print:!0,printfData:j?{path:h.relativePath,name:h.name,size:h.stat?.size??0,mtime:h.stat?.mtime?.getTime()??Date.now(),mode:h.stat?.mode??420,isDirectory:h.isDirectory,depth:h.depth,startingPoint:o}:null}:{print:!1,printfData:null}};var le=b;o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1));let l=s.fs.resolvePath(s.cwd,o);try{await s.fs.stat(l)}catch{A+=`find: ${o}: No such file or directory
|
|
5
|
+
`,C=1;continue}async function I(h){let{path:P,depth:d,typeInfo:T}=h;if(r!==null&&d>r)return null;let v,m,f;if(T&&!X)v=T.isFile,m=T.isDirectory;else{try{f=await s.fs.stat(P)}catch{return null}if(!f)return null;v=f.isFile,m=f.isDirectory}let y;P===l?y=o.split("/").pop()||o:y=P.split("/").pop()||"";let g=P===l?o:o==="."?`./${P.slice(l==="/"?l.length:l.length+1)}`:o+P.slice(l.length),S=[],M=null,$=null;m&&(ee&&s.fs.readdirWithFileTypes?(M=await s.fs.readdirWithFileTypes(P),S=M.map((R,O)=>({path:P==="/"?`/${R.name}`:`${P}/${R.name}`,depth:d+1,typeInfo:{isFile:R.isFile,isDirectory:R.isDirectory},resultIndex:O})),$=M.map(R=>R.name)):($=await s.fs.readdir(P),S=$.map((R,O)=>({path:P==="/"?`/${R}`:`${P}/${R}`,depth:d+1,resultIndex:O}))));let w=v?(f?.size??0)===0:$!==null&&$.length===0,B=!1;if(!D&&i!==null){let R={name:y,relativePath:g,isFile:v,isDirectory:m,isEmpty:w,mtime:f?.mtime?.getTime()??Date.now(),size:f?.size??0,mode:f?.mode??420,newerRefTimes:L};B=F(i,R).pruned}return{relativePath:g,name:y,isFile:v,isDirectory:m,isEmpty:w,stat:f,depth:d,children:B?[]:S,pruned:B}}async function x(){let h={paths:[],printfData:[]};if(D){let m=function(f){let y={paths:[],printfData:[]},g=d[f];if(!g)return y;for(let $ of g.childIndices){let w=m($);y.paths.push(...w.paths),y.printfData.push(...w.printfData)}let{print:S,printfData:M}=b(g.node);return S&&(y.paths.push(g.node.relativePath),M&&y.printfData.push(M)),y};var P=m;let d=[],T=[{item:{path:l,depth:0,resultIndex:0},parentIndex:-1,childOrderInParent:0}],v=new Map;for(;T.length>0;){let f=T.splice(0,100),y=await Promise.all(f.map(g=>I(g.item)));for(let g=0;g<f.length;g++){let S=y[g],M=f[g];if(!S)continue;let $=d.length;if(M.parentIndex>=0){let w=v.get(M.parentIndex)||[];w.push($),v.set(M.parentIndex,w)}d.push({node:S,parentIndex:M.parentIndex,childIndices:[]});for(let w=0;w<S.children.length;w++)T.push({item:S.children[w],parentIndex:$,childOrderInParent:w})}}for(let[f,y]of v)f>=0&&f<d.length&&(d[f].childIndices=y);if(d.length>0){let f=m(0);h.paths.push(...f.paths),h.printfData.push(...f.printfData)}}else{async function d(v){let m={paths:[],printfData:[]},f=await I(v);if(!f)return m;let{print:y,printfData:g}=b(f);y&&(m.paths.push(f.relativePath),g&&m.printfData.push(g));for(let S=0;S<f.children.length;S+=100){let M=f.children.slice(S,S+100),$=await Promise.all(M.map(d));for(let w of $)m.paths.push(...w.paths),m.printfData.push(...w.printfData)}return m}let T=await d({path:l,depth:0,resultIndex:0});h.paths.push(...T.paths),h.printfData.push(...T.printfData)}return h}let k=await x();E.push(...k.paths),Y.push(...k.printfData)}let N="";if(p.length>0)for(let o of p)switch(o.type){case"print":N+=E.length>0?`${E.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"";break;case"print0":N+=E.length>0?`${E.join("\0")}\0`:"";break;case"delete":{let l=[...E].sort((I,b)=>b.length-I.length);for(let I of l){let b=s.fs.resolvePath(s.cwd,I);try{await s.fs.rm(b,{recursive:!1})}catch(x){let k=x instanceof Error?x.message:String(x);A+=`find: cannot delete '${I}': ${k}
|
|
8
|
+
`,C=1}}break}case"printf":for(let l of Y)N+=re(o.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
9
|
+
`,exitCode:1};if(o.batchMode){let l=[];for(let x of o.command)x==="{}"?l.push(...E):l.push(x);let I=l.map(x=>`"${x}"`).join(" "),b=await s.exec(I,{cwd:s.cwd});N+=b.stdout,A+=b.stderr,b.exitCode!==0&&(C=b.exitCode)}else for(let l of E){let b=o.command.map(k=>k==="{}"?l:k).map(k=>`"${k}"`).join(" "),x=await s.exec(b,{cwd:s.cwd});N+=x.stdout,A+=x.stderr,x.exitCode!==0&&(C=x.exitCode)}break}else W&&(N=E.length>0?`${E.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:"");return{stdout:N,stderr:A,exitCode:C}}};function re(e,s){let n=q(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[D,a,i]=U(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],p;switch(c){case"f":p=s.name,t++;break;case"h":{let u=s.path.lastIndexOf("/");p=u>0?s.path.slice(0,u):".",t++;break}case"p":p=s.path,t++;break;case"P":{let u=s.startingPoint;s.path===u?p="":s.path.startsWith(`${u}/`)?p=s.path.slice(u.length+1):u==="."&&s.path.startsWith("./")?p=s.path.slice(2):p=s.path,t++;break}case"s":p=String(s.size),t++;break;case"d":p=String(s.depth),t++;break;case"m":p=(s.mode&511).toString(8),t++;break;case"M":p=ie(s.mode,s.isDirectory),t++;break;case"t":{let u=new Date(s.mtime);p=ae(u),t++;break}case"T":{if(t+1<n.length){let u=n[t+1],W=new Date(s.mtime);p=pe(W,u),t+=2}else p="%T",t++;break}default:r+=`%${D!==0||a!==-1?`${D}.${a}`:""}${c}`,t++;continue}r+=J(p,D,a)}else r+=n[t],t++;return r}function ie(e,s){let n=e&511,r=s?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function ae(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=s[e.getDay()],t=n[e.getMonth()],D=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),p=e.getFullYear();return`${r} ${t} ${D} ${a}:${i}:${c} ${p}`}function pe(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{ge as findCommand};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as N}from"./chunk-26Q3PZQ6.js";import{a as j,b as Z,c as q}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var Y={name:"grep",summary:"print lines that match patterns",usage:"grep [OPTION]... PATTERN [FILE]...",options:["-E, --extended-regexp PATTERN is an extended regular expression","-P, --perl-regexp PATTERN is a Perl regular expression","-F, --fixed-strings PATTERN is a set of newline-separated strings","-i, --ignore-case ignore case distinctions","-v, --invert-match select non-matching lines","-w, --word-regexp match only whole words","-x, --line-regexp match only whole lines","-c, --count print only a count of matching lines","-l, --files-with-matches print only names of files with matches","-L, --files-without-match print names of files with no matches","-m NUM, --max-count=NUM stop after NUM matches","-n, --line-number print line number with output lines","-h, --no-filename suppress the file name prefix on output","-o, --only-matching show only nonempty parts of lines that match","-q, --quiet, --silent suppress all normal output","-r, -R, --recursive search directories recursively","-A NUM print NUM lines of trailing context","-B NUM print NUM lines of leading context","-C NUM print NUM lines of context","-e PATTERN use PATTERN for matching"," --include=GLOB search only files matching GLOB"," --exclude=GLOB skip files matching GLOB"," --exclude-dir=DIR skip directories matching DIR"," --help display this help and exit"]},z={name:"grep",async execute(s,e){if(Z(s))return j(Y);let l=!1,i=!1,f=!1,o=!1,w=!1,h=!1,r=!1,$=!1,y=!1,d=!1,m=!1,P=!1,I=!1,R=!1,M=!1,c=0,T=0,a=0,n=[],C=[],S=[],x=null,O=[];for(let p=0;p<s.length;p++){let u=s[p];if(u.startsWith("-")&&u!=="-"){if(u==="-e"&&p+1<s.length){x=s[++p];continue}if(u.startsWith("--include=")){n.push(u.slice(10));continue}if(u.startsWith("--exclude=")){C.push(u.slice(10));continue}if(u.startsWith("--exclude-dir=")){S.push(u.slice(14));continue}if(u.startsWith("--max-count=")){c=parseInt(u.slice(12),10);continue}let A=u.match(/^-m(\d+)$/);if(A){c=parseInt(A[1],10);continue}if(u==="-m"&&p+1<s.length){c=parseInt(s[++p],10);continue}let g=u.match(/^-([ABC])(\d+)$/);if(g){let t=parseInt(g[2],10);g[1]==="A"?a=t:g[1]==="B"?T=t:g[1]==="C"&&(T=t,a=t);continue}if((u==="-A"||u==="-B"||u==="-C")&&p+1<s.length){let t=parseInt(s[++p],10);u==="-A"?a=t:u==="-B"?T=t:(T=t,a=t);continue}let F=u.startsWith("--")?[u]:u.slice(1).split("");for(let t of F)if(t==="i"||t==="--ignore-case")l=!0;else if(t==="n"||t==="--line-number")i=!0;else if(t==="v"||t==="--invert-match")f=!0;else if(t==="c"||t==="--count")o=!0;else if(t==="l"||t==="--files-with-matches")w=!0;else if(t==="L"||t==="--files-without-match")h=!0;else if(t==="r"||t==="R"||t==="--recursive")r=!0;else if(t==="w"||t==="--word-regexp")$=!0;else if(t==="x"||t==="--line-regexp")y=!0;else if(t==="E"||t==="--extended-regexp")d=!0;else if(t==="P"||t==="--perl-regexp")m=!0;else if(t==="F"||t==="--fixed-strings")P=!0;else if(t==="o"||t==="--only-matching")I=!0;else if(t==="h"||t==="--no-filename")R=!0;else if(t==="q"||t==="--quiet"||t==="--silent")M=!0;else{if(t.startsWith("--"))return q("grep",t);if(t.length===1)return q("grep",`-${t}`)}}else x===null?x=u:O.push(u)}if(x===null)return{stdout:"",stderr:`grep: missing pattern
|
|
3
|
+
`,exitCode:2};let W;P?W=x.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):d||m?W=x:W=ee(x),$&&(W=`\\b${W}\\b`),y&&(W=`^${W}$`);let U;try{U=new RegExp(W,l?"gi":"g")}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${x}
|
|
4
|
+
`,exitCode:2}}if(O.length===0&&e.stdin){let p=_(e.stdin,U,f,i,o,"",I,T,a,c);return M?{stdout:"",stderr:"",exitCode:p.matched?0:1}:{stdout:p.output,stderr:"",exitCode:p.matched?0:1}}if(O.length===0)return{stdout:"",stderr:`grep: no input files
|
|
5
|
+
`,exitCode:2};let E="",G="",D=!1,H=!1,v=[];for(let p of O)if(p.includes("*")||p.includes("?")||p.includes("[")){let u=await te(p,e);if(r)for(let A of u){let g=await Q(A.path,e,n,C,S,A.isFile);v.push(...g)}else v.push(...u)}else if(r){let u=await Q(p,e,n,C,S);v.push(...u)}else v.push({path:p});let K=(v.length>1||r)&&!R,k=50;for(let p=0;p<v.length;p+=k){let u=v.slice(p,p+k),A=await Promise.all(u.map(async g=>{let F=g.path,t=F.split("/").pop()||F;if(C.length>0&&!r&&C.some(B=>N(t,B,{stripQuotes:!0}))||n.length>0&&!r&&!n.some(B=>N(t,B,{stripQuotes:!0})))return null;try{let B=e.fs.resolvePath(e.cwd,F),b=!1;if(g.isFile===void 0?b=(await e.fs.stat(B)).isDirectory:b=!g.isFile,b)return r?null:{error:`grep: ${F}: Is a directory
|
|
6
|
+
`};let V=await e.fs.readFile(B),X=_(V,U,f,i,o,K?F:"",I,T,a,c);return{file:F,result:X}}catch{return{error:`grep: ${F}: No such file or directory
|
|
7
|
+
`}}}));for(let g of A){if(g===null)continue;if("error"in g&&g.error){G+=g.error,g.error.includes("Is a directory")||(H=!0);continue}if(!("file"in g)||!g.result)continue;let{file:F,result:t}=g;if(t.matched){if(D=!0,M)return{stdout:"",stderr:"",exitCode:0};w?E+=`${F}
|
|
8
|
+
`:h||(E+=t.output)}else h?E+=`${F}
|
|
9
|
+
`:o&&!w&&(E+=t.output)}}let L;return H?L=2:h?L=E.length>0?0:1:L=D?0:1,M?{stdout:"",stderr:"",exitCode:L}:{stdout:E,stderr:G,exitCode:L}}};function ee(s){let e="",l=0;for(;l<s.length;){let i=s[l];if(i==="\\"&&l+1<s.length){let f=s[l+1];if(f==="|"||f==="("||f===")"){e+=f,l+=2;continue}else if(f==="{"||f==="}"){e+=`\\${f}`,l+=2;continue}}i==="+"||i==="?"||i==="|"||i==="("||i===")"||i==="{"||i==="}"?e+=`\\${i}`:e+=i,l++}return e}function _(s,e,l,i,f,o,w=!1,h=0,r=0,$=0){let y=s.split(`
|
|
10
|
+
`),d=y.length,m=d>0&&y[d-1]===""?d-1:d;if(f){let c=0;for(let a=0;a<m;a++)e.lastIndex=0,e.test(y[a])!==l&&c++;return{output:`${o?`${o}:${c}`:String(c)}
|
|
11
|
+
`,matched:c>0}}if(h===0&&r===0){let c=[],T=!1,a=0;for(let n=0;n<m&&!($>0&&a>=$);n++){let C=y[n];if(e.lastIndex=0,e.test(C)!==l)if(T=!0,a++,w){e.lastIndex=0;for(let x=e.exec(C);x!==null;x=e.exec(C))c.push(o?`${o}:${x[0]}`:x[0]),x[0].length===0&&e.lastIndex++}else i?c.push(o?`${o}:${n+1}:${C}`:`${n+1}:${C}`):c.push(o?`${o}:${C}`:C)}return{output:c.length>0?`${c.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`:"",matched:T}}let P=[],I=0,R=new Set,M=[];for(let c=0;c<m&&!($>0&&I>=$);c++)e.lastIndex=0,e.test(y[c])!==l&&(M.push(c),I++);for(let c of M){for(let a=Math.max(0,c-h);a<c;a++)if(!R.has(a)){R.add(a);let n=y[a];i&&(n=`${a+1}-${n}`),o&&(n=`${o}-${n}`),P.push(n)}if(!R.has(c)){R.add(c);let a=y[c];if(w){e.lastIndex=0;for(let n=e.exec(a);n!==null;n=e.exec(a))P.push(o?`${o}:${n[0]}`:n[0]),n[0].length===0&&e.lastIndex++}else{let n=a;i&&(n=`${c+1}:${n}`),o&&(n=`${o}:${n}`),P.push(n)}}let T=Math.min(m-1,c+r);for(let a=c+1;a<=T;a++)if(!R.has(a)){R.add(a);let n=y[a];i&&(n=`${a+1}-${n}`),o&&(n=`${o}-${n}`),P.push(n)}}return{output:P.length>0?`${P.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`:"",matched:I>0}}async function J(s,e,l,i){let f=l.fs.resolvePath(l.cwd,s);try{if(!(await l.fs.stat(f)).isDirectory){let h=s.split("/").pop()||"";if(e){let r=e.replace(/^\//,"");N(h,r,{stripQuotes:!0})&&i.push(s)}return}let w=await l.fs.readdir(f);for(let h of w){let r=s==="."?h:`${s}/${h}`,$=l.fs.resolvePath(l.cwd,r);if((await l.fs.stat($)).isDirectory)await J(r,e,l,i);else if(e){let d=e.replace(/^\//,"");N(h,d,{stripQuotes:!0})&&i.push(r)}}}catch{}}async function te(s,e){let l=[],i=s.lastIndexOf("/"),f,o;if(i===-1?(f=e.cwd,o=s):(f=s.slice(0,i)||"/",o=s.slice(i+1)),s.includes("**")){let h=[],r=s.split("**"),$=r[0].replace(/\/$/,"")||".",y=r[1]||"";return await J($,y,e,h),h.map(d=>({path:d}))}let w=e.fs.resolvePath(e.cwd,f);try{if(e.fs.readdirWithFileTypes){let h=await e.fs.readdirWithFileTypes(w);for(let r of h)if(N(r.name,o,{stripQuotes:!0})){let $=i===-1?r.name:`${f}/${r.name}`;l.push({path:$,isFile:r.isFile})}}else{let h=await e.fs.readdir(w);for(let r of h)if(N(r,o,{stripQuotes:!0})){let $=i===-1?r:`${f}/${r}`;l.push({path:$})}}}catch{}return l.sort((h,r)=>h.path.localeCompare(r.path))}async function Q(s,e,l=[],i=[],f=[],o){let w=e.fs.resolvePath(e.cwd,s),h=[];try{let r,$;if(o!==void 0)r=o,$=!o;else{let d=await e.fs.stat(w);r=d.isFile,$=d.isDirectory}if(r){let d=s.split("/").pop()||s;return i.length>0&&i.some(m=>N(d,m,{stripQuotes:!0}))?[]:l.length>0&&!l.some(m=>N(d,m,{stripQuotes:!0}))?[]:[{path:s,isFile:!0}]}if(!$)return[];let y=s.split("/").pop()||s;if(f.length>0&&f.some(d=>N(y,d,{stripQuotes:!0})))return[];if(e.fs.readdirWithFileTypes){let d=await e.fs.readdirWithFileTypes(w);for(let m of d){if(m.name.startsWith("."))continue;let P=s==="."?m.name:`${s}/${m.name}`,I=await Q(P,e,l,i,f,m.isFile);h.push(...I)}}else{let d=await e.fs.readdir(w);for(let m of d){if(m.startsWith("."))continue;let P=s==="."?m:`${s}/${m}`,I=await Q(P,e,l,i,f);h.push(...I)}}}catch{}return h}var re={name:"fgrep",async execute(s,e){return z.execute(["-F",...s],e)}},le={name:"egrep",async execute(s,e){return z.execute(["-E",...s],e)}};export{le as egrepCommand,re as fgrepCommand,z as grepCommand};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as w,b as J}from"./chunk-ACRTDIBO.js";import{i as q}from"./chunk-NWWB2XRE.js";import{a as N}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as C,b as E,c as x}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function I(s){let i=[],t=0,o=s.length;for(;t<o;){for(;t<o&&/\s/.test(s[t]);)t++;if(t>=o)break;let a=t,r=s[t];if(r==="{"||r==="["){let n=r,l=r==="{"?"}":"]",c=1,p=!1,d=!1;for(t++;t<o&&c>0;){let h=s[t];d?d=!1:h==="\\"?d=!0:h==='"'?p=!p:p||(h===n?c++:h===l&&c--),t++}if(c!==0)throw new Error(`Unexpected end of JSON input at position ${t} (unclosed ${n})`);i.push(JSON.parse(s.slice(a,t)))}else if(r==='"'){let n=!1;for(t++;t<o;){let l=s[t];if(n)n=!1;else if(l==="\\")n=!0;else if(l==='"'){t++;break}t++}i.push(JSON.parse(s.slice(a,t)))}else if(r==="-"||r>="0"&&r<="9"){for(;t<o&&/[\d.eE+-]/.test(s[t]);)t++;i.push(JSON.parse(s.slice(a,t)))}else if(s.slice(t,t+4)==="true")i.push(!0),t+=4;else if(s.slice(t,t+5)==="false")i.push(!1),t+=5;else if(s.slice(t,t+4)==="null")i.push(null),t+=4;else{let n=s.slice(t,t+10);throw new Error(`Invalid JSON at position ${a}: unexpected '${n.split(/\s/)[0]}'`)}}return i}var H={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input","-j, --join-output don't print newlines after each output","-a, --ascii force ASCII output","-S, --sort-keys sort object keys","-C, --color colorize output (ignored)","-M, --monochrome monochrome output (ignored)"," --tab use tabs for indentation"," --help display this help and exit"]};function g(s,i,t,o,a,r=0){if(s===null||s===void 0)return"null";if(typeof s=="boolean")return String(s);if(typeof s=="number")return Number.isFinite(s)?String(s):"null";if(typeof s=="string")return t?s:JSON.stringify(s);let n=a?" ":" ";if(Array.isArray(s))return s.length===0?"[]":i?`[${s.map(c=>g(c,!0,!1,o,a)).join(",")}]`:`[
|
|
3
|
+
${s.map(c=>n.repeat(r+1)+g(c,!1,!1,o,a,r+1)).join(`,
|
|
4
|
+
`)}
|
|
5
|
+
${n.repeat(r)}]`;if(typeof s=="object"){let l=Object.keys(s);return o&&(l=l.sort()),l.length===0?"{}":i?`{${l.map(p=>`${JSON.stringify(p)}:${g(s[p],!0,!1,o,a)}`).join(",")}}`:`{
|
|
6
|
+
${l.map(p=>{let d=g(s[p],!1,!1,o,a,r+1);return`${n.repeat(r+1)}${JSON.stringify(p)}: ${d}`}).join(`,
|
|
7
|
+
`)}
|
|
8
|
+
${n.repeat(r)}}`}return String(s)}var P={name:"jq",async execute(s,i){if(E(s))return C(H);let t=!1,o=!1,a=!1,r=!1,n=!1,l=!1,c=!1,p=!1,d=".",h=!1,j=[];for(let u=0;u<s.length;u++){let e=s[u];if(e==="-r"||e==="--raw-output")t=!0;else if(e==="-c"||e==="--compact-output")o=!0;else if(e==="-e"||e==="--exit-status")a=!0;else if(e==="-s"||e==="--slurp")r=!0;else if(e==="-n"||e==="--null-input")n=!0;else if(e==="-j"||e==="--join-output")l=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")c=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")p=!0;else if(e==="-")j.push("-");else{if(e.startsWith("--"))return x("jq",e);if(e.startsWith("-")){for(let f of e.slice(1))if(f==="r")t=!0;else if(f==="c")o=!0;else if(f==="e")a=!0;else if(f==="s")r=!0;else if(f==="n")n=!0;else if(f==="j")l=!0;else if(f!=="a"){if(f==="S")c=!0;else if(f!=="C"){if(f!=="M")return x("jq",`-${f}`)}}}else h?j.push(e):(d=e,h=!0)}}}}let S=[];if(!n)if(j.length===0||j.length===1&&j[0]==="-")S.push({source:"stdin",content:i.stdin});else{let u=await N(i,j,{cmdName:"jq",stopOnError:!0});if(u.exitCode!==0)return{stdout:"",stderr:u.stderr,exitCode:2};S=u.files.map(e=>({source:e.filename||"stdin",content:e.content}))}try{let u=J(d),e=[],f={limits:i.limits?{maxIterations:i.limits.maxJqIterations}:void 0,env:i.env};if(n)e=w(null,u,f);else if(r){let m=[];for(let{content:$}of S){let y=$.trim();y&&m.push(...I(y))}e=w(m,u,f)}else for(let{content:m}of S){let $=m.trim();if(!$)continue;let y=I($);for(let A of y)e.push(...w(A,u,f))}let b=e.map(m=>g(m,o,t,c,p)),k=l?"":`
|
|
9
|
+
`,O=b.join(k),F=a&&(e.length===0||e.every(m=>m==null||m===!1))?1:0;return{stdout:O?l?O:`${O}
|
|
10
|
+
`:"",stderr:"",exitCode:F}}catch(u){if(u instanceof q)return{stdout:"",stderr:`jq: ${u.message}
|
|
11
|
+
`,exitCode:q.EXIT_CODE};let e=u.message;return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
|
|
12
|
+
`,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
|
|
13
|
+
`,exitCode:5}}}};export{P as jqCommand};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-OBH7XN5N.js";import{a as U}from"./chunk-TA7RUHGQ.js";import{a as I,b as J}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var G=(n,t,e)=>{let s=n instanceof RegExp?Z(n,e):n,r=t instanceof RegExp?Z(t,e):t,i=s!==null&&r!=null&&wt(s,r,e);return i&&{start:i[0],end:i[1],pre:e.slice(0,i[0]),body:e.slice(i[0]+s.length,i[1]),post:e.slice(i[1]+r.length)}},Z=(n,t)=>{let e=t.match(n);return e?e[0]:null},wt=(n,t,e)=>{let s,r,i,o,l,h=e.indexOf(n),f=e.indexOf(t,h+1),u=h;if(h>=0&&f>0){if(n===t)return[h,f];for(s=[],i=e.length;u>=0&&!l;){if(u===h)s.push(u),h=e.indexOf(n,u+1);else if(s.length===1){let g=s.pop();g!==void 0&&(l=[g,f])}else r=s.pop(),r!==void 0&&r<i&&(i=r,o=f),f=e.indexOf(t,u+1);u=h<f&&h>=0?h:f}s.length&&o!==void 0&&(l=[i,o])}return l};var K="\0SLASH"+Math.random()+"\0",V="\0OPEN"+Math.random()+"\0",F="\0CLOSE"+Math.random()+"\0",X="\0COMMA"+Math.random()+"\0",Y="\0PERIOD"+Math.random()+"\0",St=new RegExp(K,"g"),xt=new RegExp(V,"g"),$t=new RegExp(F,"g"),bt=new RegExp(X,"g"),Et=new RegExp(Y,"g"),At=/\\\\/g,Tt=/\\{/g,Mt=/\\}/g,vt=/\\,/g,Pt=/\\./g;function B(n){return isNaN(n)?n.charCodeAt(0):parseInt(n,10)}function Nt(n){return n.replace(At,K).replace(Tt,V).replace(Mt,F).replace(vt,X).replace(Pt,Y)}function Ot(n){return n.replace(St,"\\").replace(xt,"{").replace($t,"}").replace(bt,",").replace(Et,".")}function Q(n){if(!n)return[""];let t=[],e=G("{","}",n);if(!e)return n.split(",");let{pre:s,body:r,post:i}=e,o=s.split(",");o[o.length-1]+="{"+r+"}";let l=Q(i);return i.length&&(o[o.length-1]+=l.shift(),o.push.apply(o,l)),t.push.apply(t,o),t}function tt(n){return n?(n.slice(0,2)==="{}"&&(n="\\{\\}"+n.slice(2)),z(Nt(n),!0).map(Ot)):[]}function Ct(n){return"{"+n+"}"}function Dt(n){return/^-?0\d/.test(n)}function zt(n,t){return n<=t}function Rt(n,t){return n>=t}function z(n,t){let e=[],s=G("{","}",n);if(!s)return[n];let r=s.pre,i=s.post.length?z(s.post,!1):[""];if(/\$$/.test(s.pre))for(let o=0;o<i.length;o++){let l=r+"{"+s.body+"}"+i[o];e.push(l)}else{let o=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),l=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),h=o||l,f=s.body.indexOf(",")>=0;if(!h&&!f)return s.post.match(/,(?!,).*\}/)?(n=s.pre+"{"+s.body+F+s.post,z(n)):[n];let u;if(h)u=s.body.split(/\.\./);else if(u=Q(s.body),u.length===1&&u[0]!==void 0&&(u=z(u[0],!1).map(Ct),u.length===1))return i.map(a=>s.pre+u[0]+a);let g;if(h&&u[0]!==void 0&&u[1]!==void 0){let a=B(u[0]),c=B(u[1]),p=Math.max(u[0].length,u[1].length),d=u.length===3&&u[2]!==void 0?Math.abs(B(u[2])):1,S=zt;c<a&&(d*=-1,S=Rt);let x=u.some(Dt);g=[];for(let y=a;S(y,c);y+=d){let m;if(l)m=String.fromCharCode(y),m==="\\"&&(m="");else if(m=String(y),x){let b=p-m.length;if(b>0){let $=new Array(b+1).join("0");y<0?m="-"+$+m.slice(1):m=$+m}}g.push(m)}}else{g=[];for(let a=0;a<u.length;a++)g.push.apply(g,z(u[a],!1))}for(let a=0;a<g.length;a++)for(let c=0;c<i.length;c++){let p=r+g[a]+i[c];(!t||h||p)&&e.push(p)}}return e}var R=n=>{if(typeof n!="string")throw new TypeError("invalid pattern");if(n.length>65536)throw new TypeError("pattern is too long")};var Wt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},W=n=>n.replace(/[[\]\\-]/g,"\\$&"),jt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),et=n=>n.join(""),st=(n,t)=>{let e=t;if(n.charAt(e)!=="[")throw new Error("not in a brace expression");let s=[],r=[],i=e+1,o=!1,l=!1,h=!1,f=!1,u=e,g="";t:for(;i<n.length;){let d=n.charAt(i);if((d==="!"||d==="^")&&i===e+1){f=!0,i++;continue}if(d==="]"&&o&&!h){u=i+1;break}if(o=!0,d==="\\"&&!h){h=!0,i++;continue}if(d==="["&&!h){for(let[S,[w,x,y]]of Object.entries(Wt))if(n.startsWith(S,i)){if(g)return["$.",!1,n.length-e,!0];i+=S.length,y?r.push(w):s.push(w),l=l||x;continue t}}if(h=!1,g){d>g?s.push(W(g)+"-"+W(d)):d===g&&s.push(W(d)),g="",i++;continue}if(n.startsWith("-]",i+1)){s.push(W(d+"-")),i+=2;continue}if(n.startsWith("-",i+1)){g=d,i+=2;continue}s.push(W(d)),i++}if(u<i)return["",!1,0,!1];if(!s.length&&!r.length)return["$.",!1,n.length-e,!0];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!f){let d=s[0].length===2?s[0].slice(-1):s[0];return[jt(d),!1,u-e,!1]}let a="["+(f?"^":"")+et(s)+"]",c="["+(f?"":"^")+et(r)+"]";return[s.length&&r.length?"("+a+"|"+c+")":s.length?a:c,l,u-e,!0]};var v=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!0}={})=>e?t?n.replace(/\[([^\/\\])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?n.replace(/\[([^\/\\{}])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1");var Lt=new Set(["!","?","+","*","@"]),nt=n=>Lt.has(n),kt="(?!(?:^|/)\\.\\.?(?:$|/))",j="(?!\\.)",Gt=new Set(["[","."]),Bt=new Set(["..","."]),Ft=new Set("().*{}+?[]^$\\!"),_t=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),_="[^/]",it=_+"*?",rt=_+"+?",O=class n{type;#s;#n;#r=!1;#t=[];#e;#o;#c;#a=!1;#i;#l;#u=!1;constructor(t,e,s={}){this.type=t,t&&(this.#n=!0),this.#e=e,this.#s=this.#e?this.#e.#s:this,this.#i=this.#s===this?s:this.#s.#i,this.#c=this.#s===this?[]:this.#s.#c,t==="!"&&!this.#s.#a&&this.#c.push(this),this.#o=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(let t of this.#t)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#l!==void 0?this.#l:this.type?this.#l=this.type+"("+this.#t.map(t=>String(t)).join("|")+")":this.#l=this.#t.map(t=>String(t)).join("")}#p(){if(this!==this.#s)throw new Error("should only call on root");if(this.#a)return this;this.toString(),this.#a=!0;let t;for(;t=this.#c.pop();){if(t.type!=="!")continue;let e=t,s=e.#e;for(;s;){for(let r=e.#o+1;!s.type&&r<s.#t.length;r++)for(let i of t.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(s.#t[r])}e=s,s=e.#e}}return this}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof n&&e.#e===this))throw new Error("invalid part: "+e);this.#t.push(e)}}toJSON(){let t=this.type===null?this.#t.slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...this.#t.map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#s||this.#s.#a&&this.#e?.type==="!")&&t.push({}),t}isStart(){if(this.#s===this)return!0;if(!this.#e?.isStart())return!1;if(this.#o===0)return!0;let t=this.#e;for(let e=0;e<this.#o;e++){let s=t.#t[e];if(!(s instanceof n&&s.type==="!"))return!1}return!0}isEnd(){if(this.#s===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();let t=this.#e?this.#e.#t.length:0;return this.#o===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let e=new n(this.type,t);for(let s of this.#t)e.copyIn(s);return e}static#h(t,e,s,r){let i=!1,o=!1,l=-1,h=!1;if(e.type===null){let c=s,p="";for(;c<t.length;){let d=t.charAt(c++);if(i||d==="\\"){i=!i,p+=d;continue}if(o){c===l+1?(d==="^"||d==="!")&&(h=!0):d==="]"&&!(c===l+2&&h)&&(o=!1),p+=d;continue}else if(d==="["){o=!0,l=c,h=!1,p+=d;continue}if(!r.noext&&nt(d)&&t.charAt(c)==="("){e.push(p),p="";let S=new n(d,e);c=n.#h(t,S,c,r),e.push(S);continue}p+=d}return e.push(p),c}let f=s+1,u=new n(null,e),g=[],a="";for(;f<t.length;){let c=t.charAt(f++);if(i||c==="\\"){i=!i,a+=c;continue}if(o){f===l+1?(c==="^"||c==="!")&&(h=!0):c==="]"&&!(f===l+2&&h)&&(o=!1),a+=c;continue}else if(c==="["){o=!0,l=f,h=!1,a+=c;continue}if(nt(c)&&t.charAt(f)==="("){u.push(a),a="";let p=new n(c,u);u.push(p),f=n.#h(t,p,f,r);continue}if(c==="|"){u.push(a),a="",g.push(u),u=new n(null,e);continue}if(c===")")return a===""&&e.#t.length===0&&(e.#u=!0),u.push(a),a="",e.push(...g,u),f;a+=c}return e.type=null,e.#n=void 0,e.#t=[t.substring(s-1)],f}static fromGlob(t,e={}){let s=new n(null,void 0,e);return n.#h(t,s,0,e),s}toMMPattern(){if(this!==this.#s)return this.#s.toMMPattern();let t=this.toString(),[e,s,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#i.nocase&&!this.#i.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return s;let l=(this.#i.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${e}$`,l),{_src:e,_glob:t})}get options(){return this.#i}toRegExpSource(t){let e=t??!!this.#i.dot;if(this.#s===this&&this.#p(),!this.type){let h=this.isStart()&&this.isEnd()&&!this.#t.some(c=>typeof c!="string"),f=this.#t.map(c=>{let[p,d,S,w]=typeof c=="string"?n.#d(c,this.#n,h):c.toRegExpSource(t);return this.#n=this.#n||S,this.#r=this.#r||w,p}).join(""),u="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&Bt.has(this.#t[0]))){let p=Gt,d=e&&p.has(f.charAt(0))||f.startsWith("\\.")&&p.has(f.charAt(2))||f.startsWith("\\.\\.")&&p.has(f.charAt(4)),S=!e&&!t&&p.has(f.charAt(0));u=d?kt:S?j:""}let g="";return this.isEnd()&&this.#s.#a&&this.#e?.type==="!"&&(g="(?:$|\\/)"),[u+f+g,v(f),this.#n=!!this.#n,this.#r]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",i=this.#f(e);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){let h=this.toString();return this.#t=[h],this.type=null,this.#n=void 0,[h,v(this.toString()),!1,!1]}let o=!s||t||e||!j?"":this.#f(!0);o===i&&(o=""),o&&(i=`(?:${i})(?:${o})*?`);let l="";if(this.type==="!"&&this.#u)l=(this.isStart()&&!e?j:"")+rt;else{let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?j:"")+it+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;l=r+i+h}return[l,v(i),this.#n=!!this.#n,this.#r]}#f(t){return this.#t.map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[s,r,i,o]=e.toRegExpSource(t);return this.#r=this.#r||o,s}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")}static#d(t,e,s=!1){let r=!1,i="",o=!1;for(let l=0;l<t.length;l++){let h=t.charAt(l);if(r){r=!1,i+=(Ft.has(h)?"\\":"")+h;continue}if(h==="\\"){l===t.length-1?i+="\\\\":r=!0;continue}if(h==="["){let[f,u,g,a]=st(t,l);if(g){i+=f,o=o||u,l+=g-1,e=e||a;continue}}if(h==="*"){i+=s&&t==="*"?rt:it,e=!0;continue}if(h==="?"){i+=_,e=!0;continue}i+=_t(h)}return[i,v(t),!!e,o]}};var q=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!1}={})=>e?t?n.replace(/[?*()[\]{}]/g,"[$&]"):n.replace(/[?*()[\]\\{}]/g,"\\$&"):t?n.replace(/[?*()[\]]/g,"[$&]"):n.replace(/[?*()[\]\\]/g,"\\$&");var E=(n,t,e={})=>(R(t),!e.nocomment&&t.charAt(0)==="#"?!1:new C(t,e).match(n)),qt=/^\*+([^+@!?\*\[\(]*)$/,Ht=n=>t=>!t.startsWith(".")&&t.endsWith(n),It=n=>t=>t.endsWith(n),Jt=n=>(n=n.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(n)),Ut=n=>(n=n.toLowerCase(),t=>t.toLowerCase().endsWith(n)),Zt=/^\*+\.\*+$/,Kt=n=>!n.startsWith(".")&&n.includes("."),Vt=n=>n!=="."&&n!==".."&&n.includes("."),Xt=/^\.\*+$/,Yt=n=>n!=="."&&n!==".."&&n.startsWith("."),Qt=/^\*+$/,te=n=>n.length!==0&&!n.startsWith("."),ee=n=>n.length!==0&&n!=="."&&n!=="..",se=/^\?+([^+@!?\*\[\(]*)?$/,ne=([n,t=""])=>{let e=ct([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},ie=([n,t=""])=>{let e=lt([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},re=([n,t=""])=>{let e=lt([n]);return t?s=>e(s)&&s.endsWith(t):e},oe=([n,t=""])=>{let e=ct([n]);return t?s=>e(s)&&s.endsWith(t):e},ct=([n])=>{let t=n.length;return e=>e.length===t&&!e.startsWith(".")},lt=([n])=>{let t=n.length;return e=>e.length===t&&e!=="."&&e!==".."},ht=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",ot={win32:{sep:"\\"},posix:{sep:"/"}},ae=ht==="win32"?ot.win32.sep:ot.posix.sep;E.sep=ae;var M=Symbol("globstar **");E.GLOBSTAR=M;var ce="[^/]",le=ce+"*?",he="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",ue="(?:(?!(?:\\/|^)\\.).)*?",fe=(n,t={})=>e=>E(e,n,t);E.filter=fe;var T=(n,t={})=>Object.assign({},n,t),pe=n=>{if(!n||typeof n!="object"||!Object.keys(n).length)return E;let t=E;return Object.assign((s,r,i={})=>t(s,r,T(n,i)),{Minimatch:class extends t.Minimatch{constructor(r,i={}){super(r,T(n,i))}static defaults(r){return t.defaults(T(n,r)).Minimatch}},AST:class extends t.AST{constructor(r,i,o={}){super(r,i,T(n,o))}static fromGlob(r,i={}){return t.AST.fromGlob(r,T(n,i))}},unescape:(s,r={})=>t.unescape(s,T(n,r)),escape:(s,r={})=>t.escape(s,T(n,r)),filter:(s,r={})=>t.filter(s,T(n,r)),defaults:s=>t.defaults(T(n,s)),makeRe:(s,r={})=>t.makeRe(s,T(n,r)),braceExpand:(s,r={})=>t.braceExpand(s,T(n,r)),match:(s,r,i={})=>t.match(s,r,T(n,i)),sep:t.sep,GLOBSTAR:M})};E.defaults=pe;var ut=(n,t={})=>(R(n),t.nobrace||!/\{(?:(?!\{).)*\}/.test(n)?[n]:tt(n));E.braceExpand=ut;var de=(n,t={})=>new C(n,t).makeRe();E.makeRe=de;var ge=(n,t,e={})=>{let s=new C(t,e);return n=n.filter(r=>s.match(r)),s.options.nonull&&!n.length&&n.push(t),n};E.match=ge;var at=/[?*]|[+@!]\(.*?\)|\[|\]/,me=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),C=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(t,e={}){R(t),e=e||{},this.options=e,this.pattern=t,this.platform=e.platform||ht,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!e.nonegate,this.comment=!1,this.empty=!1,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let e of t)if(typeof e!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,e=this.options;if(!e.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);let s=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(s),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,o,l)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=i[0]===""&&i[1]===""&&(i[2]==="?"||!at.test(i[2]))&&!at.test(i[3]),f=/^[a-z]:/i.test(i[0]);if(h)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(f)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(h=>this.parse(h))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){let o=this.set[i];o[0]===""&&o[1]===""&&this.globParts[i][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let s=0;s<t.length;s++)for(let r=0;r<t[s].length;r++)t[s][r]==="**"&&(t[s][r]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):e>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(e=>{let s=-1;for(;(s=e.indexOf("**",s+1))!==-1;){let r=s;for(;e[r+1]==="**";)r++;r!==s&&e.splice(s,r-s)}return e})}levelOneOptimize(t){return t.map(e=>(e=e.reduce((s,r)=>{let i=s[s.length-1];return r==="**"&&i==="**"?s:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(s.pop(),s):(s.push(r),s)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let e=!1;do{if(e=!1,!this.preserveMultipleSlashes){for(let r=1;r<t.length-1;r++){let i=t[r];r===1&&i===""&&t[0]===""||(i==="."||i==="")&&(e=!0,t.splice(r,1),r--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=!0,t.pop())}let s=0;for(;(s=t.indexOf("..",s+1))!==-1;){let r=t[s-1];r&&r!=="."&&r!==".."&&r!=="**"&&(e=!0,t.splice(s-1,2),s-=2)}}while(e);return t.length===0?[""]:t}firstPhasePreProcess(t){let e=!1;do{e=!1;for(let s of t){let r=-1;for(;(r=s.indexOf("**",r+1))!==-1;){let o=r;for(;s[o+1]==="**";)o++;o>r&&s.splice(r+1,o-r);let l=s[r+1],h=s[r+2],f=s[r+3];if(l!==".."||!h||h==="."||h===".."||!f||f==="."||f==="..")continue;e=!0,s.splice(r,1);let u=s.slice(0);u[r]="**",t.push(u),r--}if(!this.preserveMultipleSlashes){for(let o=1;o<s.length-1;o++){let l=s[o];o===1&&l===""&&s[0]===""||(l==="."||l==="")&&(e=!0,s.splice(o,1),o--)}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(e=!0,s.pop())}let i=0;for(;(i=s.indexOf("..",i+1))!==-1;){let o=s[i-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=!0;let h=i===1&&s[i+1]==="**"?["."]:[];s.splice(i-1,2,...h),s.length===0&&s.push(""),i-=2}}}}while(e);return t}secondPhasePreProcess(t){for(let e=0;e<t.length-1;e++)for(let s=e+1;s<t.length;s++){let r=this.partsMatch(t[e],t[s],!this.preserveMultipleSlashes);if(r){t[e]=[],t[s]=r;break}}return t.filter(e=>e.length)}partsMatch(t,e,s=!1){let r=0,i=0,o=[],l="";for(;r<t.length&&i<e.length;)if(t[r]===e[i])o.push(l==="b"?e[i]:t[r]),r++,i++;else if(s&&t[r]==="**"&&e[i]===t[r+1])o.push(t[r]),r++;else if(s&&e[i]==="**"&&t[r]===e[i+1])o.push(e[i]),i++;else if(t[r]==="*"&&e[i]&&(this.options.dot||!e[i].startsWith("."))&&e[i]!=="**"){if(l==="b")return!1;l="a",o.push(t[r]),r++,i++}else if(e[i]==="*"&&t[r]&&(this.options.dot||!t[r].startsWith("."))&&t[r]!=="**"){if(l==="a")return!1;l="b",o.push(e[i]),r++,i++}else return!1;return t.length===e.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,e=!1,s=0;for(let r=0;r<t.length&&t.charAt(r)==="!";r++)e=!e,s++;s&&(this.pattern=t.slice(s)),this.negate=e}matchOne(t,e,s=!1){let r=this.options;if(this.isWindows){let d=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),S=!d&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),w=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),x=!w&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),y=S?3:d?0:void 0,m=x?3:w?0:void 0;if(typeof y=="number"&&typeof m=="number"){let[b,$]=[t[y],e[m]];b.toLowerCase()===$.toLowerCase()&&(e[m]=b,m>y?e=e.slice(m):y>m&&(t=t.slice(y)))}}let{optimizationLevel:i=1}=this.options;i>=2&&(t=this.levelTwoFileOptimize(t)),this.debug("matchOne",this,{file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var o=0,l=0,h=t.length,f=e.length;o<h&&l<f;o++,l++){this.debug("matchOne loop");var u=e[l],g=t[o];if(this.debug(e,u,g),u===!1)return!1;if(u===M){this.debug("GLOBSTAR",[e,u,g]);var a=o,c=l+1;if(c===f){for(this.debug("** at the end");o<h;o++)if(t[o]==="."||t[o]===".."||!r.dot&&t[o].charAt(0)===".")return!1;return!0}for(;a<h;){var p=t[a];if(this.debug(`
|
|
3
|
+
globstar while`,t,a,e,c,p),this.matchOne(t.slice(a),e.slice(c),s))return this.debug("globstar found match!",a,h,p),!0;if(p==="."||p===".."||!r.dot&&p.charAt(0)==="."){this.debug("dot detected!",t,a,e,c);break}this.debug("globstar swallow a segment, and continue"),a++}return!!(s&&(this.debug(`
|
|
4
|
+
>>> no match, partial?`,t,a,e,c),a===h))}let d;if(typeof u=="string"?(d=g===u,this.debug("string match",u,g,d)):(d=u.test(g),this.debug("pattern match",u,g,d)),!d)return!1}if(o===h&&l===f)return!0;if(o===h)return s;if(l===f)return o===h-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return ut(this.pattern,this.options)}parse(t){R(t);let e=this.options;if(t==="**")return M;if(t==="")return"";let s,r=null;(s=t.match(Qt))?r=e.dot?ee:te:(s=t.match(qt))?r=(e.nocase?e.dot?Ut:Jt:e.dot?It:Ht)(s[1]):(s=t.match(se))?r=(e.nocase?e.dot?ie:ne:e.dot?re:oe)(s):(s=t.match(Zt))?r=e.dot?Vt:Kt:(s=t.match(Xt))&&(r=Yt);let i=O.fromGlob(t,this.options).toMMPattern();return r&&typeof i=="object"&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let e=this.options,s=e.noglobstar?le:e.dot?he:ue,r=new Set(e.nocase?["i"]:[]),i=t.map(h=>{let f=h.map(g=>{if(g instanceof RegExp)for(let a of g.flags.split(""))r.add(a);return typeof g=="string"?me(g):g===M?M:g._src});f.forEach((g,a)=>{let c=f[a+1],p=f[a-1];g!==M||p===M||(p===void 0?c!==void 0&&c!==M?f[a+1]="(?:\\/|"+s+"\\/)?"+c:f[a]=s:c===void 0?f[a-1]=p+"(?:\\/|\\/"+s+")?":c!==M&&(f[a-1]=p+"(?:\\/|\\/"+s+"\\/)"+c,f[a+1]=M))});let u=f.filter(g=>g!==M);if(this.partial&&u.length>=1){let g=[];for(let a=1;a<=u.length;a++)g.push(u.slice(0,a).join("/"));return"(?:"+g.join("|")+")"}return u.join("/")}).join("|"),[o,l]=t.length>1?["(?:",")"]:["",""];i="^"+o+i+l+"$",this.partial&&(i="^(?:\\/|"+o+i.slice(1,-1)+l+")$"),this.negate&&(i="^(?!"+i+").+$");try{this.regexp=new RegExp(i,[...r].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,e=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&e)return!0;let s=this.options;this.isWindows&&(t=t.split("\\").join("/"));let r=this.slashSplit(t);this.debug(this.pattern,"split",r);let i=this.set;this.debug(this.pattern,"set",i);let o=r[r.length-1];if(!o)for(let l=r.length-2;!o&&l>=0;l--)o=r[l];for(let l=0;l<i.length;l++){let h=i[l],f=r;if(s.matchBase&&h.length===1&&(f=[o]),this.matchOne(f,h,e))return s.flipNegate?!0:!this.negate}return s.flipNegate?!1:this.negate}static defaults(t){return E.defaults(t).Minimatch}};E.AST=O;E.Minimatch=C;E.escape=q;E.unescape=v;function L(n){if(n<1024)return String(n);if(n<1024*1024){let e=n/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(n<1024*1024*1024){let e=n/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=n/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function k(n){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=String(n.getDate()).padStart(2," "),r=new Date,i=new Date(r.getTime()-4320*60*60*1e3);if(n>i){let l=String(n.getHours()).padStart(2,"0"),h=String(n.getMinutes()).padStart(2,"0");return`${e} ${s} ${l}:${h}`}let o=n.getFullYear();return`${e} ${s} ${o}`}var ye={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},we={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},Ie={name:"ls",async execute(n,t){if(J(n))return I(ye);let e=U("ls",n,we);if(!e.ok)return e.error;let s=e.result.flags.showAll,r=e.result.flags.showAlmostAll,i=e.result.flags.longFormat,o=e.result.flags.humanReadable,l=e.result.flags.recursive,h=e.result.flags.reverse,f=e.result.flags.sortBySize,u=e.result.flags.directoryOnly,g=e.result.flags.sortByTime;e.result.flags.onePerLine;let a=e.result.positional;a.length===0&&a.push(".");let c="",p="",d=0;for(let S=0;S<a.length;S++){let w=a[S];if(S>0&&c&&!c.endsWith(`
|
|
5
|
+
|
|
6
|
+
`)&&(c+=`
|
|
7
|
+
`),u){let x=t.fs.resolvePath(t.cwd,w);try{let y=await t.fs.stat(x);if(i){let m=y.isDirectory?"drwxr-xr-x":"-rw-r--r--",b=y.isDirectory?"/":"",$=y.size??0,A=o?L($).padStart(5):String($).padStart(5),P=y.mtime??new Date(0),N=k(P);c+=`${m} 1 user user ${A} ${N} ${w}${b}
|
|
8
|
+
`}else c+=`${w}
|
|
9
|
+
`}catch{p+=`ls: cannot access '${w}': No such file or directory
|
|
10
|
+
`,d=2}continue}if(w.includes("*")||w.includes("?")||w.includes("[")){let x=await Se(w,t,s,r,i,h,o,f);c+=x.stdout,p+=x.stderr,x.exitCode!==0&&(d=x.exitCode)}else{let x=await ft(w,t,s,r,i,l,a.length>1,h,o,f);c+=x.stdout,p+=x.stderr,x.exitCode!==0&&(d=x.exitCode)}}return{stdout:c,stderr:p,exitCode:d}}};async function Se(n,t,e,s,r,i=!1,o=!1,l=!1){let h=e||s,f=t.fs.getAllPaths(),u=t.fs.resolvePath(t.cwd,"."),g=[];for(let a of f){let c=a.startsWith(u)&&a.slice(u.length+1)||a;if(E(c,n)||E(a,n)){let p=c.split("/").pop()||c;if(!h&&p.startsWith("."))continue;g.push(c||a)}}if(g.length===0)return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
11
|
+
`,exitCode:2};if(l){let a=[];for(let c of g){let p=t.fs.resolvePath(t.cwd,c);try{let d=await t.fs.stat(p);a.push({path:c,size:d.size??0})}catch{a.push({path:c,size:0})}}a.sort((c,p)=>p.size-c.size),g.length=0,g.push(...a.map(c=>c.path))}else g.sort();if(i&&g.reverse(),r){let a=[];for(let c of g){let p=t.fs.resolvePath(t.cwd,c);try{let d=await t.fs.stat(p),S=d.isDirectory?"drwxr-xr-x":"-rw-r--r--",w=d.isDirectory?"/":"",x=d.size??0,y=o?L(x).padStart(5):String(x).padStart(5),m=d.mtime??new Date(0),b=k(m);a.push(`${S} 1 user user ${y} ${b} ${c}${w}`)}catch{a.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${c}`)}}return{stdout:`${a.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`,stderr:"",exitCode:0}}return{stdout:`${g.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`,stderr:"",exitCode:0}}async function ft(n,t,e,s,r,i,o,l=!1,h=!1,f=!1,u=!1){let g=e||s,a=t.fs.resolvePath(t.cwd,n);try{let c=await t.fs.stat(a);if(!c.isDirectory){if(r){let S=c.size??0,w=h?L(S).padStart(5):String(S).padStart(5),x=c.mtime??new Date(0),y=k(x);return{stdout:`-rw-r--r-- 1 user user ${w} ${y} ${n}
|
|
16
|
+
`,stderr:"",exitCode:0}}return{stdout:`${n}
|
|
17
|
+
`,stderr:"",exitCode:0}}let p=await t.fs.readdir(a);if(g||(p=p.filter(S=>!S.startsWith("."))),f){let S=[];for(let w of p){let x=a==="/"?`/${w}`:`${a}/${w}`;try{let y=await t.fs.stat(x);S.push({name:w,size:y.size??0})}catch{S.push({name:w,size:0})}}S.sort((w,x)=>x.size-w.size),p=S.map(w=>w.name)}else p.sort();e&&(p=[".","..",...p]),l&&p.reverse();let d="";if((i||o)&&(d+=`${n}:
|
|
18
|
+
`),r){d+=`total ${p.length}
|
|
19
|
+
`;let S=p.filter(m=>m==="."||m===".."),w=p.filter(m=>m!=="."&&m!=="..");for(let m of S)d+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${m}
|
|
20
|
+
`;let x=[];for(let m=0;m<w.length;m+=100){let b=w.slice(m,m+100),$=await Promise.all(b.map(async A=>{let P=a==="/"?`/${A}`:`${a}/${A}`;try{let N=await t.fs.stat(P),pt=N.isDirectory?"drwxr-xr-x":"-rw-r--r--",dt=N.isDirectory?"/":"",H=N.size??0,gt=h?L(H).padStart(5):String(H).padStart(5),mt=N.mtime??new Date(0),yt=k(mt);return{name:A,line:`${pt} 1 user user ${gt} ${yt} ${A}${dt}
|
|
21
|
+
`}}catch{return{name:A,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${A}
|
|
22
|
+
`}}}));x.push(...$)}let y=new Map(w.map((m,b)=>[m,b]));x.sort((m,b)=>(y.get(m.name)??0)-(y.get(b.name)??0));for(let{line:m}of x)d+=m}else d+=p.join(`
|
|
23
|
+
`)+(p.length?`
|
|
24
|
+
`:"");if(i){let S=p.filter(y=>y!=="."&&y!==".."),w=[];if(t.fs.readdirWithFileTypes)w=(await t.fs.readdirWithFileTypes(a)).filter(m=>m.isDirectory&&S.includes(m.name)).map(m=>({name:m.name,isDirectory:!0}));else for(let y=0;y<S.length;y+=100){let m=S.slice(y,y+100),b=await Promise.all(m.map(async $=>{let A=a==="/"?`/${$}`:`${a}/${$}`;try{let P=await t.fs.stat(A);return{name:$,isDirectory:P.isDirectory}}catch{return{name:$,isDirectory:!1}}}));w.push(...b.filter($=>$.isDirectory))}w.sort((y,m)=>y.name.localeCompare(m.name)),l&&w.reverse();let x=[];for(let y=0;y<w.length;y+=100){let m=w.slice(y,y+100),b=await Promise.all(m.map(async $=>{let A=n==="."?`./${$.name}`:`${n}/${$.name}`,P=await ft(A,t,e,s,r,i,!1,l,h,f,!0);return{name:$.name,result:P}}));x.push(...b)}x.sort((y,m)=>y.name.localeCompare(m.name)),l&&x.reverse();for(let{result:y}of x)d+=`
|
|
25
|
+
`,d+=y.stdout}return{stdout:d,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
26
|
+
`,exitCode:2}}}export{Ie as lsCommand};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as O}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as F,b as N,c as k}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var P={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},V={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12};function w(u){let r=u.trim(),e=r.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!e){let n=parseFloat(r);return Number.isNaN(n)?0:n}let l=parseFloat(e[1]),s=(e[2]||"").toLowerCase(),i=P[s]||1;return l*i}function L(u){let r=u.trim().toLowerCase().slice(0,3);return V[r]||0}function D(u,r){let e=u.split(/(\d+)/),l=r.split(/(\d+)/),s=Math.max(e.length,l.length);for(let i=0;i<s;i++){let n=e[i]||"",d=l[i]||"",o=/^\d+$/.test(n)?parseInt(n,10):null,c=/^\d+$/.test(d)?parseInt(d,10):null;if(o!==null&&c!==null){if(o!==c)return o-c}else if(n!==d)return n.localeCompare(d)}return 0}function x(u){return u.replace(/[^a-zA-Z0-9\s]/g,"")}function v(u,r,e){let l=e!==null?e:/\s+/,s=u.split(l),i=r.startField-1;if(i>=s.length)return"";if(r.endField===void 0){let o=s[i]||"";return r.startChar!==void 0&&(o=o.slice(r.startChar-1)),r.ignoreLeading&&(o=o.trimStart()),o}let n=Math.min(r.endField-1,s.length-1),d="";for(let o=i;o<=n&&o<s.length;o++){let c=s[o]||"";if(o===i&&r.startChar!==void 0&&(c=c.slice(r.startChar-1)),o===n&&r.endChar!==void 0){let t=o===i&&r.startChar!==void 0?r.endChar-r.startChar+1:r.endChar;c=c.slice(0,t)}o>i&&(d+=e||" "),d+=c}return r.ignoreLeading&&(d=d.trimStart()),d}function I(u,r,e){let l=u,s=r;if(e.dictionaryOrder&&(l=x(l),s=x(s)),e.ignoreCase&&(l=l.toLowerCase(),s=s.toLowerCase()),e.monthSort){let i=L(l),n=L(s);return i-n}if(e.humanNumeric){let i=w(l),n=w(s);return i-n}if(e.versionSort)return D(l,s);if(e.numeric){let i=parseFloat(l)||0,n=parseFloat(s)||0;return i-n}return l.localeCompare(s)}function M(u){let{keys:r,fieldDelimiter:e,numeric:l,ignoreCase:s,reverse:i,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c,ignoreLeadingBlanks:t,stable:a}=u;return(f,S)=>{let g=f,b=S;if(t&&(g=g.trimStart(),b=b.trimStart()),r.length===0){let h=I(g,b,{numeric:l,ignoreCase:s,humanNumeric:n,versionSort:d,dictionaryOrder:o,monthSort:c});if(h!==0)return i?-h:h;if(!a){let p=f.localeCompare(S);return i?-p:p}return 0}for(let m of r){let h=v(g,m,e),p=v(b,m,e);m.ignoreLeading&&(h=h.trimStart(),p=p.trimStart());let B={numeric:m.numeric??l,ignoreCase:m.ignoreCase??s,humanNumeric:m.humanNumeric??n,versionSort:m.versionSort??d,dictionaryOrder:m.dictionaryOrder??o,monthSort:m.monthSort??c},A=m.reverse??i,y=I(h,p,B);if(y!==0)return A?-y:y}if(!a){let m=f.localeCompare(S);return i?-m:m}return 0}}function E(u,r){if(r.keys.length===0){if(r.ignoreCase){let s=new Set;return u.filter(i=>{let n=i.toLowerCase();return s.has(n)?!1:(s.add(n),!0)})}return[...new Set(u)]}let e=r.keys[0],l=new Set;return u.filter(s=>{let i=v(s,e,r.fieldDelimiter);return(e.ignoreCase??r.ignoreCase)&&(i=i.toLowerCase()),l.has(i)?!1:(l.add(i),!0)})}function C(u){let r={startField:1},e="",l=u,s=l.match(/([bdfhMnrV]+)$/);s&&(e=s[1],l=l.slice(0,-e.length)),e.includes("n")&&(r.numeric=!0),e.includes("r")&&(r.reverse=!0),e.includes("f")&&(r.ignoreCase=!0),e.includes("b")&&(r.ignoreLeading=!0),e.includes("h")&&(r.humanNumeric=!0),e.includes("V")&&(r.versionSort=!0),e.includes("d")&&(r.dictionaryOrder=!0),e.includes("M")&&(r.monthSort=!0);let i=l.split(",");if(i.length===0||i[0]==="")return null;let n=i[0].split("."),d=parseInt(n[0],10);if(Number.isNaN(d)||d<1)return null;if(r.startField=d,n.length>1&&n[1]){let o=parseInt(n[1],10);!Number.isNaN(o)&&o>=1&&(r.startChar=o)}if(i.length>1&&i[1]){let o=i[1],c=o.match(/([bdfhMnrV]+)$/);if(c){let a=c[1];a.includes("n")&&(r.numeric=!0),a.includes("r")&&(r.reverse=!0),a.includes("f")&&(r.ignoreCase=!0),a.includes("b")&&(r.ignoreLeading=!0),a.includes("h")&&(r.humanNumeric=!0),a.includes("V")&&(r.versionSort=!0),a.includes("d")&&(r.dictionaryOrder=!0),a.includes("M")&&(r.monthSort=!0),o=o.slice(0,-a.length)}let t=o.split(".");if(t[0]){let a=parseInt(t[0],10);if(!Number.isNaN(a)&&a>=1&&(r.endField=a),t.length>1&&t[1]){let f=parseInt(t[1],10);!Number.isNaN(f)&&f>=1&&(r.endChar=f)}}}return r}var q={name:"sort",summary:"sort lines of text files",usage:"sort [OPTION]... [FILE]...",options:["-b, --ignore-leading-blanks ignore leading blanks","-d, --dictionary-order consider only blanks and alphanumeric characters","-f, --ignore-case fold lower case to upper case characters","-h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)","-M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC'","-n, --numeric-sort compare according to string numerical value","-r, --reverse reverse the result of comparisons","-V, --version-sort natural sort of (version) numbers within text","-c, --check check for sorted input; do not sort","-o, --output=FILE write result to FILE instead of stdout","-s, --stable stabilize sort by disabling last-resort comparison","-u, --unique output only unique lines","-k, --key=KEYDEF sort via a key; KEYDEF gives location and type","-t, --field-separator=SEP use SEP as field separator"," --help display this help and exit"],description:`KEYDEF is F[.C][OPTS][,F[.C][OPTS]]
|
|
3
|
+
F is a field number (1-indexed)
|
|
4
|
+
C is a character position within the field (1-indexed)
|
|
5
|
+
OPTS can be: b d f h M n r V (per-key modifiers)
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
-k1 sort by first field
|
|
9
|
+
-k2,2 sort by second field only
|
|
10
|
+
-k1.3 sort by first field starting at 3rd character
|
|
11
|
+
-k1,2n sort by fields 1-2 numerically
|
|
12
|
+
-k2 -k1 sort by field 2, then by field 1`},j={name:"sort",async execute(u,r){if(N(u))return F(q);let e={reverse:!1,numeric:!1,unique:!1,ignoreCase:!1,humanNumeric:!1,versionSort:!1,dictionaryOrder:!1,monthSort:!1,ignoreLeadingBlanks:!1,stable:!1,checkOnly:!1,outputFile:null,keys:[],fieldDelimiter:null},l=[];for(let c=0;c<u.length;c++){let t=u[c];if(t==="-r"||t==="--reverse")e.reverse=!0;else if(t==="-n"||t==="--numeric-sort")e.numeric=!0;else if(t==="-u"||t==="--unique")e.unique=!0;else if(t==="-f"||t==="--ignore-case")e.ignoreCase=!0;else if(t==="-h"||t==="--human-numeric-sort")e.humanNumeric=!0;else if(t==="-V"||t==="--version-sort")e.versionSort=!0;else if(t==="-d"||t==="--dictionary-order")e.dictionaryOrder=!0;else if(t==="-M"||t==="--month-sort")e.monthSort=!0;else if(t==="-b"||t==="--ignore-leading-blanks")e.ignoreLeadingBlanks=!0;else if(t==="-s"||t==="--stable")e.stable=!0;else if(t==="-c"||t==="--check")e.checkOnly=!0;else if(t==="-o"||t==="--output")e.outputFile=u[++c]||null;else if(t.startsWith("-o"))e.outputFile=t.slice(2)||null;else if(t.startsWith("--output="))e.outputFile=t.slice(9)||null;else if(t==="-t"||t==="--field-separator")e.fieldDelimiter=u[++c]||null;else if(t.startsWith("-t"))e.fieldDelimiter=t.slice(2)||null;else if(t.startsWith("--field-separator="))e.fieldDelimiter=t.slice(18)||null;else if(t==="-k"||t==="--key"){let a=u[++c];if(a){let f=C(a);f&&e.keys.push(f)}}else if(t.startsWith("-k")){let a=C(t.slice(2));a&&e.keys.push(a)}else if(t.startsWith("--key=")){let a=C(t.slice(6));a&&e.keys.push(a)}else{if(t.startsWith("--"))return k("sort",t);if(t.startsWith("-")&&!t.startsWith("--")){let a=!1;for(let f of t.slice(1))if(f==="r")e.reverse=!0;else if(f==="n")e.numeric=!0;else if(f==="u")e.unique=!0;else if(f==="f")e.ignoreCase=!0;else if(f==="h")e.humanNumeric=!0;else if(f==="V")e.versionSort=!0;else if(f==="d")e.dictionaryOrder=!0;else if(f==="M")e.monthSort=!0;else if(f==="b")e.ignoreLeadingBlanks=!0;else if(f==="s")e.stable=!0;else if(f==="c")e.checkOnly=!0;else{a=!0;break}if(a)return k("sort",t)}else l.push(t)}}let s=await O(r,l,{cmdName:"sort"});if(!s.ok)return s.error;let n=s.content.split(`
|
|
13
|
+
`);n.length>0&&n[n.length-1]===""&&n.pop();let d=M(e);if(e.checkOnly){let c=l.length>0?l[0]:"-";for(let t=1;t<n.length;t++)if(d(n[t-1],n[t])>0)return{stdout:"",stderr:`sort: ${c}:${t+1}: disorder: ${n[t]}
|
|
14
|
+
`,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}n.sort(d),e.unique&&(n=E(n,e));let o=n.length>0?`${n.join(`
|
|
15
|
+
`)}
|
|
16
|
+
`:"";if(e.outputFile){let c=r.fs.resolvePath(r.cwd,e.outputFile);return await r.fs.writeFile(c,o),{stdout:"",stderr:"",exitCode:0}}return{stdout:o,stderr:"",exitCode:0}}};export{j as sortCommand};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-OBH7XN5N.js";import{a as w}from"./chunk-TA7RUHGQ.js";import{a as D,b as $}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var g={name:"tree",summary:"list contents of directories in a tree-like format",usage:"tree [OPTION]... [DIRECTORY]...",options:["-a include hidden files","-d list directories only","-L LEVEL limit depth of directory tree","-f print full path prefix for each file"," --help display this help and exit"]},T={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},E={name:"tree",async execute(i,o){if($(i))return D(g);let s=w("tree",i,T);if(!s.ok)return s.error;let f={showHidden:s.result.flags.showHidden,directoriesOnly:s.result.flags.directoriesOnly,maxDepth:s.result.flags.maxDepth??null,fullPath:s.result.flags.fullPath},d=s.result.positional;d.length===0&&d.push(".");let t="",l="",a=0,n=0;for(let e of d){let r=await b(o,e,f,"",0);t+=r.output,l+=r.stderr,a+=r.dirCount,n+=r.fileCount}return t+=`
|
|
3
|
+
${a} director${a===1?"y":"ies"}`,f.directoriesOnly||(t+=`, ${n} file${n===1?"":"s"}`),t+=`
|
|
4
|
+
`,{stdout:t,stderr:l,exitCode:l?1:0}}};async function b(i,o,s,f,d){let t={output:"",stderr:"",dirCount:0,fileCount:0},l=i.fs.resolvePath(i.cwd,o);try{if(!(await i.fs.stat(l)).isDirectory)return t.output=`${o}
|
|
5
|
+
`,t.fileCount=1,t}catch{return t.stderr=`tree: ${o}: No such file or directory
|
|
6
|
+
`,t}if(t.output=`${o}
|
|
7
|
+
`,s.maxDepth!==null&&d>=s.maxDepth)return t;try{let a=[];if(i.fs.readdirWithFileTypes)a=(await i.fs.readdirWithFileTypes(l)).map(r=>({name:r.name,isDirectory:r.isDirectory}));else{let e=await i.fs.readdir(l);for(let r=0;r<e.length;r+=100){let h=e.slice(r,r+100),u=await Promise.all(h.map(async c=>{let m=l==="/"?`/${c}`:`${l}/${c}`;try{let y=await i.fs.stat(m);return{name:c,isDirectory:y.isDirectory}}catch{return null}}));a.push(...u.filter(c=>c!==null))}}let n=a.filter(e=>!(!s.showHidden&&e.name.startsWith(".")||s.directoriesOnly&&!e.isDirectory));n.sort((e,r)=>e.name.localeCompare(r.name));for(let e=0;e<n.length;e++){let r=n[e],h=l==="/"?`/${r.name}`:`${l}/${r.name}`,u=e===n.length-1,c=u?"`-- ":"|-- ",m=f+(u?" ":"| ");if(r.isDirectory){t.dirCount++;let y=s.fullPath?h:r.name;if(t.output+=`${f+c+y}
|
|
8
|
+
`,s.maxDepth===null||d+1<s.maxDepth){let C=await P(i,h,s,m,d+1);t.output+=C.output,t.dirCount+=C.dirCount,t.fileCount+=C.fileCount}}else{t.fileCount++;let y=s.fullPath?h:r.name;t.output+=`${f+c+y}
|
|
9
|
+
`}}}catch{t.stderr=`tree: ${o}: Permission denied
|
|
10
|
+
`}return t}async function P(i,o,s,f,d){let t={output:"",stderr:"",dirCount:0,fileCount:0};if(s.maxDepth!==null&&d>=s.maxDepth)return t;try{let l=[];if(i.fs.readdirWithFileTypes)l=(await i.fs.readdirWithFileTypes(o)).map(e=>({name:e.name,isDirectory:e.isDirectory}));else{let n=await i.fs.readdir(o);for(let e=0;e<n.length;e+=100){let r=n.slice(e,e+100),h=await Promise.all(r.map(async u=>{let c=o==="/"?`/${u}`:`${o}/${u}`;try{let m=await i.fs.stat(c);return{name:u,isDirectory:m.isDirectory}}catch{return null}}));l.push(...h.filter(u=>u!==null))}}let a=l.filter(n=>!(!s.showHidden&&n.name.startsWith(".")||s.directoriesOnly&&!n.isDirectory));a.sort((n,e)=>n.name.localeCompare(e.name));for(let n=0;n<a.length;n++){let e=a[n],r=o==="/"?`/${e.name}`:`${o}/${e.name}`,h=n===a.length-1,u=h?"`-- ":"|-- ",c=f+(h?" ":"| ");if(e.isDirectory){t.dirCount++;let m=s.fullPath?r:e.name;t.output+=`${f+u+m}
|
|
11
|
+
`;let y=await P(i,r,s,c,d+1);t.output+=y.output,t.dirCount+=y.dirCount,t.fileCount+=y.fileCount}else{t.fileCount++;let m=s.fullPath?r:e.name;t.output+=`${f+u+m}
|
|
12
|
+
`}}}catch{}return t}export{E as treeCommand};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as g}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as f}from"./chunk-TA7RUHGQ.js";import{a as p,b as d}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var b={name:"uniq",summary:"report or omit repeated lines",usage:"uniq [OPTION]... [INPUT [OUTPUT]]",options:["-c, --count prefix lines by the number of occurrences","-d, --repeated only print duplicate lines","-i, --ignore-case ignore case when comparing","-u, --unique only print unique lines"," --help display this help and exit"]},w={count:{short:"c",long:"count",type:"boolean"},duplicatesOnly:{short:"d",long:"repeated",type:"boolean"},uniqueOnly:{short:"u",long:"unique",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},P={name:"uniq",async execute(a,m){if(d(a))return p(b);let o=f("uniq",a,w);if(!o.ok)return o.error;let{count:h,duplicatesOnly:y,uniqueOnly:q,ignoreCase:C}=o.result.flags,O=o.result.positional,u=await g(m,O,{cmdName:"uniq"});if(!u.ok)return u.error;let n=u.content.split(`
|
|
3
|
+
`);if(n.length>0&&n[n.length-1]===""&&n.pop(),n.length===0)return{stdout:"",stderr:"",exitCode:0};let t=[],r=n[0],i=1,x=(e,s)=>C?e.toLowerCase()===s.toLowerCase():e===s;for(let e=1;e<n.length;e++)x(n[e],r)?i++:(t.push({line:r,count:i}),r=n[e],i=1);t.push({line:r,count:i});let l=t;y?l=t.filter(e=>e.count>1):q&&(l=t.filter(e=>e.count===1));let c="";for(let{line:e,count:s}of l)h?c+=`${String(s).padStart(4)} ${e}
|
|
4
|
+
`:c+=`${e}
|
|
5
|
+
`;return{stdout:c,stderr:"",exitCode:0}}};export{P as uniqCommand};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as y}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as g}from"./chunk-TA7RUHGQ.js";import{a as w,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var C={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes print the byte counts","-m, --chars print the character counts","-l, --lines print the newline counts","-w, --words print the word counts"," --help display this help and exit"]},S={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},L={name:"wc",async execute(n,l){if(m(n))return w(C);let r=g("wc",n,S);if(!r.ok)return r.error;let{lines:s,words:t}=r.result.flags,e=r.result.flags.bytes||r.result.flags.chars,o=r.result.positional;!s&&!t&&!e&&(s=t=e=!0);let i=await y(l,o,{cmdName:"wc",stopOnError:!1});if(o.length===0){let f=b(i.files[0].content);return{stdout:`${h(f,s,t,e,"")}
|
|
3
|
+
`,stderr:"",exitCode:0}}let c="",u=0,d=0,p=0;for(let{filename:f,content:x}of i.files){let a=b(x);u+=a.lines,d+=a.words,p+=a.chars,c+=`${h(a,s,t,e,f)}
|
|
4
|
+
`}return o.length>1&&(c+=`${h({lines:u,words:d,chars:p},s,t,e,"total")}
|
|
5
|
+
`),{stdout:c,stderr:i.stderr,exitCode:i.exitCode}}};function b(n){let l=n.length,r=0,s=0,t=!1;for(let e=0;e<l;e++){let o=n[e];o===`
|
|
6
|
+
`?(r++,t&&(s++,t=!1)):o===" "||o===" "||o==="\r"?t&&(s++,t=!1):t=!0}return t&&s++,{lines:r,words:s,chars:l}}function h(n,l,r,s,t){let e=[];l&&e.push(String(n.lines)),r&&e.push(String(n.words)),s&&e.push(String(n.chars));let o=e.join(" ");return t&&(o+=` ${t}`),o}export{L as wcCommand};
|