just-bash 1.2.2 → 1.2.3
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/find-HW2TUO6B.js +11 -0
- package/dist/bin/just-bash.js +1 -1
- package/dist/bin/shell/chunks/find-HW2TUO6B.js +11 -0
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/ai/index.js +1 -1
- package/dist/bundle/chunks/find-4QUN2ATO.js +10 -0
- package/dist/bundle/index.js +1 -1
- 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 A,b as z}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";function g(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 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 I(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 $(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 u=parseInt(f,10);Number.isNaN(u)||t.push({type:"expr",expr:{type:"mtime",days:u,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 u=f.match(/^(\d+)([ckMGb])?$/);if(u){let m=parseInt(u[1],10),v=u[2]||"b";t.push({type:"expr",expr:{type:"size",value:m,unit:v,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 u=parseInt(f,8);Number.isNaN(u)||t.push({type:"expr",expr:{type:"perm",mode:u,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==="-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=S(t);return w.error?{expr:null,pathIndex:n,error:w.error,actions:r}:{expr:w.expr,pathIndex:n,actions:r}}function S(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 F={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","-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"]},L=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),K={name:"find",async execute(e,s){if(z(e))return A(F);let t=".",r=null,n=null;for(let a=0;a<e.length;a++){let p=e[a];if(p==="-maxdepth"&&a+1<e.length)r=parseInt(e[++a],10);else if(p==="-mindepth"&&a+1<e.length)n=parseInt(e[++a],10);else if(p==="-exec")for(a++;a<e.length&&e[a]!==";"&&e[a]!=="+";)a++;else!p.startsWith("-")&&p!==";"&&p!=="+"&&p!=="("&&p!==")"&&p!=="\\("&&p!=="\\)"&&p!=="!"?t=p:L.has(p)&&a++}let{expr:w,error:l,actions:i}=$(e,0);if(l)return{stdout:"",stderr:l,exitCode:1};let o=i.some(a=>a.type==="print"),f=i.length===0,u=s.fs.resolvePath(s.cwd,t);try{await s.fs.stat(u)}catch{return{stdout:"",stderr:`find: ${t}: No such file or directory
|
|
5
|
+
`,exitCode:1}}let m=[],v=I(w),C=new Map;for(let a of v){let p=s.fs.resolvePath(s.cwd,a);try{let c=await s.fs.stat(p);C.set(a,c.mtime?.getTime()??Date.now())}catch{}}async function R(a,p){if(r!==null&&p>r)return;let c;try{c=await s.fs.stat(a)}catch{return}if(!c)return;let d;a===u?d=t.split("/").pop()||t:d=a.split("/").pop()||"";let h=a===u?t:t==="."?`./${a.slice(u.length+1)}`:t+a.slice(u.length),y=null;c.isDirectory&&(y=await s.fs.readdir(a));let W=c.isFile?c.size===0:y!==null&&y.length===0,P=n===null||p>=n,k=!1,D=!1;if(P&&w!==null){let M={name:d,relativePath:h,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:W,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C},E=g(w,M);P=E.matches,k=E.pruned,o?D=E.printed:D=P}else P&&(D=!0);if(D&&m.push(h),y!==null&&!k)for(let M of y){let E=a==="/"?`/${M}`:`${a}/${M}`;await R(E,p+1)}}await R(u,0);let x="",b="",T=0;if(i.length>0)for(let a of i)switch(a.type){case"print":x+=m.length>0?`${m.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"";break;case"print0":x+=m.length>0?`${m.join("\0")}\0`:"";break;case"delete":{let p=[...m].sort((c,d)=>d.length-c.length);for(let c of p){let d=s.fs.resolvePath(s.cwd,c);try{await s.fs.rm(d,{recursive:!1})}catch(h){let y=h instanceof Error?h.message:String(h);b+=`find: cannot delete '${c}': ${y}
|
|
8
|
+
`,T=1}}break}case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
9
|
+
`,exitCode:1};if(a.batchMode){let p=[];for(let h of a.command)h==="{}"?p.push(...m):p.push(h);let c=p.map(h=>`"${h}"`).join(" "),d=await s.exec(c,{cwd:s.cwd});x+=d.stdout,b+=d.stderr,d.exitCode!==0&&(T=d.exitCode)}else for(let p of m){let d=a.command.map(y=>y==="{}"?p:y).map(y=>`"${y}"`).join(" "),h=await s.exec(d,{cwd:s.cwd});x+=h.stdout,b+=h.stderr,h.exitCode!==0&&(T=h.exitCode)}break}else f&&(x=m.length>0?`${m.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:"");return{stdout:x,stderr:b,exitCode:T}}};export{K as findCommand};
|
package/dist/bin/just-bash.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as z,b as Q,c as U,d as Y,e as K,f as k,g as W,h as de,i as B,j as ie,k as Fe}from"./chunks/chunk-NWWB2XRE.js";import{a as ne}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-5KNEBKYN.js";import{resolve as ks}from"node:path";var lr=[{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-WJV3FM6L.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}],Ds=[{name:"curl",load:async()=>(await import("./chunks/curl-NE7XEWMN.js")).curlCommand}],fr=new Map;function ur(t){return{name:t.name,async execute(e,s){let r=fr.get(t.name);return r||(r=await t.load(),fr.set(t.name,r)),r.execute(e,s)}}}function hr(t){return(t?lr.filter(s=>t.includes(s.name)):lr).map(ur)}function dr(){return Ds.map(ur)}function pr(t){return"load"in t&&typeof t.load=="function"}function mr(t){let e=null;return{name:t.name,async execute(s,r){return e||(e=await t.load()),e.execute(s,r)}}}var Os=new TextEncoder,_s=new TextDecoder;function ge(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),s=>s.charCodeAt(0));case"hex":{let s=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)s[r/2]=parseInt(t.slice(r,r+2),16);return s}case"binary":case"latin1":return Uint8Array.from(t,s=>s.charCodeAt(0));default:return Os.encode(t)}}function Me(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return _s.decode(t)}}function oe(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Be=new TextEncoder;function Ls(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[s,r]of Object.entries(e))Ls(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(o=>o&&o!=="."),n=[];for(let o of r)o===".."?n.pop():n.push(o);return`/${n.join("/")}`||"/"}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,s,r,n){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=oe(r),a=ge(s,i);this.data.set(o,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}async readFile(e,s){let r=await this.readFileBuffer(e),n=oe(s);return Me(r,n)}async readFileBuffer(e){let s=this.normalizePath(e),r=this.data.get(s),n=s;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(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}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,s,r){this.writeFileSync(e,s,r)}async appendFile(e,s,r){let n=this.normalizePath(e),o=this.data.get(n);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=oe(r),a=ge(s,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(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,s,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(s,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(e){let s=this.normalizePath(e),r=this.data.get(s);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 n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}async mkdir(e,s){this.mkdirSync(e,s)}mkdirSync(e,s){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(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let n=this.dirname(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{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 s=this.normalizePath(e),r=this.data.get(s);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 n=s==="/"?"/":`${s}/`,o=[];for(let i of this.data.keys())if(i!==s&&i.startsWith(n)){let l=i.slice(n.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(n.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!s?.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,s)}}}this.data.delete(r)}async cp(e,s,r){let n=this.normalizePath(e),o=this.normalizePath(s),i=this.data.get(n);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(n);for(let l of a){let c=n==="/"?`/${l}`:`${n}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,s){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}async chmod(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);n.mode=s}async symlink(e,s){let r=this.normalizePath(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,s){let r=this.normalizePath(e),n=this.normalizePath(s),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(n))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let s=this.normalizePath(e),r=this.data.get(s);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:J(t,e,0).expr}}function J(t,e,s){return Ts(t,e,s)}function Ts(t,e,s){let{expr:r,pos:n}=Ue(t,e,s);for(n=D(e,n);e[n]===",";){n++;let{expr:o,pos:i}=Ue(t,e,n);r={type:"ArithBinary",operator:",",left:r,right:o},n=D(e,i)}return{expr:r,pos:n}}function Ue(t,e,s){let{expr:r,pos:n}=Ws(t,e,s);if(n=D(e,n),e[n]==="?"){n++;let{expr:o,pos:i}=J(t,e,n);if(n=D(e,i),e[n]===":"){n++;let{expr:a,pos:l}=J(t,e,n);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:n}}function Ws(t,e,s){let{expr:r,pos:n}=yr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="||";){n+=2;let{expr:o,pos:i}=yr(t,e,n);r={type:"ArithBinary",operator:"||",left:r,right:o},n=i}return{expr:r,pos:n}}function yr(t,e,s){let{expr:r,pos:n}=Er(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="&&";){n+=2;let{expr:o,pos:i}=Er(t,e,n);r={type:"ArithBinary",operator:"&&",left:r,right:o},n=i}return{expr:r,pos:n}}function Er(t,e,s){let{expr:r,pos:n}=wr(t,e,s);for(;n=D(e,n),e[n]==="|"&&e[n+1]!=="|";){n++;let{expr:o,pos:i}=wr(t,e,n);r={type:"ArithBinary",operator:"|",left:r,right:o},n=i}return{expr:r,pos:n}}function wr(t,e,s){let{expr:r,pos:n}=gr(t,e,s);for(;n=D(e,n),e[n]==="^";){n++;let{expr:o,pos:i}=gr(t,e,n);r={type:"ArithBinary",operator:"^",left:r,right:o},n=i}return{expr:r,pos:n}}function gr(t,e,s){let{expr:r,pos:n}=Ar(t,e,s);for(;n=D(e,n),e[n]==="&"&&e[n+1]!=="&";){n++;let{expr:o,pos:i}=Ar(t,e,n);r={type:"ArithBinary",operator:"&",left:r,right:o},n=i}return{expr:r,pos:n}}function Ar(t,e,s){let{expr:r,pos:n}=xr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="=="||e.slice(n,n+2)==="!=";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=xr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function xr(t,e,s){let{expr:r,pos:n}=mt(t,e,s);for(;;)if(n=D(e,n),e.slice(n,n+2)==="<="||e.slice(n,n+2)===">="){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=mt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else if(e[n]==="<"||e[n]===">"){let o=e[n];n++;let{expr:i,pos:a}=mt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function mt(t,e,s){let{expr:r,pos:n}=Sr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="<<"||e.slice(n,n+2)===">>";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=Sr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Sr(t,e,s){let{expr:r,pos:n}=br(t,e,s);for(;n=D(e,n),(e[n]==="+"||e[n]==="-")&&e[n+1]!==e[n];){let o=e[n];n++;let{expr:i,pos:a}=br(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function br(t,e,s){let{expr:r,pos:n}=ze(t,e,s);for(;;)if(n=D(e,n),e[n]==="*"&&e[n+1]!=="*"){n++;let{expr:o,pos:i}=ze(t,e,n);r={type:"ArithBinary",operator:"*",left:r,right:o},n=i}else if(e[n]==="/"||e[n]==="%"){let o=e[n];n++;let{expr:i,pos:a}=ze(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function ze(t,e,s){let{expr:r,pos:n}=yt(t,e,s),o=D(e,n);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:n}}function yt(t,e,s){let r=D(e,s);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let n=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=yt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let n=e[r];r++;let{expr:o,pos:i}=yt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}return Ms(t,e,r)}function Fs(t,e){let s=t[e];return s==="$"||s==="`"}function Ms(t,e,s){let{expr:r,pos:n}=Cr(t,e,s),o=[r];for(;Fs(e,n);){let{expr:i,pos:a}=Cr(t,e,n);o.push(i),n=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),n=D(e,n),e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let i=e.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Cr(t,e,s){let r=D(e,s);if(e.slice(r,r+3)==="$(("){r+=3;let n=1,o=r;for(;r<e.length-1&&n>0;)e[r]==="("&&e[r+1]==="("?(n++,r+=2):e[r]===")"&&e[r+1]===")"?(n--,n>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=J(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 n=1,o=r;for(;r<e.length&&n>0;)e[r]==="("?n++:e[r]===")"&&n--,n>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let n=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(n,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:n,pos:o}=J(t,e,r);return r=D(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:n},pos:r}}if(/[0-9]/.test(e[r])){let n="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))n+=a,r++;else break;else if(a==="#")o=!0,n+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))n+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new W(`${n}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:n,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Ae(n)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let n=r+2,o=1,i=n;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(n,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 n="";for(;r<e.length&&/[0-9]/.test(e[r]);)n+=e[r],r++;return{expr:{type:"ArithVariable",name:n},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=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}=J(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=D(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:n,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:n,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:n,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:n,value:a},pos:l}}return{expr:{type:"ArithVariable",name:n},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function Ae(t){if(t.includes("#")){let[e,s]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(s,r);let n=0;for(let o of s){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;n=n*r+i}return n}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 z,b as Q,c as U,d as Y,e as K,f as k,g as W,h as de,i as B,j as ie,k as Fe}from"./chunks/chunk-NWWB2XRE.js";import{a as ne}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-5KNEBKYN.js";import{resolve as ks}from"node:path";var lr=[{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}],Ds=[{name:"curl",load:async()=>(await import("./chunks/curl-NE7XEWMN.js")).curlCommand}],fr=new Map;function ur(t){return{name:t.name,async execute(e,s){let r=fr.get(t.name);return r||(r=await t.load(),fr.set(t.name,r)),r.execute(e,s)}}}function hr(t){return(t?lr.filter(s=>t.includes(s.name)):lr).map(ur)}function dr(){return Ds.map(ur)}function pr(t){return"load"in t&&typeof t.load=="function"}function mr(t){let e=null;return{name:t.name,async execute(s,r){return e||(e=await t.load()),e.execute(s,r)}}}var Os=new TextEncoder,_s=new TextDecoder;function ge(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),s=>s.charCodeAt(0));case"hex":{let s=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)s[r/2]=parseInt(t.slice(r,r+2),16);return s}case"binary":case"latin1":return Uint8Array.from(t,s=>s.charCodeAt(0));default:return Os.encode(t)}}function Me(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return _s.decode(t)}}function oe(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Be=new TextEncoder;function Ls(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[s,r]of Object.entries(e))Ls(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(o=>o&&o!=="."),n=[];for(let o of r)o===".."?n.pop():n.push(o);return`/${n.join("/")}`||"/"}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,s,r,n){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=oe(r),a=ge(s,i);this.data.set(o,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}async readFile(e,s){let r=await this.readFileBuffer(e),n=oe(s);return Me(r,n)}async readFileBuffer(e){let s=this.normalizePath(e),r=this.data.get(s),n=s;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(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}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,s,r){this.writeFileSync(e,s,r)}async appendFile(e,s,r){let n=this.normalizePath(e),o=this.data.get(n);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=oe(r),a=ge(s,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(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,s,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(s,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(e){let s=this.normalizePath(e),r=this.data.get(s);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 n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Be.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}async mkdir(e,s){this.mkdirSync(e,s)}mkdirSync(e,s){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(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let n=this.dirname(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{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 s=this.normalizePath(e),r=this.data.get(s);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 n=s==="/"?"/":`${s}/`,o=[];for(let i of this.data.keys())if(i!==s&&i.startsWith(n)){let l=i.slice(n.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(n.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!s?.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,s)}}}this.data.delete(r)}async cp(e,s,r){let n=this.normalizePath(e),o=this.normalizePath(s),i=this.data.get(n);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(n);for(let l of a){let c=n==="/"?`/${l}`:`${n}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,s){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}async chmod(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);n.mode=s}async symlink(e,s){let r=this.normalizePath(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,s){let r=this.normalizePath(e),n=this.normalizePath(s),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(n))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let s=this.normalizePath(e),r=this.data.get(s);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:J(t,e,0).expr}}function J(t,e,s){return Ts(t,e,s)}function Ts(t,e,s){let{expr:r,pos:n}=Ue(t,e,s);for(n=D(e,n);e[n]===",";){n++;let{expr:o,pos:i}=Ue(t,e,n);r={type:"ArithBinary",operator:",",left:r,right:o},n=D(e,i)}return{expr:r,pos:n}}function Ue(t,e,s){let{expr:r,pos:n}=Ws(t,e,s);if(n=D(e,n),e[n]==="?"){n++;let{expr:o,pos:i}=J(t,e,n);if(n=D(e,i),e[n]===":"){n++;let{expr:a,pos:l}=J(t,e,n);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:n}}function Ws(t,e,s){let{expr:r,pos:n}=yr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="||";){n+=2;let{expr:o,pos:i}=yr(t,e,n);r={type:"ArithBinary",operator:"||",left:r,right:o},n=i}return{expr:r,pos:n}}function yr(t,e,s){let{expr:r,pos:n}=Er(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="&&";){n+=2;let{expr:o,pos:i}=Er(t,e,n);r={type:"ArithBinary",operator:"&&",left:r,right:o},n=i}return{expr:r,pos:n}}function Er(t,e,s){let{expr:r,pos:n}=wr(t,e,s);for(;n=D(e,n),e[n]==="|"&&e[n+1]!=="|";){n++;let{expr:o,pos:i}=wr(t,e,n);r={type:"ArithBinary",operator:"|",left:r,right:o},n=i}return{expr:r,pos:n}}function wr(t,e,s){let{expr:r,pos:n}=gr(t,e,s);for(;n=D(e,n),e[n]==="^";){n++;let{expr:o,pos:i}=gr(t,e,n);r={type:"ArithBinary",operator:"^",left:r,right:o},n=i}return{expr:r,pos:n}}function gr(t,e,s){let{expr:r,pos:n}=Ar(t,e,s);for(;n=D(e,n),e[n]==="&"&&e[n+1]!=="&";){n++;let{expr:o,pos:i}=Ar(t,e,n);r={type:"ArithBinary",operator:"&",left:r,right:o},n=i}return{expr:r,pos:n}}function Ar(t,e,s){let{expr:r,pos:n}=xr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="=="||e.slice(n,n+2)==="!=";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=xr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function xr(t,e,s){let{expr:r,pos:n}=mt(t,e,s);for(;;)if(n=D(e,n),e.slice(n,n+2)==="<="||e.slice(n,n+2)===">="){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=mt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else if(e[n]==="<"||e[n]===">"){let o=e[n];n++;let{expr:i,pos:a}=mt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function mt(t,e,s){let{expr:r,pos:n}=Sr(t,e,s);for(;n=D(e,n),e.slice(n,n+2)==="<<"||e.slice(n,n+2)===">>";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=Sr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Sr(t,e,s){let{expr:r,pos:n}=br(t,e,s);for(;n=D(e,n),(e[n]==="+"||e[n]==="-")&&e[n+1]!==e[n];){let o=e[n];n++;let{expr:i,pos:a}=br(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function br(t,e,s){let{expr:r,pos:n}=ze(t,e,s);for(;;)if(n=D(e,n),e[n]==="*"&&e[n+1]!=="*"){n++;let{expr:o,pos:i}=ze(t,e,n);r={type:"ArithBinary",operator:"*",left:r,right:o},n=i}else if(e[n]==="/"||e[n]==="%"){let o=e[n];n++;let{expr:i,pos:a}=ze(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function ze(t,e,s){let{expr:r,pos:n}=yt(t,e,s),o=D(e,n);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:n}}function yt(t,e,s){let r=D(e,s);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let n=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=yt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let n=e[r];r++;let{expr:o,pos:i}=yt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}return Ms(t,e,r)}function Fs(t,e){let s=t[e];return s==="$"||s==="`"}function Ms(t,e,s){let{expr:r,pos:n}=Cr(t,e,s),o=[r];for(;Fs(e,n);){let{expr:i,pos:a}=Cr(t,e,n);o.push(i),n=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),n=D(e,n),e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let i=e.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Cr(t,e,s){let r=D(e,s);if(e.slice(r,r+3)==="$(("){r+=3;let n=1,o=r;for(;r<e.length-1&&n>0;)e[r]==="("&&e[r+1]==="("?(n++,r+=2):e[r]===")"&&e[r+1]===")"?(n--,n>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=J(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 n=1,o=r;for(;r<e.length&&n>0;)e[r]==="("?n++:e[r]===")"&&n--,n>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let n=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(n,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:n,pos:o}=J(t,e,r);return r=D(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:n},pos:r}}if(/[0-9]/.test(e[r])){let n="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))n+=a,r++;else break;else if(a==="#")o=!0,n+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))n+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new W(`${n}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:n,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Ae(n)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let n=r+2,o=1,i=n;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(n,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 n="";for(;r<e.length&&/[0-9]/.test(e[r]);)n+=e[r],r++;return{expr:{type:"ArithVariable",name:n},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=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}=J(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=D(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:n,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:n,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:n,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:n,value:a},pos:l}}return{expr:{type:"ArithVariable",name:n},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function Ae(t){if(t.includes("#")){let[e,s]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(s,r);let n=0;for(let o of s){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;n=n*r+i}return n}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=[],s=!1){return{type:"Statement",pipelines:t,operators:e,background:s}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],s=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:s,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,s=!1,r=null){return{type:"Assignment",name:t,value:e,append:s,array:r}},redirection(t,e,s=null){return{type:"Redirection",fd:s,operator:t,target:e}},hereDoc(t,e,s=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:s,quoted:r}},ifNode(t,e=null,s=[]){return{type:"If",clauses:t,elseBody:e,redirections:s}},forNode(t,e,s,r=[]){return{type:"For",variable:t,words:e,body:s,redirections:r}},whileNode(t,e,s=[]){return{type:"While",condition:t,body:e,redirections:s}},untilNode(t,e,s=[]){return{type:"Until",condition:t,body:e,redirections:s}},caseNode(t,e,s=[]){return{type:"Case",word:t,items:e,redirections:s}},caseItem(t,e,s=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:s}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,s=[]){return{type:"FunctionDef",name:t,body:e,redirections:s}},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 je={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 $r(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let s=t.slice(e[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n<s.length;n++)if(s[n]==="[")r++;else if(s[n]==="]"&&(r--,r===0))break;if(r!==0||n>=s.length)return!1;let o=s.slice(n+1);return o===""||o==="+"}return!1}var Bs=[[";",";","&",u.SEMI_SEMI_AND],["<","<","<",u.TLESS],["&",">",">",u.AND_DGREAT]],zs=[["[","[",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]],Us={"|":u.PIPE,"&":u.AMP,";":u.SEMICOLON,"(":u.LPAREN,")":u.RPAREN,"<":u.LESS,">":u.GREAT};function js(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 s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos<s&&(this.skipWhitespace(),!(this.pos>=s));){if(n.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,s=e.length,r=this.pos,n=this.column,o=this.line;for(;r<s;){let i=e[r];if(i===" "||i===" ")r++,n++;else if(i==="\\"&&e[r+1]===`
|
|
4
4
|
`)r+=2,o++,n=1;else break}this.pos=r,this.column=n,this.line=o}nextToken(){let e=this.input,s=this.pos,r=this.line,n=this.column,o=e[s],i=e[s+1],a=e[s+2];if(o==="#")return this.readComment(s,r,n);if(o===`
|
|
5
5
|
`)return this.pos=s+1,this.line++,this.column=1,{type:u.NEWLINE,value:`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as N}from"./chunk-26Q3PZQ6.js";import{a as A,b as z}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";function g(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 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 I(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 $(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 u=parseInt(f,10);Number.isNaN(u)||t.push({type:"expr",expr:{type:"mtime",days:u,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 u=f.match(/^(\d+)([ckMGb])?$/);if(u){let m=parseInt(u[1],10),v=u[2]||"b";t.push({type:"expr",expr:{type:"size",value:m,unit:v,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 u=parseInt(f,8);Number.isNaN(u)||t.push({type:"expr",expr:{type:"perm",mode:u,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==="-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=S(t);return w.error?{expr:null,pathIndex:n,error:w.error,actions:r}:{expr:w.expr,pathIndex:n,actions:r}}function S(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 F={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","-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"]},L=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),K={name:"find",async execute(e,s){if(z(e))return A(F);let t=".",r=null,n=null;for(let a=0;a<e.length;a++){let p=e[a];if(p==="-maxdepth"&&a+1<e.length)r=parseInt(e[++a],10);else if(p==="-mindepth"&&a+1<e.length)n=parseInt(e[++a],10);else if(p==="-exec")for(a++;a<e.length&&e[a]!==";"&&e[a]!=="+";)a++;else!p.startsWith("-")&&p!==";"&&p!=="+"&&p!=="("&&p!==")"&&p!=="\\("&&p!=="\\)"&&p!=="!"?t=p:L.has(p)&&a++}let{expr:w,error:l,actions:i}=$(e,0);if(l)return{stdout:"",stderr:l,exitCode:1};let o=i.some(a=>a.type==="print"),f=i.length===0,u=s.fs.resolvePath(s.cwd,t);try{await s.fs.stat(u)}catch{return{stdout:"",stderr:`find: ${t}: No such file or directory
|
|
5
|
+
`,exitCode:1}}let m=[],v=I(w),C=new Map;for(let a of v){let p=s.fs.resolvePath(s.cwd,a);try{let c=await s.fs.stat(p);C.set(a,c.mtime?.getTime()??Date.now())}catch{}}async function R(a,p){if(r!==null&&p>r)return;let c;try{c=await s.fs.stat(a)}catch{return}if(!c)return;let d;a===u?d=t.split("/").pop()||t:d=a.split("/").pop()||"";let h=a===u?t:t==="."?`./${a.slice(u.length+1)}`:t+a.slice(u.length),y=null;c.isDirectory&&(y=await s.fs.readdir(a));let W=c.isFile?c.size===0:y!==null&&y.length===0,P=n===null||p>=n,k=!1,D=!1;if(P&&w!==null){let M={name:d,relativePath:h,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:W,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C},E=g(w,M);P=E.matches,k=E.pruned,o?D=E.printed:D=P}else P&&(D=!0);if(D&&m.push(h),y!==null&&!k)for(let M of y){let E=a==="/"?`/${M}`:`${a}/${M}`;await R(E,p+1)}}await R(u,0);let x="",b="",T=0;if(i.length>0)for(let a of i)switch(a.type){case"print":x+=m.length>0?`${m.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`:"";break;case"print0":x+=m.length>0?`${m.join("\0")}\0`:"";break;case"delete":{let p=[...m].sort((c,d)=>d.length-c.length);for(let c of p){let d=s.fs.resolvePath(s.cwd,c);try{await s.fs.rm(d,{recursive:!1})}catch(h){let y=h instanceof Error?h.message:String(h);b+=`find: cannot delete '${c}': ${y}
|
|
8
|
+
`,T=1}}break}case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
9
|
+
`,exitCode:1};if(a.batchMode){let p=[];for(let h of a.command)h==="{}"?p.push(...m):p.push(h);let c=p.map(h=>`"${h}"`).join(" "),d=await s.exec(c,{cwd:s.cwd});x+=d.stdout,b+=d.stderr,d.exitCode!==0&&(T=d.exitCode)}else for(let p of m){let d=a.command.map(y=>y==="{}"?p:y).map(y=>`"${y}"`).join(" "),h=await s.exec(d,{cwd:s.cwd});x+=h.stdout,b+=h.stderr,h.exitCode!==0&&(T=h.exitCode)}break}else f&&(x=m.length>0?`${m.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:"");return{stdout:x,stderr:b,exitCode:T}}};export{K as findCommand};
|
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-WJV3FM6L.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-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]===`
|
|
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:`
|
package/dist/bundle/ai/index.js
CHANGED
|
@@ -293,7 +293,7 @@ Examples:
|
|
|
293
293
|
`,exitCode:1};let o=_i(a[0]),c=a.length>1?_i(a[1]):"",l=e.stdin,u=d=>{let h=o.includes(d);return n?!h:h},f="";if(s)for(let d of l)u(d)||(f+=d);else if(i&&a.length===1){let d="";for(let h of l)u(h)&&h===d||(f+=h,d=h)}else{if(n){let d=c.length>0?c[c.length-1]:"";for(let h of l)o.includes(h)?f+=h:f+=d}else{let d=new Map;for(let h=0;h<o.length;h++){let p=h<c.length?c[h]:c[c.length-1];d.set(o[h],p)}for(let h of l)f+=d.get(h)??h}if(i){let d="",h="";for(let p of f)c.includes(p)&&p===h||(d+=p,h=p);f=d}}return{stdout:f,stderr:"",exitCode:0}}}});var Hi={};O(Hi,{teeCommand:()=>zu});var Hu,Uu,zu,Ui=N(()=>{"use strict";ae();L();Hu={name:"tee",summary:"read from stdin and write to stdout and files",usage:"tee [OPTION]... [FILE]...",options:["-a, --append append to the given FILEs, do not overwrite"," --help display this help and exit"]},Uu={append:{short:"a",long:"append",type:"boolean"}},zu={name:"tee",async execute(t,e){if(C(t))return A(Hu);let r=H("tee",t,Uu);if(!r.ok)return r.error;let{append:n}=r.result.flags,s=r.result.positional,i=e.stdin,a="",o=0;for(let c of s)try{let l=e.fs.resolvePath(e.cwd,c);n?await e.fs.appendFile(l,i):await e.fs.writeFile(l,i)}catch{a+=`tee: ${c}: No such file or directory
|
|
294
294
|
`,o=1}return{stdout:i,stderr:a,exitCode:o}}}});function Je(t,e){switch(t.type){case"name":return{matches:be(e.name,t.pattern,t.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:be(e.relativePath,t.pattern,t.ignoreCase),pruned:!1,printed:!1};case"regex":try{let r=t.ignoreCase?"i":"";return{matches:new RegExp(t.pattern,r).test(e.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return t.fileType==="f"?{matches:e.isFile,pruned:!1,printed:!1}:t.fileType==="d"?{matches:e.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:e.isEmpty,pruned:!1,printed:!1};case"mtime":{let n=(Date.now()-e.mtime)/(1e3*60*60*24),s;return t.comparison==="more"?s=n>t.days:t.comparison==="less"?s=n<t.days:s=Math.floor(n)===t.days,{matches:s,pruned:!1,printed:!1}}case"newer":{let r=e.newerRefTimes.get(t.refPath);return r===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:e.mtime>r,pruned:!1,printed:!1}}case"size":{let r=t.value;switch(t.unit){case"c":r=t.value;break;case"k":r=t.value*1024;break;case"M":r=t.value*1024*1024;break;case"G":r=t.value*1024*1024*1024;break;case"b":r=t.value*512;break}let n;return t.comparison==="more"?n=e.size>r:t.comparison==="less"?n=e.size<r:t.unit==="b"?n=Math.ceil(e.size/512)===t.value:n=e.size===r,{matches:n,pruned:!1,printed:!1}}case"perm":{let r=e.mode&511,n=t.mode&511,s;return t.matchType==="exact"?s=r===n:t.matchType==="all"?s=(r&n)===n:s=(r&n)!==0,{matches:s,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 r=Je(t.expr,e);return{matches:!r.matches,pruned:r.pruned,printed:!1}}case"and":{let r=Je(t.left,e);if(!r.matches)return{matches:!1,pruned:r.pruned,printed:!1};let n=Je(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:r.printed||n.printed}}case"or":{let r=Je(t.left,e);if(r.matches)return r;let n=Je(t.right,e);return{matches:n.matches,pruned:r.pruned||n.pruned,printed:n.printed}}}}function zi(t){let e=[],r=n=>{n&&(n.type==="newer"?e.push(n.refPath):n.type==="not"?r(n.expr):(n.type==="and"||n.type==="or")&&(r(n.left),r(n.right)))};return r(t),e}var Gi=N(()=>{"use strict";Or()});function ji(t,e){let r=[],n=[],s=e;for(;s<t.length;){let a=t[s];if(a==="("||a==="\\("){r.push({type:"lparen"}),s++;continue}if(a===")"||a==="\\)"){r.push({type:"rparen"}),s++;continue}if(a==="-name"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s]}});else if(a==="-iname"&&s+1<t.length)r.push({type:"expr",expr:{type:"name",pattern:t[++s],ignoreCase:!0}});else if(a==="-path"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s]}});else if(a==="-ipath"&&s+1<t.length)r.push({type:"expr",expr:{type:"path",pattern:t[++s],ignoreCase:!0}});else if(a==="-regex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s]}});else if(a==="-iregex"&&s+1<t.length)r.push({type:"expr",expr:{type:"regex",pattern:t[++s],ignoreCase:!0}});else if(a==="-type"&&s+1<t.length){let o=t[++s];if(o==="f"||o==="d")r.push({type:"expr",expr:{type:"type",fileType:o}});else return{expr:null,pathIndex:s,error:`find: Unknown argument to -type: ${o}
|
|
295
295
|
`,actions:[]}}else if(a==="-empty")r.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&s+1<t.length){let o=t[++s],c="exact",l=o;o.startsWith("+")?(c="more",l=o.slice(1)):o.startsWith("-")&&(c="less",l=o.slice(1));let u=parseInt(l,10);Number.isNaN(u)||r.push({type:"expr",expr:{type:"mtime",days:u,comparison:c}})}else if(a==="-newer"&&s+1<t.length){let o=t[++s];r.push({type:"expr",expr:{type:"newer",refPath:o}})}else if(a==="-size"&&s+1<t.length){let o=t[++s],c="exact",l=o;o.startsWith("+")?(c="more",l=o.slice(1)):o.startsWith("-")&&(c="less",l=o.slice(1));let u=l.match(/^(\d+)([ckMGb])?$/);if(u){let f=parseInt(u[1],10),d=u[2]||"b";r.push({type:"expr",expr:{type:"size",value:f,unit:d,comparison:c}})}}else if(a==="-perm"&&s+1<t.length){let o=t[++s],c="exact",l=o;o.startsWith("-")?(c="all",l=o.slice(1)):o.startsWith("/")&&(c="any",l=o.slice(1));let u=parseInt(l,8);Number.isNaN(u)||r.push({type:"expr",expr:{type:"perm",mode:u,matchType:c}})}else if(a==="-prune")r.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")r.push({type:"not"});else if(a==="-o"||a==="-or")r.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")r.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")s++;else if(a==="-exec"){let o=[];for(s++;s<t.length&&t[s]!==";"&&t[s]!=="+";)o.push(t[s]),s++;if(s>=t.length)return{expr:null,pathIndex:s,error:"find: missing argument to `-exec'\n",actions:[]};let c=t[s]==="+";n.push({type:"exec",command:o,batchMode:c})}else if(a==="-print")r.push({type:"expr",expr:{type:"print"}}),n.push({type:"print"});else if(a==="-print0")n.push({type:"print0"});else if(a==="-delete")n.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:s,error:`find: unknown predicate '${a}'
|
|
296
|
-
`,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=Gu(r);return i.error?{expr:null,pathIndex:s,error:i.error,actions:n}:{expr:i.expr,pathIndex:s,actions:n}}function Gu(t){let e=0;function r(){let o=n();if(!o)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="or"){e++;let l=n();if(!l)return o;o={type:"or",left:o,right:l}}else break}return o}function n(){let o=s();if(!o)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="and"){e++;let l=s();if(!l)return o;o={type:"and",left:o,right:l}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let l=s();if(!l)return o;o={type:"and",left:o,right:l}}else break}return o}function s(){if(e<t.length&&t[e].type==="not"){e++;let o=s();return o?{type:"not",expr:o}:null}return i()}function i(){if(e>=t.length)return null;let o=t[e];if(o.type==="lparen"){e++;let c=r();return e<t.length&&t[e].type==="rparen"&&e++,c}return o.type==="expr"?(e++,o.expr):(o.type==="rparen",null)}return{expr:r()}}var qi=N(()=>{"use strict"});var Vi={};O(Vi,{findCommand:()=>Vu});var ju,qu,Vu,Zi=N(()=>{"use strict";L();Gi();qi();ju={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","-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"]},qu=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Vu={name:"find",async execute(t,e){if(C(t))return A(ju);let r=".",n=null,s=null;for(let E=0;E<t.length;E++){let x=t[E];if(x==="-maxdepth"&&E+1<t.length)n=parseInt(t[++E],10);else if(x==="-mindepth"&&E+1<t.length)s=parseInt(t[++E],10);else if(x==="-exec")for(E++;E<t.length&&t[E]!==";"&&t[E]!=="+";)E++;else!x.startsWith("-")&&x!==";"&&x!=="+"&&x!=="("&&x!==")"&&x!=="\\("&&x!=="\\)"?r=x:qu.has(x)&&E++}let{expr:i,error:a,actions:o}=ji(t,0);if(a)return{stdout:"",stderr:a,exitCode:1};let c=o.some(E=>E.type==="print"),l=o.length===0,u=e.fs.resolvePath(e.cwd,r);try{await e.fs.stat(u)}catch{return{stdout:"",stderr:`find: ${r}: No such file or directory
|
|
296
|
+
`,actions:[]};if(r.length===0){s++;continue}break}s++}if(r.length===0)return{expr:null,pathIndex:s,actions:n};let i=Gu(r);return i.error?{expr:null,pathIndex:s,error:i.error,actions:n}:{expr:i.expr,pathIndex:s,actions:n}}function Gu(t){let e=0;function r(){let o=n();if(!o)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="or"){e++;let l=n();if(!l)return o;o={type:"or",left:o,right:l}}else break}return o}function n(){let o=s();if(!o)return null;for(;e<t.length;){let c=t[e];if(c.type==="op"&&c.op==="and"){e++;let l=s();if(!l)return o;o={type:"and",left:o,right:l}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let l=s();if(!l)return o;o={type:"and",left:o,right:l}}else break}return o}function s(){if(e<t.length&&t[e].type==="not"){e++;let o=s();return o?{type:"not",expr:o}:null}return i()}function i(){if(e>=t.length)return null;let o=t[e];if(o.type==="lparen"){e++;let c=r();return e<t.length&&t[e].type==="rparen"&&e++,c}return o.type==="expr"?(e++,o.expr):(o.type==="rparen",null)}return{expr:r()}}var qi=N(()=>{"use strict"});var Vi={};O(Vi,{findCommand:()=>Vu});var ju,qu,Vu,Zi=N(()=>{"use strict";L();Gi();qi();ju={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","-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"]},qu=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Vu={name:"find",async execute(t,e){if(C(t))return A(ju);let r=".",n=null,s=null;for(let E=0;E<t.length;E++){let x=t[E];if(x==="-maxdepth"&&E+1<t.length)n=parseInt(t[++E],10);else if(x==="-mindepth"&&E+1<t.length)s=parseInt(t[++E],10);else if(x==="-exec")for(E++;E<t.length&&t[E]!==";"&&t[E]!=="+";)E++;else!x.startsWith("-")&&x!==";"&&x!=="+"&&x!=="("&&x!==")"&&x!=="\\("&&x!=="\\)"&&x!=="!"?r=x:qu.has(x)&&E++}let{expr:i,error:a,actions:o}=ji(t,0);if(a)return{stdout:"",stderr:a,exitCode:1};let c=o.some(E=>E.type==="print"),l=o.length===0,u=e.fs.resolvePath(e.cwd,r);try{await e.fs.stat(u)}catch{return{stdout:"",stderr:`find: ${r}: No such file or directory
|
|
297
297
|
`,exitCode:1}}let f=[],d=zi(i),h=new Map;for(let E of d){let x=e.fs.resolvePath(e.cwd,E);try{let S=await e.fs.stat(x);h.set(E,S.mtime?.getTime()??Date.now())}catch{}}async function p(E,x){if(n!==null&&x>n)return;let S;try{S=await e.fs.stat(E)}catch{return}if(!S)return;let v;E===u?v=r.split("/").pop()||r:v=E.split("/").pop()||"";let R=E===u?r:r==="."?`./${E.slice(u.length+1)}`:r+E.slice(u.length),M=null;S.isDirectory&&(M=await e.fs.readdir(E));let _=S.isFile?S.size===0:M!==null&&M.length===0,K=s===null||x>=s,Ee=!1,ne=!1;if(K&&i!==null){let de={name:v,relativePath:R,isFile:S.isFile,isDirectory:S.isDirectory,isEmpty:_,mtime:S.mtime?.getTime()??Date.now(),size:S.size??0,mode:S.mode??420,newerRefTimes:h},oe=Je(i,de);K=oe.matches,Ee=oe.pruned,c?ne=oe.printed:ne=K}else K&&(ne=!0);if(ne&&f.push(R),M!==null&&!Ee)for(let de of M){let oe=E==="/"?`/${de}`:`${E}/${de}`;await p(oe,x+1)}}await p(u,0);let b="",w="",g=0;if(o.length>0)for(let E of o)switch(E.type){case"print":b+=f.length>0?`${f.join(`
|
|
298
298
|
`)}
|
|
299
299
|
`:"";break;case"print0":b+=f.length>0?`${f.join("\0")}\0`:"";break;case"delete":{let x=[...f].sort((S,v)=>v.length-S.length);for(let S of x){let v=e.fs.resolvePath(e.cwd,S);try{await e.fs.rm(v,{recursive:!1})}catch(R){let M=R instanceof Error?R.message:String(R);w+=`find: cannot delete '${S}': ${M}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as N}from"./chunk-UJMN5NLH.js";import{a as A,b as z}from"./chunk-74CEPOFO.js";function g(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 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 I(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 $(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}
|
|
2
|
+
`,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 u=parseInt(f,10);Number.isNaN(u)||t.push({type:"expr",expr:{type:"mtime",days:u,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 u=f.match(/^(\d+)([ckMGb])?$/);if(u){let m=parseInt(u[1],10),v=u[2]||"b";t.push({type:"expr",expr:{type:"size",value:m,unit:v,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 u=parseInt(f,8);Number.isNaN(u)||t.push({type:"expr",expr:{type:"perm",mode:u,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==="-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}'
|
|
3
|
+
`,actions:[]};if(t.length===0){n++;continue}break}n++}if(t.length===0)return{expr:null,pathIndex:n,actions:r};let w=S(t);return w.error?{expr:null,pathIndex:n,error:w.error,actions:r}:{expr:w.expr,pathIndex:n,actions:r}}function S(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 F={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","-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"]},L=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),K={name:"find",async execute(e,s){if(z(e))return A(F);let t=".",r=null,n=null;for(let a=0;a<e.length;a++){let p=e[a];if(p==="-maxdepth"&&a+1<e.length)r=parseInt(e[++a],10);else if(p==="-mindepth"&&a+1<e.length)n=parseInt(e[++a],10);else if(p==="-exec")for(a++;a<e.length&&e[a]!==";"&&e[a]!=="+";)a++;else!p.startsWith("-")&&p!==";"&&p!=="+"&&p!=="("&&p!==")"&&p!=="\\("&&p!=="\\)"&&p!=="!"?t=p:L.has(p)&&a++}let{expr:w,error:l,actions:i}=$(e,0);if(l)return{stdout:"",stderr:l,exitCode:1};let o=i.some(a=>a.type==="print"),f=i.length===0,u=s.fs.resolvePath(s.cwd,t);try{await s.fs.stat(u)}catch{return{stdout:"",stderr:`find: ${t}: No such file or directory
|
|
4
|
+
`,exitCode:1}}let m=[],v=I(w),C=new Map;for(let a of v){let p=s.fs.resolvePath(s.cwd,a);try{let c=await s.fs.stat(p);C.set(a,c.mtime?.getTime()??Date.now())}catch{}}async function R(a,p){if(r!==null&&p>r)return;let c;try{c=await s.fs.stat(a)}catch{return}if(!c)return;let d;a===u?d=t.split("/").pop()||t:d=a.split("/").pop()||"";let h=a===u?t:t==="."?`./${a.slice(u.length+1)}`:t+a.slice(u.length),y=null;c.isDirectory&&(y=await s.fs.readdir(a));let W=c.isFile?c.size===0:y!==null&&y.length===0,P=n===null||p>=n,k=!1,D=!1;if(P&&w!==null){let M={name:d,relativePath:h,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:W,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C},E=g(w,M);P=E.matches,k=E.pruned,o?D=E.printed:D=P}else P&&(D=!0);if(D&&m.push(h),y!==null&&!k)for(let M of y){let E=a==="/"?`/${M}`:`${a}/${M}`;await R(E,p+1)}}await R(u,0);let x="",b="",T=0;if(i.length>0)for(let a of i)switch(a.type){case"print":x+=m.length>0?`${m.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"";break;case"print0":x+=m.length>0?`${m.join("\0")}\0`:"";break;case"delete":{let p=[...m].sort((c,d)=>d.length-c.length);for(let c of p){let d=s.fs.resolvePath(s.cwd,c);try{await s.fs.rm(d,{recursive:!1})}catch(h){let y=h instanceof Error?h.message:String(h);b+=`find: cannot delete '${c}': ${y}
|
|
7
|
+
`,T=1}}break}case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
8
|
+
`,exitCode:1};if(a.batchMode){let p=[];for(let h of a.command)h==="{}"?p.push(...m):p.push(h);let c=p.map(h=>`"${h}"`).join(" "),d=await s.exec(c,{cwd:s.cwd});x+=d.stdout,b+=d.stderr,d.exitCode!==0&&(T=d.exitCode)}else for(let p of m){let d=a.command.map(y=>y==="{}"?p:y).map(y=>`"${y}"`).join(" "),h=await s.exec(d,{cwd:s.cwd});x+=h.stdout,b+=h.stderr,h.exitCode!==0&&(T=h.exitCode)}break}else f&&(x=m.length>0?`${m.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`:"");return{stdout:x,stderr:b,exitCode:T}}};export{K as findCommand};
|
package/dist/bundle/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as U,b as X,c as V,d as te,e as Y,f as k,g as F,h as Ee,i as z,j as fe,k as Ve}from"./chunks/chunk-CG2HXOFG.js";import{a as le}from"./chunks/chunk-44UOCSGV.js";var At=[{name:"echo",load:async()=>(await import("./chunks/echo-W2TA2N7Y.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-5KESXK2M.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-3ZT5XOIZ.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-B7C35UDO.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-WYI2LJ6H.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-Z5XRYFYY.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5X2XSQQ6.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-BLHAPLQZ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-GN23UIZU.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-UTUVIAFP.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-VLKWIL3N.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-ZVX5RTL4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HHC33N5C.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-7H5R4WKO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-BLGGG2VX.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-OXLYBRUE.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-TM5F5YO4.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGVS3UIY.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-4YCQ6UCB.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-LHMQWYH2.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IIOQKNTS.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-7RHEYJ7Y.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-L4TYPVSP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-UV4V27RJ.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-VCNOG5VI.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-K7D4PKHS.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SB5JXIY3.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Q5HDZLH2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-75UXQ4XJ.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-I5HYAKTQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2F2VHNYS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2F2VHNYS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-7Z2STZ6Y.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-752VENJT.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-ZBD2DMXN.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-5WG5RD6L.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-5WG5RD6L.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-7R2XGLLH.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-WATI5PWI.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-IVJFQANX.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YOOSNZVA.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-QJBQD6VS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VG2N46UR.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-TFPZQZPJ.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-A4LJAGVP.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XMBYO6FD.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-XHGUXTV3.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-ONWH3TNF.js")).whichCommand}],yr=[{name:"curl",load:async()=>(await import("./chunks/curl-PA2MWGKN.js")).curlCommand}],pr=new Map;function Er(t){return{name:t.name,async execute(e,s){let r=pr.get(t.name);return r||(r=await t.load(),pr.set(t.name,r)),r.execute(e,s)}}}function Ts(){return At.map(t=>t.name)}function Ws(){return yr.map(t=>t.name)}function wr(t){return(t?At.filter(s=>t.includes(s.name)):At).map(Er)}function gr(){return yr.map(Er)}function Ar(t){return"load"in t&&typeof t.load=="function"}function Fs(t,e){return{name:t,execute:e}}function xr(t){let e=null;return{name:t.name,async execute(s,r){return e||(e=await t.load()),e.execute(s,r)}}}var Ms=new TextEncoder,Bs=new TextDecoder;function re(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),s=>s.charCodeAt(0));case"hex":{let s=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)s[r/2]=parseInt(t.slice(r,r+2),16);return s}case"binary":case"latin1":return Uint8Array.from(t,s=>s.charCodeAt(0));default:return Ms.encode(t)}}function Se(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Bs.decode(t)}}function Z(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Ge=new TextEncoder;function zs(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var se=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[s,r]of Object.entries(e))zs(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(o=>o&&o!=="."),n=[];for(let o of r)o===".."?n.pop():n.push(o);return`/${n.join("/")}`||"/"}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,s,r,n){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=Z(r),a=re(s,i);this.data.set(o,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}async readFile(e,s){let r=await this.readFileBuffer(e),n=Z(s);return Se(r,n)}async readFileBuffer(e){let s=this.normalizePath(e),r=this.data.get(s),n=s;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(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}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:Ge.encode(r.content)}async writeFile(e,s,r){this.writeFileSync(e,s,r)}async appendFile(e,s,r){let n=this.normalizePath(e),o=this.data.get(n);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=Z(r),a=re(s,i);if(o?.type==="file"){let l=o.content instanceof Uint8Array?o.content:Ge.encode(o.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,s,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(s,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ge.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(e){let s=this.normalizePath(e),r=this.data.get(s);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 n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ge.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}async mkdir(e,s){this.mkdirSync(e,s)}mkdirSync(e,s){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(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let n=this.dirname(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{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 s=this.normalizePath(e),r=this.data.get(s);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 n=s==="/"?"/":`${s}/`,o=[];for(let i of this.data.keys())if(i!==s&&i.startsWith(n)){let l=i.slice(n.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(n.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!s?.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,s)}}}this.data.delete(r)}async cp(e,s,r){let n=this.normalizePath(e),o=this.normalizePath(s),i=this.data.get(n);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(n);for(let l of a){let c=n==="/"?`/${l}`:`${n}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,s){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}async chmod(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);n.mode=s}async symlink(e,s){let r=this.normalizePath(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,s){let r=this.normalizePath(e),n=this.normalizePath(s),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(n))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let s=this.normalizePath(e),r=this.data.get(s);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 T(t,e){return{type:"ArithmeticExpression",expression:ne(t,e,0).expr}}function ne(t,e,s){return Us(t,e,s)}function Us(t,e,s){let{expr:r,pos:n}=je(t,e,s);for(n=O(e,n);e[n]===",";){n++;let{expr:o,pos:i}=je(t,e,n);r={type:"ArithBinary",operator:",",left:r,right:o},n=O(e,i)}return{expr:r,pos:n}}function je(t,e,s){let{expr:r,pos:n}=Vs(t,e,s);if(n=O(e,n),e[n]==="?"){n++;let{expr:o,pos:i}=ne(t,e,n);if(n=O(e,i),e[n]===":"){n++;let{expr:a,pos:l}=ne(t,e,n);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:n}}function Vs(t,e,s){let{expr:r,pos:n}=Sr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="||";){n+=2;let{expr:o,pos:i}=Sr(t,e,n);r={type:"ArithBinary",operator:"||",left:r,right:o},n=i}return{expr:r,pos:n}}function Sr(t,e,s){let{expr:r,pos:n}=br(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="&&";){n+=2;let{expr:o,pos:i}=br(t,e,n);r={type:"ArithBinary",operator:"&&",left:r,right:o},n=i}return{expr:r,pos:n}}function br(t,e,s){let{expr:r,pos:n}=Nr(t,e,s);for(;n=O(e,n),e[n]==="|"&&e[n+1]!=="|";){n++;let{expr:o,pos:i}=Nr(t,e,n);r={type:"ArithBinary",operator:"|",left:r,right:o},n=i}return{expr:r,pos:n}}function Nr(t,e,s){let{expr:r,pos:n}=Cr(t,e,s);for(;n=O(e,n),e[n]==="^";){n++;let{expr:o,pos:i}=Cr(t,e,n);r={type:"ArithBinary",operator:"^",left:r,right:o},n=i}return{expr:r,pos:n}}function Cr(t,e,s){let{expr:r,pos:n}=$r(t,e,s);for(;n=O(e,n),e[n]==="&"&&e[n+1]!=="&";){n++;let{expr:o,pos:i}=$r(t,e,n);r={type:"ArithBinary",operator:"&",left:r,right:o},n=i}return{expr:r,pos:n}}function $r(t,e,s){let{expr:r,pos:n}=Pr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="=="||e.slice(n,n+2)==="!=";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=Pr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Pr(t,e,s){let{expr:r,pos:n}=xt(t,e,s);for(;;)if(n=O(e,n),e.slice(n,n+2)==="<="||e.slice(n,n+2)===">="){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=xt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else if(e[n]==="<"||e[n]===">"){let o=e[n];n++;let{expr:i,pos:a}=xt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function xt(t,e,s){let{expr:r,pos:n}=vr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="<<"||e.slice(n,n+2)===">>";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=vr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function vr(t,e,s){let{expr:r,pos:n}=Ir(t,e,s);for(;n=O(e,n),(e[n]==="+"||e[n]==="-")&&e[n+1]!==e[n];){let o=e[n];n++;let{expr:i,pos:a}=Ir(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Ir(t,e,s){let{expr:r,pos:n}=He(t,e,s);for(;;)if(n=O(e,n),e[n]==="*"&&e[n+1]!=="*"){n++;let{expr:o,pos:i}=He(t,e,n);r={type:"ArithBinary",operator:"*",left:r,right:o},n=i}else if(e[n]==="/"||e[n]==="%"){let o=e[n];n++;let{expr:i,pos:a}=He(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function He(t,e,s){let{expr:r,pos:n}=St(t,e,s),o=O(e,n);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=He(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:n}}function St(t,e,s){let r=O(e,s);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let n=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let n=e[r];r++;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}return Hs(t,e,r)}function Gs(t,e){let s=t[e];return s==="$"||s==="`"}function Hs(t,e,s){let{expr:r,pos:n}=Rr(t,e,s),o=[r];for(;Gs(e,n);){let{expr:i,pos:a}=Rr(t,e,n);o.push(i),n=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),n=O(e,n),e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let i=e.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Rr(t,e,s){let r=O(e,s);if(e.slice(r,r+3)==="$(("){r+=3;let n=1,o=r;for(;r<e.length-1&&n>0;)e[r]==="("&&e[r+1]==="("?(n++,r+=2):e[r]===")"&&e[r+1]===")"?(n--,n>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=ne(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 n=1,o=r;for(;r<e.length&&n>0;)e[r]==="("?n++:e[r]===")"&&n--,n>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let n=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(n,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:n,pos:o}=ne(t,e,r);return r=O(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:n},pos:r}}if(/[0-9]/.test(e[r])){let n="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))n+=a,r++;else break;else if(a==="#")o=!0,n+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))n+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${n}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:n,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:be(n)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let n=r+2,o=1,i=n;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(n,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 n="";for(;r<e.length&&/[0-9]/.test(e[r]);)n+=e[r],r++;return{expr:{type:"ArithVariable",name:n},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=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=O(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:c,pos:f}=ne(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=O(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:n,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}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:c,variable:n,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:n,index:a,stringKey:i},pos:r}}r=O(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}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:n,value:a},pos:l}}return{expr:{type:"ArithVariable",name:n},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function be(t){if(t.includes("#")){let[e,s]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(s,r);let n=0;for(let o of s){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;n=n*r+i}return n}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 O(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
1
|
+
import{a as U,b as X,c as V,d as te,e as Y,f as k,g as F,h as Ee,i as z,j as fe,k as Ve}from"./chunks/chunk-CG2HXOFG.js";import{a as le}from"./chunks/chunk-44UOCSGV.js";var At=[{name:"echo",load:async()=>(await import("./chunks/echo-W2TA2N7Y.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-5KESXK2M.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-3ZT5XOIZ.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-B7C35UDO.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-WYI2LJ6H.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-Z5XRYFYY.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5X2XSQQ6.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-BLHAPLQZ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-GN23UIZU.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-UTUVIAFP.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-VLKWIL3N.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-ZVX5RTL4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HHC33N5C.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-7H5R4WKO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-BLGGG2VX.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-OXLYBRUE.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-TM5F5YO4.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGVS3UIY.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-4YCQ6UCB.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-LHMQWYH2.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IIOQKNTS.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-7RHEYJ7Y.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-L4TYPVSP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-UV4V27RJ.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-VCNOG5VI.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-4QUN2ATO.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SB5JXIY3.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Q5HDZLH2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-75UXQ4XJ.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-I5HYAKTQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2F2VHNYS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2F2VHNYS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-7Z2STZ6Y.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-752VENJT.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-ZBD2DMXN.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-5WG5RD6L.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-5WG5RD6L.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-7R2XGLLH.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-WATI5PWI.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-IVJFQANX.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YOOSNZVA.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-QJBQD6VS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VG2N46UR.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-TFPZQZPJ.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-A4LJAGVP.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XMBYO6FD.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-XHGUXTV3.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-ONWH3TNF.js")).whichCommand}],yr=[{name:"curl",load:async()=>(await import("./chunks/curl-PA2MWGKN.js")).curlCommand}],pr=new Map;function Er(t){return{name:t.name,async execute(e,s){let r=pr.get(t.name);return r||(r=await t.load(),pr.set(t.name,r)),r.execute(e,s)}}}function Ts(){return At.map(t=>t.name)}function Ws(){return yr.map(t=>t.name)}function wr(t){return(t?At.filter(s=>t.includes(s.name)):At).map(Er)}function gr(){return yr.map(Er)}function Ar(t){return"load"in t&&typeof t.load=="function"}function Fs(t,e){return{name:t,execute:e}}function xr(t){let e=null;return{name:t.name,async execute(s,r){return e||(e=await t.load()),e.execute(s,r)}}}var Ms=new TextEncoder,Bs=new TextDecoder;function re(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),s=>s.charCodeAt(0));case"hex":{let s=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)s[r/2]=parseInt(t.slice(r,r+2),16);return s}case"binary":case"latin1":return Uint8Array.from(t,s=>s.charCodeAt(0));default:return Ms.encode(t)}}function Se(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Bs.decode(t)}}function Z(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Ge=new TextEncoder;function zs(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var se=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[s,r]of Object.entries(e))zs(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(o=>o&&o!=="."),n=[];for(let o of r)o===".."?n.pop():n.push(o);return`/${n.join("/")}`||"/"}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,s,r,n){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=Z(r),a=re(s,i);this.data.set(o,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}async readFile(e,s){let r=await this.readFileBuffer(e),n=Z(s);return Se(r,n)}async readFileBuffer(e){let s=this.normalizePath(e),r=this.data.get(s),n=s;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(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}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:Ge.encode(r.content)}async writeFile(e,s,r){this.writeFileSync(e,s,r)}async appendFile(e,s,r){let n=this.normalizePath(e),o=this.data.get(n);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=Z(r),a=re(s,i);if(o?.type==="file"){let l=o.content instanceof Uint8Array?o.content:Ge.encode(o.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,s,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(s,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ge.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(e){let s=this.normalizePath(e),r=this.data.get(s);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 n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ge.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}async mkdir(e,s){this.mkdirSync(e,s)}mkdirSync(e,s){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(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let n=this.dirname(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{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 s=this.normalizePath(e),r=this.data.get(s);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 n=s==="/"?"/":`${s}/`,o=[];for(let i of this.data.keys())if(i!==s&&i.startsWith(n)){let l=i.slice(n.length).split("/")[0];l&&!o.includes(l)&&o.push(l)}return o.sort()}async rm(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(n.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!s?.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,s)}}}this.data.delete(r)}async cp(e,s,r){let n=this.normalizePath(e),o=this.normalizePath(s),i=this.data.get(n);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(n);for(let l of a){let c=n==="/"?`/${l}`:`${n}/${l}`,f=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(c,f,r)}}}async mv(e,s){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}async chmod(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);n.mode=s}async symlink(e,s){let r=this.normalizePath(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,s){let r=this.normalizePath(e),n=this.normalizePath(s),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(n))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let s=this.normalizePath(e),r=this.data.get(s);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 T(t,e){return{type:"ArithmeticExpression",expression:ne(t,e,0).expr}}function ne(t,e,s){return Us(t,e,s)}function Us(t,e,s){let{expr:r,pos:n}=je(t,e,s);for(n=O(e,n);e[n]===",";){n++;let{expr:o,pos:i}=je(t,e,n);r={type:"ArithBinary",operator:",",left:r,right:o},n=O(e,i)}return{expr:r,pos:n}}function je(t,e,s){let{expr:r,pos:n}=Vs(t,e,s);if(n=O(e,n),e[n]==="?"){n++;let{expr:o,pos:i}=ne(t,e,n);if(n=O(e,i),e[n]===":"){n++;let{expr:a,pos:l}=ne(t,e,n);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:l}}}return{expr:r,pos:n}}function Vs(t,e,s){let{expr:r,pos:n}=Sr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="||";){n+=2;let{expr:o,pos:i}=Sr(t,e,n);r={type:"ArithBinary",operator:"||",left:r,right:o},n=i}return{expr:r,pos:n}}function Sr(t,e,s){let{expr:r,pos:n}=br(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="&&";){n+=2;let{expr:o,pos:i}=br(t,e,n);r={type:"ArithBinary",operator:"&&",left:r,right:o},n=i}return{expr:r,pos:n}}function br(t,e,s){let{expr:r,pos:n}=Nr(t,e,s);for(;n=O(e,n),e[n]==="|"&&e[n+1]!=="|";){n++;let{expr:o,pos:i}=Nr(t,e,n);r={type:"ArithBinary",operator:"|",left:r,right:o},n=i}return{expr:r,pos:n}}function Nr(t,e,s){let{expr:r,pos:n}=Cr(t,e,s);for(;n=O(e,n),e[n]==="^";){n++;let{expr:o,pos:i}=Cr(t,e,n);r={type:"ArithBinary",operator:"^",left:r,right:o},n=i}return{expr:r,pos:n}}function Cr(t,e,s){let{expr:r,pos:n}=$r(t,e,s);for(;n=O(e,n),e[n]==="&"&&e[n+1]!=="&";){n++;let{expr:o,pos:i}=$r(t,e,n);r={type:"ArithBinary",operator:"&",left:r,right:o},n=i}return{expr:r,pos:n}}function $r(t,e,s){let{expr:r,pos:n}=Pr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="=="||e.slice(n,n+2)==="!=";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=Pr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Pr(t,e,s){let{expr:r,pos:n}=xt(t,e,s);for(;;)if(n=O(e,n),e.slice(n,n+2)==="<="||e.slice(n,n+2)===">="){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=xt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else if(e[n]==="<"||e[n]===">"){let o=e[n];n++;let{expr:i,pos:a}=xt(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function xt(t,e,s){let{expr:r,pos:n}=vr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="<<"||e.slice(n,n+2)===">>";){let o=e.slice(n,n+2);n+=2;let{expr:i,pos:a}=vr(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function vr(t,e,s){let{expr:r,pos:n}=Ir(t,e,s);for(;n=O(e,n),(e[n]==="+"||e[n]==="-")&&e[n+1]!==e[n];){let o=e[n];n++;let{expr:i,pos:a}=Ir(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}return{expr:r,pos:n}}function Ir(t,e,s){let{expr:r,pos:n}=He(t,e,s);for(;;)if(n=O(e,n),e[n]==="*"&&e[n+1]!=="*"){n++;let{expr:o,pos:i}=He(t,e,n);r={type:"ArithBinary",operator:"*",left:r,right:o},n=i}else if(e[n]==="/"||e[n]==="%"){let o=e[n];n++;let{expr:i,pos:a}=He(t,e,n);r={type:"ArithBinary",operator:o,left:r,right:i},n=a}else break;return{expr:r,pos:n}}function He(t,e,s){let{expr:r,pos:n}=St(t,e,s),o=O(e,n);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=He(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:n}}function St(t,e,s){let r=O(e,s);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let n=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let n=e[r];r++;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:o,prefix:!0},pos:i}}return Hs(t,e,r)}function Gs(t,e){let s=t[e];return s==="$"||s==="`"}function Hs(t,e,s){let{expr:r,pos:n}=Rr(t,e,s),o=[r];for(;Gs(e,n);){let{expr:i,pos:a}=Rr(t,e,n);o.push(i),n=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),n=O(e,n),e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let i=e.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Rr(t,e,s){let r=O(e,s);if(e.slice(r,r+3)==="$(("){r+=3;let n=1,o=r;for(;r<e.length-1&&n>0;)e[r]==="("&&e[r+1]==="("?(n++,r+=2):e[r]===")"&&e[r+1]===")"?(n--,n>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=ne(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 n=1,o=r;for(;r<e.length&&n>0;)e[r]==="("?n++:e[r]===")"&&n--,n>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let n=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(n,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:n,pos:o}=ne(t,e,r);return r=O(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:n},pos:r}}if(/[0-9]/.test(e[r])){let n="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))n+=a,r++;else break;else if(a==="#")o=!0,n+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))n+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${n}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:n,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:be(n)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let n=r+2,o=1,i=n;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(n,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 n="";for(;r<e.length&&/[0-9]/.test(e[r]);)n+=e[r],r++;return{expr:{type:"ArithVariable",name:n},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=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=O(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:c,pos:f}=ne(t,e,r);a=c,r=f,e[r]==="]"&&r++}if(r=O(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:n,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}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:c,variable:n,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:n,index:a,stringKey:i},pos:r}}r=O(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}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:n,value:a},pos:l}}return{expr:{type:"ArithVariable",name:n},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function be(t){if(t.includes("#")){let[e,s]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(s,r);let n=0;for(let o of s){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;n=n*r+i}return n}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 O(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
2
2
|
`){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=[],s=!1){return{type:"Statement",pipelines:t,operators:e,background:s}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],s=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:s,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,s=!1,r=null){return{type:"Assignment",name:t,value:e,append:s,array:r}},redirection(t,e,s=null){return{type:"Redirection",fd:s,operator:t,target:e}},hereDoc(t,e,s=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:s,quoted:r}},ifNode(t,e=null,s=[]){return{type:"If",clauses:t,elseBody:e,redirections:s}},forNode(t,e,s,r=[]){return{type:"For",variable:t,words:e,body:s,redirections:r}},whileNode(t,e,s=[]){return{type:"While",condition:t,body:e,redirections:s}},untilNode(t,e,s=[]){return{type:"Until",condition:t,body:e,redirections:s}},caseNode(t,e,s=[]){return{type:"Case",word:t,items:e,redirections:s}},caseItem(t,e,s=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:s}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,s=[]){return{type:"FunctionDef",name:t,body:e,redirections:s}},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 Ze={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 Dr(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let s=t.slice(e[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n<s.length;n++)if(s[n]==="[")r++;else if(s[n]==="]"&&(r--,r===0))break;if(r!==0||n>=s.length)return!1;let o=s.slice(n+1);return o===""||o==="+"}return!1}var js=[[";",";","&",u.SEMI_SEMI_AND],["<","<","<",u.TLESS],["&",">",">",u.AND_DGREAT]],Zs=[["[","[",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]],qs={"|":u.PIPE,"&":u.AMP,";":u.SEMICOLON,"(":u.LPAREN,")":u.RPAREN,"<":u.LESS,">":u.GREAT};function Qs(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var qe=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos<s&&(this.skipWhitespace(),!(this.pos>=s));){if(n.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,s=e.length,r=this.pos,n=this.column,o=this.line;for(;r<s;){let i=e[r];if(i===" "||i===" ")r++,n++;else if(i==="\\"&&e[r+1]===`
|
|
3
3
|
`)r+=2,o++,n=1;else break}this.pos=r,this.column=n,this.line=o}nextToken(){let e=this.input,s=this.pos,r=this.line,n=this.column,o=e[s],i=e[s+1],a=e[s+2];if(o==="#")return this.readComment(s,r,n);if(o===`
|
|
4
4
|
`)return this.pos=s+1,this.line++,this.column=1,{type:u.NEWLINE,value:`
|