just-bash 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-6QUZ7QML.js +3 -0
- package/dist/bin/chunks/chunk-PM2DS2YW.js +3 -0
- package/dist/bin/chunks/find-AMA6ABN5.js +11 -0
- package/dist/bin/chunks/find-JADNFF7V.js +11 -0
- package/dist/bin/chunks/find-NCI6KGUI.js +11 -0
- package/dist/bin/chunks/find-QEYP42JQ.js +11 -0
- package/dist/bin/chunks/printf-ASOYDPIK.js +14 -0
- package/dist/bin/chunks/printf-WM4X6IZ6.js +14 -0
- package/dist/bin/just-bash.js +1 -1
- package/dist/bin/shell/chunks/chunk-6QUZ7QML.js +3 -0
- package/dist/bin/shell/chunks/chunk-PM2DS2YW.js +3 -0
- package/dist/bin/shell/chunks/find-AMA6ABN5.js +11 -0
- package/dist/bin/shell/chunks/find-JADNFF7V.js +11 -0
- package/dist/bin/shell/chunks/find-NCI6KGUI.js +11 -0
- package/dist/bin/shell/chunks/find-QEYP42JQ.js +11 -0
- package/dist/bin/shell/chunks/printf-ASOYDPIK.js +14 -0
- package/dist/bin/shell/chunks/printf-WM4X6IZ6.js +14 -0
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/ai/index.js +286 -286
- package/dist/bundle/chunks/chunk-NWEGHOXL.js +2 -0
- package/dist/bundle/chunks/chunk-TDJNT32M.js +2 -0
- package/dist/bundle/chunks/find-3O5V74IR.js +10 -0
- package/dist/bundle/chunks/find-522XP4ZY.js +10 -0
- package/dist/bundle/chunks/find-5UN24ZV7.js +10 -0
- package/dist/bundle/chunks/find-JXG2HF6L.js +10 -0
- package/dist/bundle/chunks/printf-G2SBUNW3.js +13 -0
- package/dist/bundle/chunks/printf-O2UW73XK.js +13 -0
- package/dist/bundle/index.js +1 -1
- package/dist/commands/find/types.d.ts +5 -0
- package/dist/commands/printf/escapes.d.ts +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as N}from"./chunk-26Q3PZQ6.js";import{a as L,b as B,c as H}from"./chunk-6QUZ7QML.js";import{a as I,b as O}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(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=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function G(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 j(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",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,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",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("-")?(c="all",o=i.slice(1)):i.startsWith("/")&&(c="any",o=i.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,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 m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:r}:{expr:m.expr,pathIndex:t,actions:r}}function _(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 o=r();if(!o)return i;i={type:"or",left:i,right:o}}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 o=t();if(!o)return i;i={type:"and",left:i,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return i;i={type:"and",left:i,right:o}}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 m()}function m(){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 K={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"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],r=null,t=null,m=!1,a=!1;for(let p=0;p<e.length;p++){let l=e[p];if(l==="-maxdepth"&&p+1<e.length)a=!0,r=parseInt(e[++p],10);else if(l==="-mindepth"&&p+1<e.length)a=!0,t=parseInt(e[++p],10);else if(l==="-depth")a=!0,m=!0;else if(l==="-exec")for(a=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):U.has(l)?(a=!0,p++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(p=>p.type==="print"),b=o.length===0,y=[],Y=o.some(p=>p.type==="printf"),F=[],T="",D=0,V=G(i),k=new Map;for(let p of V){let l=s.fs.resolvePath(s.cwd,p);try{let g=await s.fs.stat(l);k.set(p,g.mtime?.getTime()??Date.now())}catch{}}for(let p of n){let l=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(l)}catch{T+=`find: ${p}: No such file or directory
|
|
5
|
+
`,D=1;continue}async function g(u,d){if(r!==null&&d>r)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===l?E=p.split("/").pop()||p:E=u.split("/").pop()||"";let $=u===l?p:p==="."?`./${u.slice(l.length+1)}`:p+u.slice(l.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,v=!1;if(x&&i!==null){let J={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},W=w(i,J);x=W.matches,h?v=W.printed:v=x}else x&&(v=!0);v&&(y.push($),Y&&F.push({path:$,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:p}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},z=!1;if(!m&&i!==null){let P={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};z=w(i,P).pruned}m?(await A(),C()):(C(),z||await A())}await g(l,0)}let S="";if(o.length>0)for(let p of o)switch(p.type){case"print":S+=y.length>0?`${y.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let l=[...y].sort((g,u)=>u.length-g.length);for(let g of l){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
|
|
8
|
+
`,D=1}}break}case"printf":for(let l of F)S+=q(p.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
9
|
+
`,exitCode:1};if(p.batchMode){let l=[];for(let d of p.command)d==="{}"?l.push(...y):l.push(d);let g=l.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let l of y){let u=p.command.map(f=>f==="{}"?l:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[m,a,i]=B(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:r+=`%${m!==0||a!==-1?`${m}.${a}`:""}${c}`,t++;continue}r+=L(o,m,a)}else r+=n[t],t++;return r}function Q(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 X(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()],m=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"),o=e.getFullYear();return`${r} ${t} ${m} ${a}:${i}:${c} ${o}`}function Z(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{oe as findCommand};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as k}from"./chunk-26Q3PZQ6.js";import{a as $,b as S}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";function g(e,s){switch(e.type){case"name":return{matches:k(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:k(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let t=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,t).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),n;return e.comparison==="more"?n=r>e.days:e.comparison==="less"?n=r<e.days:n=Math.floor(r)===e.days,{matches:n,pruned:!1,printed:!1}}case"newer":{let t=s.newerRefTimes.get(e.refPath);return t===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>t,pruned:!1,printed:!1}}case"size":{let t=e.value;switch(e.unit){case"c":t=e.value;break;case"k":t=e.value*1024;break;case"M":t=e.value*1024*1024;break;case"G":t=e.value*1024*1024*1024;break;case"b":t=e.value*512;break}let r;return e.comparison==="more"?r=s.size>t:e.comparison==="less"?r=s.size<t:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===t,{matches:r,pruned:!1,printed:!1}}case"perm":{let t=s.mode&511,r=e.mode&511,n;return e.matchType==="exact"?n=t===r:e.matchType==="all"?n=(t&r)===r:n=(t&r)!==0,{matches:n,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 t=g(e.expr,s);return{matches:!t.matches,pruned:t.pruned,printed:!1}}case"and":{let t=g(e.left,s);if(!t.matches)return{matches:!1,pruned:t.pruned,printed:!1};let r=g(e.right,s);return{matches:r.matches,pruned:t.pruned||r.pruned,printed:t.printed||r.printed}}case"or":{let t=g(e.left,s);if(t.matches)return t;let r=g(e.right,s);return{matches:r.matches,pruned:t.pruned||r.pruned,printed:r.printed}}}}function L(e){let s=[],t=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?t(r.expr):(r.type==="and"||r.type==="or")&&(t(r.left),t(r.right)))};return t(e),s}function O(e,s){let t=[],r=[],n=s;for(;n<e.length;){let l=e[n];if(l==="("||l==="\\("){t.push({type:"lparen"}),n++;continue}if(l===")"||l==="\\)"){t.push({type:"rparen"}),n++;continue}if(l==="-name"&&n+1<e.length)t.push({type:"expr",expr:{type:"name",pattern:e[++n]}});else if(l==="-iname"&&n+1<e.length)t.push({type:"expr",expr:{type:"name",pattern:e[++n],ignoreCase:!0}});else if(l==="-path"&&n+1<e.length)t.push({type:"expr",expr:{type:"path",pattern:e[++n]}});else if(l==="-ipath"&&n+1<e.length)t.push({type:"expr",expr:{type:"path",pattern:e[++n],ignoreCase:!0}});else if(l==="-regex"&&n+1<e.length)t.push({type:"expr",expr:{type:"regex",pattern:e[++n]}});else if(l==="-iregex"&&n+1<e.length)t.push({type:"expr",expr:{type:"regex",pattern:e[++n],ignoreCase:!0}});else if(l==="-type"&&n+1<e.length){let i=e[++n];if(i==="f"||i==="d")t.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:n,error:`find: Unknown argument to -type: ${i}
|
|
3
|
+
`,actions:[]}}else if(l==="-empty")t.push({type:"expr",expr:{type:"empty"}});else if(l==="-mtime"&&n+1<e.length){let i=e[++n],o="exact",f=i;i.startsWith("+")?(o="more",f=i.slice(1)):i.startsWith("-")&&(o="less",f=i.slice(1));let y=parseInt(f,10);Number.isNaN(y)||t.push({type:"expr",expr:{type:"mtime",days:y,comparison:o}})}else if(l==="-newer"&&n+1<e.length){let i=e[++n];t.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(l==="-size"&&n+1<e.length){let i=e[++n],o="exact",f=i;i.startsWith("+")?(o="more",f=i.slice(1)):i.startsWith("-")&&(o="less",f=i.slice(1));let y=f.match(/^(\d+)([ckMGb])?$/);if(y){let N=parseInt(y[1],10),d=y[2]||"b";t.push({type:"expr",expr:{type:"size",value:N,unit:d,comparison:o}})}}else if(l==="-perm"&&n+1<e.length){let i=e[++n],o="exact",f=i;i.startsWith("-")?(o="all",f=i.slice(1)):i.startsWith("/")&&(o="any",f=i.slice(1));let y=parseInt(f,8);Number.isNaN(y)||t.push({type:"expr",expr:{type:"perm",mode:y,matchType:o}})}else if(l==="-prune")t.push({type:"expr",expr:{type:"prune"}});else if(l==="-not"||l==="!")t.push({type:"not"});else if(l==="-o"||l==="-or")t.push({type:"op",op:"or"});else if(l==="-a"||l==="-and")t.push({type:"op",op:"and"});else if(l==="-maxdepth"||l==="-mindepth")n++;else if(l!=="-depth")if(l==="-exec"){let i=[];for(n++;n<e.length&&e[n]!==";"&&e[n]!=="+";)i.push(e[n]),n++;if(n>=e.length)return{expr:null,pathIndex:n,error:"find: missing argument to `-exec'\n",actions:[]};let o=e[n]==="+";r.push({type:"exec",command:i,batchMode:o})}else if(l==="-print")t.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(l==="-print0")r.push({type:"print0"});else if(l==="-delete")r.push({type:"delete"});else{if(l.startsWith("-"))return{expr:null,pathIndex:n,error:`find: unknown predicate '${l}'
|
|
4
|
+
`,actions:[]};if(t.length===0){n++;continue}break}n++}if(t.length===0)return{expr:null,pathIndex:n,actions:r};let w=j(t);return w.error?{expr:null,pathIndex:n,error:w.error,actions:r}:{expr:w.expr,pathIndex:n,actions:r}}function j(e){let s=0;function t(){let i=r();if(!i)return null;for(;s<e.length;){let o=e[s];if(o.type==="op"&&o.op==="or"){s++;let f=r();if(!f)return i;i={type:"or",left:i,right:f}}else break}return i}function r(){let i=n();if(!i)return null;for(;s<e.length;){let o=e[s];if(o.type==="op"&&o.op==="and"){s++;let f=n();if(!f)return i;i={type:"and",left:i,right:f}}else if(o.type==="expr"||o.type==="not"||o.type==="lparen"){let f=n();if(!f)return i;i={type:"and",left:i,right:f}}else break}return i}function n(){if(s<e.length&&e[s].type==="not"){s++;let i=n();return i?{type:"not",expr:i}:null}return w()}function w(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let o=t();return s<e.length&&e[s].type==="rparen"&&s++,o}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:t()}}var H={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","-delete delete found files/directories"," --help display this help and exit"]},V=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Q={name:"find",async execute(e,s){if(S(e))return $(H);let t=[],r=null,n=null,w=!1,l=!1;for(let p=0;p<e.length;p++){let a=e[p];if(a==="-maxdepth"&&p+1<e.length)l=!0,r=parseInt(e[++p],10);else if(a==="-mindepth"&&p+1<e.length)l=!0,n=parseInt(e[++p],10);else if(a==="-depth")l=!0,w=!0;else if(a==="-exec")for(l=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!a.startsWith("-")&&a!==";"&&a!=="+"&&a!=="("&&a!==")"&&a!=="\\("&&a!=="\\)"&&a!=="!"?l||t.push(a):V.has(a)?(l=!0,p++):(a.startsWith("-")||a==="("||a==="\\("||a==="!")&&(l=!0)}t.length===0&&t.push(".");let{expr:i,error:o,actions:f}=O(e,0);if(o)return{stdout:"",stderr:o,exitCode:1};let y=f.some(p=>p.type==="print"),N=f.length===0,d=[],b="",T=0,B=L(i),C=new Map;for(let p of B){let a=s.fs.resolvePath(s.cwd,p);try{let m=await s.fs.stat(a);C.set(p,m.mtime?.getTime()??Date.now())}catch{}}for(let p of t){let a=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(a)}catch{b+=`find: ${p}: No such file or directory
|
|
5
|
+
`,T=1;continue}async function m(u,h){if(r!==null&&h>r)return;let c;try{c=await s.fs.stat(u)}catch{return}if(!c)return;let v;u===a?v=p.split("/").pop()||p:v=u.split("/").pop()||"";let R=u===a?p:p==="."?`./${u.slice(a.length+1)}`:p+u.slice(a.length),D=null;c.isDirectory&&(D=await s.fs.readdir(u));let z=c.isFile?c.size===0:D!==null&&D.length===0,A=()=>{let x=n===null||h>=n,M=!1;if(x&&i!==null){let G={name:v,relativePath:R,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:z,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C},W=g(i,G);x=W.matches,y?M=W.printed:M=x}else x&&(M=!0);M&&d.push(R)},F=async()=>{if(D!==null)for(let P of D){let x=u==="/"?`/${P}`:`${u}/${P}`;await m(x,h+1)}},I=!1;if(!w&&i!==null){let P={name:v,relativePath:R,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:z,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C};I=g(i,P).pruned}w?(await F(),A()):(A(),I||await F())}await m(a,0)}let E="";if(f.length>0)for(let p of f)switch(p.type){case"print":E+=d.length>0?`${d.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"";break;case"print0":E+=d.length>0?`${d.join("\0")}\0`:"";break;case"delete":{let a=[...d].sort((m,u)=>u.length-m.length);for(let m of a){let u=s.fs.resolvePath(s.cwd,m);try{await s.fs.rm(u,{recursive:!1})}catch(h){let c=h instanceof Error?h.message:String(h);b+=`find: cannot delete '${m}': ${c}
|
|
8
|
+
`,T=1}}break}case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
9
|
+
`,exitCode:1};if(p.batchMode){let a=[];for(let h of p.command)h==="{}"?a.push(...d):a.push(h);let m=a.map(h=>`"${h}"`).join(" "),u=await s.exec(m,{cwd:s.cwd});E+=u.stdout,b+=u.stderr,u.exitCode!==0&&(T=u.exitCode)}else for(let a of d){let u=p.command.map(c=>c==="{}"?a:c).map(c=>`"${c}"`).join(" "),h=await s.exec(u,{cwd:s.cwd});E+=h.stdout,b+=h.stderr,h.exitCode!==0&&(T=h.exitCode)}break}else N&&(E=d.length>0?`${d.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:"");return{stdout:E,stderr:b,exitCode:T}}};export{Q as findCommand};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as C,c as F}from"./chunk-6QUZ7QML.js";import{a as $}from"./chunk-4VDEBYW7.js";import{a as E,b as I}from"./chunk-GTNBSMZR.js";import{a as M,b as j}from"./chunk-5KNEBKYN.js";var A=M(S=>{(function(){"use strict";var e={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function o(l){return n(i(l),arguments)}function t(l,a){return o.apply(null,[l].concat(a||[]))}function n(l,a){var f=1,p=l.length,s,h="",d,u,c,m,v,w,y,b;for(d=0;d<p;d++)if(typeof l[d]=="string")h+=l[d];else if(typeof l[d]=="object"){if(c=l[d],c.keys)for(s=a[f],u=0;u<c.keys.length;u++){if(s==null)throw new Error(o('[sprintf] Cannot access property "%s" of undefined value "%s"',c.keys[u],c.keys[u-1]));s=s[c.keys[u]]}else c.param_no?s=a[c.param_no]:s=a[f++];if(e.not_type.test(c.type)&&e.not_primitive.test(c.type)&&s instanceof Function&&(s=s()),e.numeric_arg.test(c.type)&&typeof s!="number"&&isNaN(s))throw new TypeError(o("[sprintf] expecting number but found %T",s));switch(e.number.test(c.type)&&(y=s>=0),c.type){case"b":s=parseInt(s,10).toString(2);break;case"c":s=String.fromCharCode(parseInt(s,10));break;case"d":case"i":s=parseInt(s,10);break;case"j":s=JSON.stringify(s,null,c.width?parseInt(c.width):0);break;case"e":s=c.precision?parseFloat(s).toExponential(c.precision):parseFloat(s).toExponential();break;case"f":s=c.precision?parseFloat(s).toFixed(c.precision):parseFloat(s);break;case"g":s=c.precision?String(Number(s.toPrecision(c.precision))):parseFloat(s);break;case"o":s=(parseInt(s,10)>>>0).toString(8);break;case"s":s=String(s),s=c.precision?s.substring(0,c.precision):s;break;case"t":s=String(!!s),s=c.precision?s.substring(0,c.precision):s;break;case"T":s=Object.prototype.toString.call(s).slice(8,-1).toLowerCase(),s=c.precision?s.substring(0,c.precision):s;break;case"u":s=parseInt(s,10)>>>0;break;case"v":s=s.valueOf(),s=c.precision?s.substring(0,c.precision):s;break;case"x":s=(parseInt(s,10)>>>0).toString(16);break;case"X":s=(parseInt(s,10)>>>0).toString(16).toUpperCase();break}e.json.test(c.type)?h+=s:(e.number.test(c.type)&&(!y||c.sign)?(b=y?"+":"-",s=s.toString().replace(e.sign,"")):b="",v=c.pad_char?c.pad_char==="0"?"0":c.pad_char.charAt(1):" ",w=c.width-(b+s).length,m=c.width&&w>0?v.repeat(w):"",h+=c.align?b+s+m:v==="0"?b+m+s:m+b+s)}return h}var r=Object.create(null);function i(l){if(r[l])return r[l];for(var a=l,f,p=[],s=0;a;){if((f=e.text.exec(a))!==null)p.push(f[0]);else if((f=e.modulo.exec(a))!==null)p.push("%");else if((f=e.placeholder.exec(a))!==null){if(f[2]){s|=1;var h=[],d=f[2],u=[];if((u=e.key.exec(d))!==null)for(h.push(u[1]);(d=d.substring(u[0].length))!=="";)if((u=e.key_access.exec(d))!==null)h.push(u[1]);else if((u=e.index_access.exec(d))!==null)h.push(u[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");f[2]=h}else s|=2;if(s===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");p.push({placeholder:f[0],param_no:f[1],keys:f[2],sign:f[3],pad_char:f[4],align:f[5],width:f[6],precision:f[7],type:f[8]})}else throw new SyntaxError("[sprintf] unexpected placeholder");a=a.substring(f[0].length)}return r[l]=p}typeof S<"u"&&(S.sprintf=o,S.vsprintf=t),typeof window<"u"&&(window.sprintf=o,window.vsprintf=t,typeof define=="function"&&define.amd&&define(function(){return{sprintf:o,vsprintf:t}}))})()});var x=j(A(),1);var N={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},J={name:"printf",async execute(e,o){if(I(e))return E(N);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
3
|
+
`,exitCode:2};let t=null,n=0;for(;n<e.length;){let l=e[n];if(l==="--"){n++;break}if(l==="-v"){if(n+1>=e.length)return{stdout:"",stderr:`printf: -v: option requires an argument
|
|
4
|
+
`,exitCode:1};if(t=e[n+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[^\]]+\])?$/.test(t))return{stdout:"",stderr:`printf: \`${t}': not a valid identifier
|
|
5
|
+
`,exitCode:2};n+=2}else{if(l.startsWith("-")&&l!=="-")break;break}}if(n>=e.length)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
6
|
+
`,exitCode:1};let r=e[n],i=e.slice(n+1);try{let l=F(r),a="",f=0,p=!1,s="";do{let{result:h,argsConsumed:d,error:u,errMsg:c,stopped:m}=W(l,i,f);if(a+=h,f+=d,u&&(p=!0,c&&(s=c)),m)break}while(f<i.length&&f>0);return f===0&&i.length>0,t?(o.env[t]=a,{stdout:"",stderr:s,exitCode:p?1:0}):{stdout:a,stderr:s,exitCode:p?1:0}}catch(l){return{stdout:"",stderr:`printf: ${$(l)}
|
|
7
|
+
`,exitCode:1}}}};function W(e,o,t){let n="",r=0,i=0,l=!1,a="";for(;r<e.length;)if(e[r]==="%"&&r+1<e.length){let f=r;if(r++,e[r]==="%"){n+="%",r++;continue}for(;r<e.length&&"+-0 #'".includes(e[r]);)r++;let p=!1;if(e[r]==="*")p=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;let s=!1;if(e[r]===".")if(r++,e[r]==="*")s=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;r<e.length&&"hlL".includes(e[r])&&r++;let h=e[r]||"";r++;let u=e.slice(f,r);if(p){let b=parseInt(o[t+i]||"0",10);i++,u=u.replace("*",String(b))}if(s){let b=parseInt(o[t+i]||"0",10);i++,u=u.replace(".*",`.${b}`)}let c=o[t+i]||"";i++;let{value:m,parseError:v,parseErrMsg:w,stopped:y}=z(u,h,c);if(n+=m,v&&(l=!0,w&&(a=w)),y)return{result:n,argsConsumed:i,error:l,errMsg:a,stopped:!0}}else n+=e[r],r++;return{result:n,argsConsumed:i,error:l,errMsg:a,stopped:!1}}function z(e,o,t){let n=!1,r="";switch(o){case"d":case"i":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
8
|
+
`),{value:_(e,i),parseError:n,parseErrMsg:r}}case"o":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
9
|
+
`),{value:T(e,i),parseError:n,parseErrMsg:r}}case"u":{let i=k(t);n=g,n&&(r=`printf: ${t}: invalid number
|
|
10
|
+
`);let l=i<0?i>>>0:i;return{value:_(e.replace("u","d"),l),parseError:n,parseErrMsg:r}}case"x":case"X":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
11
|
+
`),{value:O(e,i),parseError:n,parseErrMsg:r}}case"e":case"E":case"f":case"F":case"g":case"G":{let i=parseFloat(t)||0;return{value:P(e,o,i),parseError:!1,parseErrMsg:""}}case"c":return{value:t.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:U(e,t),parseError:!1,parseErrMsg:""};case"q":return{value:q(e,t),parseError:!1,parseErrMsg:""};case"b":{let i=R(t);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:(0,x.sprintf)(e,t),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
|
|
12
|
+
`}}}}var g=!1;function k(e){g=!1;let o=e.trimStart(),t=o!==o.trimEnd();if(e=o.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let n=parseInt(e,16);return Number.isNaN(n)?(g=!0,0):(t&&(g=!0),n)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return t&&(g=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){g=!0;let n=e.match(/^(\d+)#/);return n?parseInt(n[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){g=!0;let n=parseInt(e,10);return Number.isNaN(n)?0:n}return t&&(g=!0),parseInt(e,10)||0}function _(e,o){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!t)return(0,x.sprintf)(e.replace(/\.\d*/,""),o);let n=t[1]||"",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=o<0,a=Math.abs(o),f=String(a);i>=0&&(f=f.padStart(i,"0"));let p="";l?p="-":n.includes("+")?p="+":n.includes(" ")&&(p=" ");let s=p+f;return r>s.length&&(n.includes("-")?s=s.padEnd(r," "):n.includes("0")&&i<0?s=p+f.padStart(r-p.length,"0"):s=s.padStart(r," ")),s}function T(e,o){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!t)return(0,x.sprintf)(e,o);let n=t[1]||"",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=Math.abs(o).toString(8);i>=0&&(l=l.padStart(i,"0")),n.includes("#")&&!l.startsWith("0")&&(l=`0${l}`);let a=l;return r>a.length&&(n.includes("-")?a=a.padEnd(r," "):n.includes("0")&&i<0?a=a.padStart(r,"0"):a=a.padStart(r," ")),a}function O(e,o){let t=e.includes("X"),n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!n)return(0,x.sprintf)(e,o);let r=n[1]||"",i=n[2]?parseInt(n[2],10):0,l=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,a=Math.abs(o).toString(16);t&&(a=a.toUpperCase()),l>=0&&(a=a.padStart(l,"0"));let f="";r.includes("#")&&o!==0&&(f=t?"0X":"0x");let p=f+a;return i>p.length&&(r.includes("-")?p=p.padEnd(i," "):r.includes("0")&&l<0?p=f+a.padStart(i-f.length,"0"):p=p.padStart(i," ")),p}function X(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f]/.test(e)){let n="$'";for(let r of e){let i=r.charCodeAt(0);r==="'"?n+="\\'":r==="\\"?n+="\\\\":r===`
|
|
13
|
+
`?n+="\\n":r===" "?n+="\\t":r==="\r"?n+="\\r":r==="\x07"?n+="\\a":r==="\b"?n+="\\b":r==="\f"?n+="\\f":r==="\v"?n+="\\v":r==="\x1B"?n+="\\E":i<32||i>126?n+=`\\x${i.toString(16).padStart(2,"0")}`:r==='"'?n+='\\"':n+=r}return n+="'",n}let t="";for(let n of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(n)?t+=`\\${n}`:t+=n;return t}function U(e,o){let t=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!t)return(0,x.sprintf)(e.replace(/0+(?=\d)/,""),o);let n=t[1]==="-",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=n?-r:r;return C(o,l,i)}function q(e,o){let t=X(o),n=e.match(/^%(-?)(\d*)q$/);if(!n)return t;let r=n[1]==="-",i=n[2]?parseInt(n[2],10):0,l=t;return i>l.length&&(r?l=l.padEnd(i," "):l=l.padStart(i," ")),l}function P(e,o,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!n)return(0,x.sprintf)(e,t);let r=n[1]||"",i=n[2]?parseInt(n[2],10):0,l=n[3]!==void 0?n[4]?parseInt(n[4],10):0:6,a,f=o.toLowerCase();if(f==="e"?(a=t.toExponential(l),a=a.replace(/e([+-])(\d)$/,"e$10$2"),o==="E"&&(a=a.toUpperCase())):f==="f"?(a=t.toFixed(l),r.includes("#")&&l===0&&!a.includes(".")&&(a+=".")):f==="g"?(a=t.toPrecision(l||1),r.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),o==="G"&&(a=a.toUpperCase())):a=t.toString(),t>=0&&(r.includes("+")?a=`+${a}`:r.includes(" ")&&(a=` ${a}`)),i>a.length)if(r.includes("-"))a=a.padEnd(i," ");else if(r.includes("0")){let p=a.match(/^[+ -]/)?.[0]||"",s=p?a.slice(1):a;a=p+s.padStart(i-p.length,"0")}else a=a.padStart(i," ");return a}function R(e){let o="",t=0;for(;t<e.length;)if(e[t]==="\\"&&t+1<e.length)switch(e[t+1]){case"n":o+=`
|
|
14
|
+
`,t+=2;break;case"t":o+=" ",t+=2;break;case"r":o+="\r",t+=2;break;case"\\":o+="\\",t+=2;break;case"a":o+="\x07",t+=2;break;case"b":o+="\b",t+=2;break;case"f":o+="\f",t+=2;break;case"v":o+="\v",t+=2;break;case"c":return{value:o,stopped:!0};case"x":{let r="",i=t+2;for(;i<e.length&&i<t+4&&/[0-9a-fA-F]/.test(e[i]);)r+=e[i],i++;r?(o+=String.fromCharCode(parseInt(r,16)),t=i):(o+="\\x",t+=2);break}case"u":{let r="",i=t+2;for(;i<e.length&&i<t+6&&/[0-9a-fA-F]/.test(e[i]);)r+=e[i],i++;r?(o+=String.fromCodePoint(parseInt(r,16)),t=i):(o+="\\u",t+=2);break}case"0":{let r="",i=t+2;for(;i<e.length&&i<t+5&&/[0-7]/.test(e[i]);)r+=e[i],i++;r?o+=String.fromCharCode(parseInt(r,8)):o+="\0",t=i;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let r="",i=t+1;for(;i<e.length&&i<t+4&&/[0-7]/.test(e[i]);)r+=e[i],i++;o+=String.fromCharCode(parseInt(r,8)),t=i;break}default:o+=e[t],t++}else o+=e[t],t++;return{value:o,stopped:!1}}export{J as printfCommand};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as C,c as F}from"./chunk-PM2DS2YW.js";import{a as $}from"./chunk-4VDEBYW7.js";import{a as E,b as I}from"./chunk-GTNBSMZR.js";import{a as M,b as j}from"./chunk-5KNEBKYN.js";var A=M(S=>{(function(){"use strict";var e={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function o(l){return n(i(l),arguments)}function t(l,a){return o.apply(null,[l].concat(a||[]))}function n(l,a){var f=1,p=l.length,s,h="",d,u,c,m,v,w,y,b;for(d=0;d<p;d++)if(typeof l[d]=="string")h+=l[d];else if(typeof l[d]=="object"){if(c=l[d],c.keys)for(s=a[f],u=0;u<c.keys.length;u++){if(s==null)throw new Error(o('[sprintf] Cannot access property "%s" of undefined value "%s"',c.keys[u],c.keys[u-1]));s=s[c.keys[u]]}else c.param_no?s=a[c.param_no]:s=a[f++];if(e.not_type.test(c.type)&&e.not_primitive.test(c.type)&&s instanceof Function&&(s=s()),e.numeric_arg.test(c.type)&&typeof s!="number"&&isNaN(s))throw new TypeError(o("[sprintf] expecting number but found %T",s));switch(e.number.test(c.type)&&(y=s>=0),c.type){case"b":s=parseInt(s,10).toString(2);break;case"c":s=String.fromCharCode(parseInt(s,10));break;case"d":case"i":s=parseInt(s,10);break;case"j":s=JSON.stringify(s,null,c.width?parseInt(c.width):0);break;case"e":s=c.precision?parseFloat(s).toExponential(c.precision):parseFloat(s).toExponential();break;case"f":s=c.precision?parseFloat(s).toFixed(c.precision):parseFloat(s);break;case"g":s=c.precision?String(Number(s.toPrecision(c.precision))):parseFloat(s);break;case"o":s=(parseInt(s,10)>>>0).toString(8);break;case"s":s=String(s),s=c.precision?s.substring(0,c.precision):s;break;case"t":s=String(!!s),s=c.precision?s.substring(0,c.precision):s;break;case"T":s=Object.prototype.toString.call(s).slice(8,-1).toLowerCase(),s=c.precision?s.substring(0,c.precision):s;break;case"u":s=parseInt(s,10)>>>0;break;case"v":s=s.valueOf(),s=c.precision?s.substring(0,c.precision):s;break;case"x":s=(parseInt(s,10)>>>0).toString(16);break;case"X":s=(parseInt(s,10)>>>0).toString(16).toUpperCase();break}e.json.test(c.type)?h+=s:(e.number.test(c.type)&&(!y||c.sign)?(b=y?"+":"-",s=s.toString().replace(e.sign,"")):b="",v=c.pad_char?c.pad_char==="0"?"0":c.pad_char.charAt(1):" ",w=c.width-(b+s).length,m=c.width&&w>0?v.repeat(w):"",h+=c.align?b+s+m:v==="0"?b+m+s:m+b+s)}return h}var r=Object.create(null);function i(l){if(r[l])return r[l];for(var a=l,f,p=[],s=0;a;){if((f=e.text.exec(a))!==null)p.push(f[0]);else if((f=e.modulo.exec(a))!==null)p.push("%");else if((f=e.placeholder.exec(a))!==null){if(f[2]){s|=1;var h=[],d=f[2],u=[];if((u=e.key.exec(d))!==null)for(h.push(u[1]);(d=d.substring(u[0].length))!=="";)if((u=e.key_access.exec(d))!==null)h.push(u[1]);else if((u=e.index_access.exec(d))!==null)h.push(u[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");f[2]=h}else s|=2;if(s===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");p.push({placeholder:f[0],param_no:f[1],keys:f[2],sign:f[3],pad_char:f[4],align:f[5],width:f[6],precision:f[7],type:f[8]})}else throw new SyntaxError("[sprintf] unexpected placeholder");a=a.substring(f[0].length)}return r[l]=p}typeof S<"u"&&(S.sprintf=o,S.vsprintf=t),typeof window<"u"&&(window.sprintf=o,window.vsprintf=t,typeof define=="function"&&define.amd&&define(function(){return{sprintf:o,vsprintf:t}}))})()});var x=j(A(),1);var N={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},J={name:"printf",async execute(e,o){if(I(e))return E(N);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
3
|
+
`,exitCode:2};let t=null,n=0;for(;n<e.length;){let l=e[n];if(l==="--"){n++;break}if(l==="-v"){if(n+1>=e.length)return{stdout:"",stderr:`printf: -v: option requires an argument
|
|
4
|
+
`,exitCode:1};if(t=e[n+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[^\]]+\])?$/.test(t))return{stdout:"",stderr:`printf: \`${t}': not a valid identifier
|
|
5
|
+
`,exitCode:2};n+=2}else{if(l.startsWith("-")&&l!=="-")break;break}}if(n>=e.length)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
6
|
+
`,exitCode:1};let r=e[n],i=e.slice(n+1);try{let l=F(r),a="",f=0,p=!1,s="";do{let{result:h,argsConsumed:d,error:u,errMsg:c,stopped:m}=W(l,i,f);if(a+=h,f+=d,u&&(p=!0,c&&(s=c)),m)break}while(f<i.length&&f>0);return f===0&&i.length>0,t?(o.env[t]=a,{stdout:"",stderr:s,exitCode:p?1:0}):{stdout:a,stderr:s,exitCode:p?1:0}}catch(l){return{stdout:"",stderr:`printf: ${$(l)}
|
|
7
|
+
`,exitCode:1}}}};function W(e,o,t){let n="",r=0,i=0,l=!1,a="";for(;r<e.length;)if(e[r]==="%"&&r+1<e.length){let f=r;if(r++,e[r]==="%"){n+="%",r++;continue}for(;r<e.length&&"+-0 #'".includes(e[r]);)r++;let p=!1;if(e[r]==="*")p=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;let s=!1;if(e[r]===".")if(r++,e[r]==="*")s=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;r<e.length&&"hlL".includes(e[r])&&r++;let h=e[r]||"";r++;let u=e.slice(f,r);if(p){let b=parseInt(o[t+i]||"0",10);i++,u=u.replace("*",String(b))}if(s){let b=parseInt(o[t+i]||"0",10);i++,u=u.replace(".*",`.${b}`)}let c=o[t+i]||"";i++;let{value:m,parseError:v,parseErrMsg:w,stopped:y}=z(u,h,c);if(n+=m,v&&(l=!0,w&&(a=w)),y)return{result:n,argsConsumed:i,error:l,errMsg:a,stopped:!0}}else n+=e[r],r++;return{result:n,argsConsumed:i,error:l,errMsg:a,stopped:!1}}function z(e,o,t){let n=!1,r="";switch(o){case"d":case"i":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
8
|
+
`),{value:_(e,i),parseError:n,parseErrMsg:r}}case"o":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
9
|
+
`),{value:T(e,i),parseError:n,parseErrMsg:r}}case"u":{let i=k(t);n=g,n&&(r=`printf: ${t}: invalid number
|
|
10
|
+
`);let l=i<0?i>>>0:i;return{value:_(e.replace("u","d"),l),parseError:n,parseErrMsg:r}}case"x":case"X":{let i=k(t);return n=g,n&&(r=`printf: ${t}: invalid number
|
|
11
|
+
`),{value:O(e,i),parseError:n,parseErrMsg:r}}case"e":case"E":case"f":case"F":case"g":case"G":{let i=parseFloat(t)||0;return{value:P(e,o,i),parseError:!1,parseErrMsg:""}}case"c":return{value:t.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:U(e,t),parseError:!1,parseErrMsg:""};case"q":return{value:q(e,t),parseError:!1,parseErrMsg:""};case"b":{let i=R(t);return{value:i.value,parseError:!1,parseErrMsg:"",stopped:i.stopped}}default:try{return{value:(0,x.sprintf)(e,t),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
|
|
12
|
+
`}}}}var g=!1;function k(e){g=!1;let o=e.trimStart(),t=o!==o.trimEnd();if(e=o.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let n=parseInt(e,16);return Number.isNaN(n)?(g=!0,0):(t&&(g=!0),n)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return t&&(g=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){g=!0;let n=e.match(/^(\d+)#/);return n?parseInt(n[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){g=!0;let n=parseInt(e,10);return Number.isNaN(n)?0:n}return t&&(g=!0),parseInt(e,10)||0}function _(e,o){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!t)return(0,x.sprintf)(e.replace(/\.\d*/,""),o);let n=t[1]||"",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=o<0,a=Math.abs(o),f=String(a);i>=0&&(f=f.padStart(i,"0"));let p="";l?p="-":n.includes("+")?p="+":n.includes(" ")&&(p=" ");let s=p+f;return r>s.length&&(n.includes("-")?s=s.padEnd(r," "):n.includes("0")&&i<0?s=p+f.padStart(r-p.length,"0"):s=s.padStart(r," ")),s}function T(e,o){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!t)return(0,x.sprintf)(e,o);let n=t[1]||"",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=Math.abs(o).toString(8);i>=0&&(l=l.padStart(i,"0")),n.includes("#")&&!l.startsWith("0")&&(l=`0${l}`);let a=l;return r>a.length&&(n.includes("-")?a=a.padEnd(r," "):n.includes("0")&&i<0?a=a.padStart(r,"0"):a=a.padStart(r," ")),a}function O(e,o){let t=e.includes("X"),n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!n)return(0,x.sprintf)(e,o);let r=n[1]||"",i=n[2]?parseInt(n[2],10):0,l=n[3]!==void 0?n[4]?parseInt(n[4],10):0:-1,a=Math.abs(o).toString(16);t&&(a=a.toUpperCase()),l>=0&&(a=a.padStart(l,"0"));let f="";r.includes("#")&&o!==0&&(f=t?"0X":"0x");let p=f+a;return i>p.length&&(r.includes("-")?p=p.padEnd(i," "):r.includes("0")&&l<0?p=f+a.padStart(i-f.length,"0"):p=p.padStart(i," ")),p}function X(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f]/.test(e)){let n="$'";for(let r of e){let i=r.charCodeAt(0);r==="'"?n+="\\'":r==="\\"?n+="\\\\":r===`
|
|
13
|
+
`?n+="\\n":r===" "?n+="\\t":r==="\r"?n+="\\r":r==="\x07"?n+="\\a":r==="\b"?n+="\\b":r==="\f"?n+="\\f":r==="\v"?n+="\\v":r==="\x1B"?n+="\\E":i<32||i>126?n+=`\\x${i.toString(16).padStart(2,"0")}`:r==='"'?n+='\\"':n+=r}return n+="'",n}let t="";for(let n of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(n)?t+=`\\${n}`:t+=n;return t}function U(e,o){let t=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!t)return(0,x.sprintf)(e.replace(/0+(?=\d)/,""),o);let n=t[1]==="-",r=t[2]?parseInt(t[2],10):0,i=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,l=n?-r:r;return C(o,l,i)}function q(e,o){let t=X(o),n=e.match(/^%(-?)(\d*)q$/);if(!n)return t;let r=n[1]==="-",i=n[2]?parseInt(n[2],10):0,l=t;return i>l.length&&(r?l=l.padEnd(i," "):l=l.padStart(i," ")),l}function P(e,o,t){let n=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!n)return(0,x.sprintf)(e,t);let r=n[1]||"",i=n[2]?parseInt(n[2],10):0,l=n[3]!==void 0?n[4]?parseInt(n[4],10):0:6,a,f=o.toLowerCase();if(f==="e"?(a=t.toExponential(l),a=a.replace(/e([+-])(\d)$/,"e$10$2"),o==="E"&&(a=a.toUpperCase())):f==="f"?(a=t.toFixed(l),r.includes("#")&&l===0&&!a.includes(".")&&(a+=".")):f==="g"?(a=t.toPrecision(l||1),r.includes("#")||(a=a.replace(/\.?0+$/,""),a=a.replace(/\.?0+e/,"e")),a=a.replace(/e([+-])(\d)$/,"e$10$2"),o==="G"&&(a=a.toUpperCase())):a=t.toString(),t>=0&&(r.includes("+")?a=`+${a}`:r.includes(" ")&&(a=` ${a}`)),i>a.length)if(r.includes("-"))a=a.padEnd(i," ");else if(r.includes("0")){let p=a.match(/^[+ -]/)?.[0]||"",s=p?a.slice(1):a;a=p+s.padStart(i-p.length,"0")}else a=a.padStart(i," ");return a}function R(e){let o="",t=0;for(;t<e.length;)if(e[t]==="\\"&&t+1<e.length)switch(e[t+1]){case"n":o+=`
|
|
14
|
+
`,t+=2;break;case"t":o+=" ",t+=2;break;case"r":o+="\r",t+=2;break;case"\\":o+="\\",t+=2;break;case"a":o+="\x07",t+=2;break;case"b":o+="\b",t+=2;break;case"f":o+="\f",t+=2;break;case"v":o+="\v",t+=2;break;case"c":return{value:o,stopped:!0};case"x":{let r="",i=t+2;for(;i<e.length&&i<t+4&&/[0-9a-fA-F]/.test(e[i]);)r+=e[i],i++;r?(o+=String.fromCharCode(parseInt(r,16)),t=i):(o+="\\x",t+=2);break}case"u":{let r="",i=t+2;for(;i<e.length&&i<t+6&&/[0-9a-fA-F]/.test(e[i]);)r+=e[i],i++;r?(o+=String.fromCodePoint(parseInt(r,16)),t=i):(o+="\\u",t+=2);break}case"0":{let r="",i=t+2;for(;i<e.length&&i<t+5&&/[0-7]/.test(e[i]);)r+=e[i],i++;r?o+=String.fromCharCode(parseInt(r,8)):o+="\0",t=i;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let r="",i=t+1;for(;i<e.length&&i<t+4&&/[0-7]/.test(e[i]);)r+=e[i],i++;o+=String.fromCharCode(parseInt(r,8)),t=i;break}default:o+=e[t],t++}else o+=e[t],t++;return{value:o,stopped:!1}}export{J as printfCommand};
|
package/dist/bin/shell/shell.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as U,b as K,c as H,d as ee,e as Y,f as k,g as F,h as me,i as z,j as oe,k as Fe}from"./chunks/chunk-NWWB2XRE.js";import{a as X}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-5KNEBKYN.js";import*as On from"node:fs";import*as _n from"node:readline";var ur=[{name:"echo",load:async()=>(await import("./chunks/echo-DEUIS5JO.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-YZXBF5YF.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-BOFQVMMK.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-C4MPAF3H.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-LWULWDHP.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-XCIAYF5I.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-W6CCBEMG.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-77UY7PGN.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-TDYCNSIQ.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-DB7J2W5X.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-3G4LK462.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-X4MWD4JP.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-DPNOQY67.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-VGXR3WWL.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YSVKBQ77.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-CNJ3QDRA.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-3PHITCPO.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-LTCVBSRV.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-4DKPX43H.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-UJP353TM.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-W4HF6YSB.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-UYV3FM7R.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-R36J3G4K.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2EEKHHO6.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-UU2VS3OM.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-HW2TUO6B.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-Y7JDBYHN.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VLHP44TU.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-4247W67O.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4FZ7WF2P.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-AKGX6HSG.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-AKGX6HSG.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-74DFXE2E.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-74DFXE2E.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-PRQ4B6N2.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-DKUAYNEK.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-JCX733LK.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-JCX733LK.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-GTCFHSB2.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-5IWSVGHN.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-5IWSVGHN.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-EYSXBSCP.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-NC7HTKLZ.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-TG2NXCX2.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-7NBRXV2Z.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-E4DIYGTT.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RP2AJGMV.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-DGJILX2Q.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-HA2ZNL6S.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-L4UWMK4S.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-YQGNAT2T.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-HX2NMOP3.js")).whichCommand}],Ln=[{name:"curl",load:async()=>(await import("./chunks/curl-NE7XEWMN.js")).curlCommand}],hr=new Map;function dr(t){return{name:t.name,async execute(e,n){let r=hr.get(t.name);return r||(r=await t.load(),hr.set(t.name,r)),r.execute(e,n)}}}function mr(t){return(t?ur.filter(n=>t.includes(n.name)):ur).map(dr)}function pr(){return Ln.map(dr)}function yr(t){return"load"in t&&typeof t.load=="function"}function Er(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var Tn=new TextEncoder,Wn=new TextDecoder;function Ae(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),n=>n.charCodeAt(0));case"hex":{let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}case"binary":case"latin1":return Uint8Array.from(t,n=>n.charCodeAt(0));default:return Tn.encode(t)}}function Me(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Wn.decode(t)}}function ae(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Be=new TextEncoder;function Fn(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var pe=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))Fn(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=ae(r),a=Ae(n,i);this.data.set(o,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=ae(n);return Me(r,s)}async readFileBuffer(e){let n=this.normalizePath(e),r=this.data.get(n),s=n;if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let o=new Set;for(;r&&r.type==="symlink";){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(s),s=this.resolveSymlink(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Be.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){let s=this.normalizePath(e),o=this.data.get(s);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=ae(r),a=Ae(n,i);if(o?.type==="file"){let l=o.content instanceof Uint8Array?o.content:Be.encode(o.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(s,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,n,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=n==="/"?"/":`${n}/`,o=[];for(let i of this.data.keys())if(i!==n&&i.startsWith(s)){let l=i.slice(s.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let i of o){let a=r==="/"?`/${i}`:`${r}/${i}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),o=this.normalizePath(n),i=this.data.get(s);if(!i)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(i.type==="file")this.ensureParentDirs(o),this.data.set(o,{...i});else if(i.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=s==="/"?`/${l}`:`${s}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(o.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};function L(t,e){return{type:"ArithmeticExpression",expression:te(t,e,0).expr}}function te(t,e,n){return Mn(t,e,n)}function Mn(t,e,n){let{expr:r,pos:s}=Ue(t,e,n);for(s=D(e,s);e[s]===",";){s++;let{expr:o,pos:i}=Ue(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=D(e,i)}return{expr:r,pos:s}}function Ue(t,e,n){let{expr:r,pos:s}=Bn(t,e,n);if(s=D(e,s),e[s]==="?"){s++;let{expr:o,pos:i}=te(t,e,s);if(s=D(e,i),e[s]===":"){s++;let{expr:a,pos:l}=te(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:s}}function Bn(t,e,n){let{expr:r,pos:s}=wr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:o,pos:i}=wr(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=i}return{expr:r,pos:s}}function wr(t,e,n){let{expr:r,pos:s}=gr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:o,pos:i}=gr(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=i}return{expr:r,pos:s}}function gr(t,e,n){let{expr:r,pos:s}=Ar(t,e,n);for(;s=D(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:o,pos:i}=Ar(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=i}return{expr:r,pos:s}}function Ar(t,e,n){let{expr:r,pos:s}=xr(t,e,n);for(;s=D(e,s),e[s]==="^";){s++;let{expr:o,pos:i}=xr(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=i}return{expr:r,pos:s}}function xr(t,e,n){let{expr:r,pos:s}=Sr(t,e,n);for(;s=D(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:o,pos:i}=Sr(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=i}return{expr:r,pos:s}}function Sr(t,e,n){let{expr:r,pos:s}=br(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=br(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function br(t,e,n){let{expr:r,pos:s}=yt(t,e,n);for(;;)if(s=D(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=yt(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else if(e[s]==="<"||e[s]===">"){let o=e[s];s++;let{expr:i,pos:a}=yt(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function yt(t,e,n){let{expr:r,pos:s}=Cr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Cr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Cr(t,e,n){let{expr:r,pos:s}=Nr(t,e,n);for(;s=D(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let o=e[s];s++;let{expr:i,pos:a}=Nr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Nr(t,e,n){let{expr:r,pos:s}=ze(t,e,n);for(;;)if(s=D(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:o,pos:i}=ze(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=i}else if(e[s]==="/"||e[s]==="%"){let o=e[s];s++;let{expr:i,pos:a}=ze(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function ze(t,e,n){let{expr:r,pos:s}=Et(t,e,n),o=D(e,s);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=ze(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:s}}function Et(t,e,n){let r=D(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=Et(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:o,pos:i}=Et(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}return Un(t,e,r)}function zn(t,e){let n=t[e];return n==="$"||n==="`"}function Un(t,e,n){let{expr:r,pos:s}=$r(t,e,n),o=[r];for(;zn(e,s);){let{expr:i,pos:a}=$r(t,e,s);o.push(i),s=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),s=D(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let i=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function $r(t,e,n){let r=D(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,o=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=te(t,i,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,o=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:o}=te(t,e,r);return r=D(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")o=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:xe(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+2,o=1,i=s;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(s,i),l=i+1;if(e[l]==="#"){let c=l+1;for(;c<e.length&&/[0-9a-zA-Z@_]/.test(e[c]);)c++;let f=e.slice(l+1,c);return{expr:{type:"ArithDynamicBase",baseExpr:a,value:f},pos:c}}if(/[0-9]/.test(e[l])||e[l]==="x"||e[l]==="X"){let c=l;if(e[l]==="x"||e[l]==="X")for(c++;c<e.length&&/[0-9a-fA-F]/.test(e[c]);)c++;else for(;c<e.length&&/[0-9]/.test(e[c]);)c++;let f=e.slice(l,c);return{expr:{type:"ArithDynamicNumber",prefix:a,suffix:f},pos:c}}return r=l,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let i;if(e[r]==="'"||e[r]==='"'){let c=e[r];for(r++,i="";r<e.length&&e[r]!==c;)i+=e[r],r++;e[r]===c&&r++,r=D(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:c,pos:f}=te(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=D(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},pos:r};let l=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let c of l)if(e.slice(r,r+c.length)===c&&e.slice(r,r+c.length+1)!=="=="){r+=c.length;let{expr:f,pos:h}=Ue(t,e,r);return{expr:{type:"ArithAssignment",operator:c,variable:s,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:i},pos:r}}r=D(e,r);let o=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let i of o)if(e.slice(r,r+i.length)===i&&e.slice(r,r+i.length+1)!=="=="){r+=i.length;let{expr:a,pos:l}=Ue(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:s,value:a},pos:l}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function xe(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let o of n){let i;if(o>="0"&&o<="9")i=o.charCodeAt(0)-48;else if(o>="a"&&o<="z")i=o.charCodeAt(0)-97+10;else if(o>="A"&&o<="Z")i=o.charCodeAt(0)-65+36;else if(o==="@")i=62;else if(o==="_")i=63;else return Number.NaN;if(i>=r)return Number.NaN;s=s*r+i}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function D(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
2
|
+
import{a as U,b as K,c as H,d as ee,e as Y,f as k,g as F,h as me,i as z,j as oe,k as Fe}from"./chunks/chunk-NWWB2XRE.js";import{a as X}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-5KNEBKYN.js";import*as On from"node:fs";import*as _n from"node:readline";var ur=[{name:"echo",load:async()=>(await import("./chunks/echo-DEUIS5JO.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-YZXBF5YF.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-WM4X6IZ6.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-C4MPAF3H.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-LWULWDHP.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-XCIAYF5I.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-W6CCBEMG.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-77UY7PGN.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-TDYCNSIQ.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-DB7J2W5X.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-3G4LK462.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-X4MWD4JP.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-DPNOQY67.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-VGXR3WWL.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YSVKBQ77.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-CNJ3QDRA.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-3PHITCPO.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-PHBFGJCV.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-LTCVBSRV.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-4DKPX43H.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-UJP353TM.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-W4HF6YSB.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-UYV3FM7R.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-R36J3G4K.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2EEKHHO6.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-UU2VS3OM.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-JADNFF7V.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-Y7JDBYHN.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VLHP44TU.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-4247W67O.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4FZ7WF2P.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-AKGX6HSG.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-AKGX6HSG.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-74DFXE2E.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-74DFXE2E.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-PRQ4B6N2.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-DKUAYNEK.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-JCX733LK.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-JCX733LK.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-GTCFHSB2.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-5IWSVGHN.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-5IWSVGHN.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-EYSXBSCP.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-NC7HTKLZ.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-TG2NXCX2.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-7NBRXV2Z.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-E4DIYGTT.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RP2AJGMV.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-DGJILX2Q.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-HA2ZNL6S.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-L4UWMK4S.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-YQGNAT2T.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-HX2NMOP3.js")).whichCommand}],Ln=[{name:"curl",load:async()=>(await import("./chunks/curl-NE7XEWMN.js")).curlCommand}],hr=new Map;function dr(t){return{name:t.name,async execute(e,n){let r=hr.get(t.name);return r||(r=await t.load(),hr.set(t.name,r)),r.execute(e,n)}}}function mr(t){return(t?ur.filter(n=>t.includes(n.name)):ur).map(dr)}function pr(){return Ln.map(dr)}function yr(t){return"load"in t&&typeof t.load=="function"}function Er(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var Tn=new TextEncoder,Wn=new TextDecoder;function Ae(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),n=>n.charCodeAt(0));case"hex":{let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}case"binary":case"latin1":return Uint8Array.from(t,n=>n.charCodeAt(0));default:return Tn.encode(t)}}function Me(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Wn.decode(t)}}function ae(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Be=new TextEncoder;function Fn(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var pe=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))Fn(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=ae(r),a=Ae(n,i);this.data.set(o,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=ae(n);return Me(r,s)}async readFileBuffer(e){let n=this.normalizePath(e),r=this.data.get(n),s=n;if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let o=new Set;for(;r&&r.type==="symlink";){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(s),s=this.resolveSymlink(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Be.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){let s=this.normalizePath(e),o=this.data.get(s);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=ae(r),a=Ae(n,i);if(o?.type==="file"){let l=o.content instanceof Uint8Array?o.content:Be.encode(o.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(s,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,n,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=n==="/"?"/":`${n}/`,o=[];for(let i of this.data.keys())if(i!==n&&i.startsWith(s)){let l=i.slice(s.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let i of o){let a=r==="/"?`/${i}`:`${r}/${i}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),o=this.normalizePath(n),i=this.data.get(s);if(!i)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(i.type==="file")this.ensureParentDirs(o),this.data.set(o,{...i});else if(i.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=s==="/"?`/${l}`:`${s}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(o.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};function L(t,e){return{type:"ArithmeticExpression",expression:te(t,e,0).expr}}function te(t,e,n){return Mn(t,e,n)}function Mn(t,e,n){let{expr:r,pos:s}=Ue(t,e,n);for(s=D(e,s);e[s]===",";){s++;let{expr:o,pos:i}=Ue(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=D(e,i)}return{expr:r,pos:s}}function Ue(t,e,n){let{expr:r,pos:s}=Bn(t,e,n);if(s=D(e,s),e[s]==="?"){s++;let{expr:o,pos:i}=te(t,e,s);if(s=D(e,i),e[s]===":"){s++;let{expr:a,pos:l}=te(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:s}}function Bn(t,e,n){let{expr:r,pos:s}=wr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:o,pos:i}=wr(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=i}return{expr:r,pos:s}}function wr(t,e,n){let{expr:r,pos:s}=gr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:o,pos:i}=gr(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=i}return{expr:r,pos:s}}function gr(t,e,n){let{expr:r,pos:s}=Ar(t,e,n);for(;s=D(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:o,pos:i}=Ar(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=i}return{expr:r,pos:s}}function Ar(t,e,n){let{expr:r,pos:s}=xr(t,e,n);for(;s=D(e,s),e[s]==="^";){s++;let{expr:o,pos:i}=xr(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=i}return{expr:r,pos:s}}function xr(t,e,n){let{expr:r,pos:s}=Sr(t,e,n);for(;s=D(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:o,pos:i}=Sr(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=i}return{expr:r,pos:s}}function Sr(t,e,n){let{expr:r,pos:s}=br(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=br(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function br(t,e,n){let{expr:r,pos:s}=yt(t,e,n);for(;;)if(s=D(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=yt(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else if(e[s]==="<"||e[s]===">"){let o=e[s];s++;let{expr:i,pos:a}=yt(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function yt(t,e,n){let{expr:r,pos:s}=Cr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Cr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Cr(t,e,n){let{expr:r,pos:s}=Nr(t,e,n);for(;s=D(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let o=e[s];s++;let{expr:i,pos:a}=Nr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Nr(t,e,n){let{expr:r,pos:s}=ze(t,e,n);for(;;)if(s=D(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:o,pos:i}=ze(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=i}else if(e[s]==="/"||e[s]==="%"){let o=e[s];s++;let{expr:i,pos:a}=ze(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function ze(t,e,n){let{expr:r,pos:s}=Et(t,e,n),o=D(e,s);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=ze(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:s}}function Et(t,e,n){let r=D(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=Et(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:o,pos:i}=Et(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}return Un(t,e,r)}function zn(t,e){let n=t[e];return n==="$"||n==="`"}function Un(t,e,n){let{expr:r,pos:s}=$r(t,e,n),o=[r];for(;zn(e,s);){let{expr:i,pos:a}=$r(t,e,s);o.push(i),s=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),s=D(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let i=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function $r(t,e,n){let r=D(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,o=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=te(t,i,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,o=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:o}=te(t,e,r);return r=D(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")o=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:xe(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+2,o=1,i=s;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(s,i),l=i+1;if(e[l]==="#"){let c=l+1;for(;c<e.length&&/[0-9a-zA-Z@_]/.test(e[c]);)c++;let f=e.slice(l+1,c);return{expr:{type:"ArithDynamicBase",baseExpr:a,value:f},pos:c}}if(/[0-9]/.test(e[l])||e[l]==="x"||e[l]==="X"){let c=l;if(e[l]==="x"||e[l]==="X")for(c++;c<e.length&&/[0-9a-fA-F]/.test(e[c]);)c++;else for(;c<e.length&&/[0-9]/.test(e[c]);)c++;let f=e.slice(l,c);return{expr:{type:"ArithDynamicNumber",prefix:a,suffix:f},pos:c}}return r=l,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let i;if(e[r]==="'"||e[r]==='"'){let c=e[r];for(r++,i="";r<e.length&&e[r]!==c;)i+=e[r],r++;e[r]===c&&r++,r=D(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:c,pos:f}=te(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=D(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},pos:r};let l=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let c of l)if(e.slice(r,r+c.length)===c&&e.slice(r,r+c.length+1)!=="=="){r+=c.length;let{expr:f,pos:h}=Ue(t,e,r);return{expr:{type:"ArithAssignment",operator:c,variable:s,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:i},pos:r}}r=D(e,r);let o=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let i of o)if(e.slice(r,r+i.length)===i&&e.slice(r,r+i.length+1)!=="=="){r+=i.length;let{expr:a,pos:l}=Ue(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:s,value:a},pos:l}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function xe(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let o of n){let i;if(o>="0"&&o<="9")i=o.charCodeAt(0)-48;else if(o>="a"&&o<="z")i=o.charCodeAt(0)-97+10;else if(o>="A"&&o<="Z")i=o.charCodeAt(0)-65+36;else if(o==="@")i=62;else if(o==="_")i=63;else return Number.NaN;if(i>=r)return Number.NaN;s=s*r+i}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function D(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
3
3
|
`){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var A={script(t){return{type:"Script",statements:t}},statement(t,e=[],n=!1){return{type:"Statement",pipelines:t,operators:e,background:n}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],n=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:n,redirections:r}},word(t){return{type:"Word",parts:t}},literal(t){return{type:"Literal",value:t}},singleQuoted(t){return{type:"SingleQuoted",value:t}},doubleQuoted(t){return{type:"DoubleQuoted",parts:t}},escaped(t){return{type:"Escaped",value:t}},parameterExpansion(t,e=null){return{type:"ParameterExpansion",parameter:t,operation:e}},commandSubstitution(t,e=!1){return{type:"CommandSubstitution",body:t,legacy:e}},arithmeticExpansion(t){return{type:"ArithmeticExpansion",expression:t}},assignment(t,e,n=!1,r=null){return{type:"Assignment",name:t,value:e,append:n,array:r}},redirection(t,e,n=null){return{type:"Redirection",fd:n,operator:t,target:e}},hereDoc(t,e,n=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:n,quoted:r}},ifNode(t,e=null,n=[]){return{type:"If",clauses:t,elseBody:e,redirections:n}},forNode(t,e,n,r=[]){return{type:"For",variable:t,words:e,body:n,redirections:r}},whileNode(t,e,n=[]){return{type:"While",condition:t,body:e,redirections:n}},untilNode(t,e,n=[]){return{type:"Until",condition:t,body:e,redirections:n}},caseNode(t,e,n=[]){return{type:"Case",word:t,items:e,redirections:n}},caseItem(t,e,n=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:n}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,n=[]){return{type:"FunctionDef",name:t,body:e,redirections:n}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var u;(function(t){t.EOF="EOF",t.NEWLINE="NEWLINE",t.SEMICOLON="SEMICOLON",t.AMP="AMP",t.PIPE="PIPE",t.PIPE_AMP="PIPE_AMP",t.AND_AND="AND_AND",t.OR_OR="OR_OR",t.BANG="BANG",t.LESS="LESS",t.GREAT="GREAT",t.DLESS="DLESS",t.DGREAT="DGREAT",t.LESSAND="LESSAND",t.GREATAND="GREATAND",t.LESSGREAT="LESSGREAT",t.DLESSDASH="DLESSDASH",t.CLOBBER="CLOBBER",t.TLESS="TLESS",t.AND_GREAT="AND_GREAT",t.AND_DGREAT="AND_DGREAT",t.LPAREN="LPAREN",t.RPAREN="RPAREN",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.DSEMI="DSEMI",t.SEMI_AND="SEMI_AND",t.SEMI_SEMI_AND="SEMI_SEMI_AND",t.DBRACK_START="DBRACK_START",t.DBRACK_END="DBRACK_END",t.DPAREN_START="DPAREN_START",t.DPAREN_END="DPAREN_END",t.IF="IF",t.THEN="THEN",t.ELSE="ELSE",t.ELIF="ELIF",t.FI="FI",t.FOR="FOR",t.WHILE="WHILE",t.UNTIL="UNTIL",t.DO="DO",t.DONE="DONE",t.CASE="CASE",t.ESAC="ESAC",t.IN="IN",t.FUNCTION="FUNCTION",t.SELECT="SELECT",t.TIME="TIME",t.COPROC="COPROC",t.WORD="WORD",t.NAME="NAME",t.NUMBER="NUMBER",t.ASSIGNMENT_WORD="ASSIGNMENT_WORD",t.COMMENT="COMMENT",t.HEREDOC_CONTENT="HEREDOC_CONTENT"})(u||(u={}));var He={if:u.IF,then:u.THEN,else:u.ELSE,elif:u.ELIF,fi:u.FI,for:u.FOR,while:u.WHILE,until:u.UNTIL,do:u.DO,done:u.DONE,case:u.CASE,esac:u.ESAC,in:u.IN,function:u.FUNCTION,select:u.SELECT,time:u.TIME,coproc:u.COPROC};function Pr(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let n=t.slice(e[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let o=n.slice(s+1);return o===""||o==="+"}return!1}var Hn=[[";",";","&",u.SEMI_SEMI_AND],["<","<","<",u.TLESS],["&",">",">",u.AND_DGREAT]],Gn=[["[","[",u.DBRACK_START],["]","]",u.DBRACK_END],["(","(",u.DPAREN_START],[")",")",u.DPAREN_END],["&","&",u.AND_AND],["|","|",u.OR_OR],[";",";",u.DSEMI],[";","&",u.SEMI_AND],["|","&",u.PIPE_AMP],[">",">",u.DGREAT],["<","&",u.LESSAND],[">","&",u.GREATAND],["<",">",u.LESSGREAT],[">","|",u.CLOBBER],["&",">",u.AND_GREAT]],Vn={"|":u.PIPE,"&":u.AMP,";":u.SEMICOLON,"(":u.LPAREN,")":u.RPAREN,"<":u.LESS,">":u.GREAT};function Zn(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Ge=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n&&(this.skipWhitespace(),!(this.pos>=n));){if(s.length>0&&r.length>0&&r[r.length-1].type===u.NEWLINE){this.readHeredocContent();continue}let o=this.nextToken();o&&r.push(o)}return r.push({type:u.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let e=this.input,n=e.length,r=this.pos,s=this.column,o=this.line;for(;r<n;){let i=e[r];if(i===" "||i===" ")r++,s++;else if(i==="\\"&&e[r+1]===`
|
|
4
4
|
`)r+=2,o++,s=1;else break}this.pos=r,this.column=s,this.line=o}nextToken(){let e=this.input,n=this.pos,r=this.line,s=this.column,o=e[n],i=e[n+1],a=e[n+2];if(o==="#")return this.readComment(n,r,s);if(o===`
|
|
5
5
|
`)return this.pos=n+1,this.line++,this.column=1,{type:u.NEWLINE,value:`
|