just-bash 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-6QUZ7QML.js +3 -0
- package/dist/bin/chunks/find-AMA6ABN5.js +11 -0
- package/dist/bin/chunks/find-HW2TUO6B.js +11 -0
- package/dist/bin/chunks/find-NCI6KGUI.js +11 -0
- package/dist/bin/chunks/find-QEYP42JQ.js +11 -0
- package/dist/bin/chunks/printf-ASOYDPIK.js +14 -0
- package/dist/bin/just-bash.js +1 -1
- package/dist/bin/shell/chunks/chunk-6QUZ7QML.js +3 -0
- package/dist/bin/shell/chunks/find-AMA6ABN5.js +11 -0
- package/dist/bin/shell/chunks/find-HW2TUO6B.js +11 -0
- package/dist/bin/shell/chunks/find-NCI6KGUI.js +11 -0
- package/dist/bin/shell/chunks/find-QEYP42JQ.js +11 -0
- package/dist/bin/shell/chunks/printf-ASOYDPIK.js +14 -0
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/ai/index.js +286 -286
- package/dist/bundle/chunks/chunk-TDJNT32M.js +2 -0
- package/dist/bundle/chunks/find-3O5V74IR.js +10 -0
- package/dist/bundle/chunks/find-4QUN2ATO.js +10 -0
- package/dist/bundle/chunks/find-522XP4ZY.js +10 -0
- package/dist/bundle/chunks/find-JXG2HF6L.js +10 -0
- package/dist/bundle/chunks/printf-G2SBUNW3.js +13 -0
- package/dist/bundle/index.js +1 -1
- package/dist/commands/find/types.d.ts +5 -0
- package/dist/commands/printf/escapes.d.ts +24 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function c(t,a,e){let l=t;e>=0&&l.length>e&&(l=l.slice(0,e));let s=Math.abs(a);return s>l.length&&(a<0?l=l.padEnd(s," "):l=l.padStart(s," ")),l}function i(t,a){let e=a,l=0,s=-1,n=!1;for(e<t.length&&t[e]==="-"&&(n=!0,e++);e<t.length&&/\d/.test(t[e]);)l=l*10+parseInt(t[e],10),e++;if(e<t.length&&t[e]===".")for(e++,s=0;e<t.length&&/\d/.test(t[e]);)s=s*10+parseInt(t[e],10),e++;return n&&l>0&&(l=-l),[l,s,e-a]}function h(t){let a="",e=0;for(;e<t.length;)if(t[e]==="\\"&&e+1<t.length)switch(t[e+1]){case"n":a+=`
|
|
2
|
+
`,e+=2;break;case"t":a+=" ",e+=2;break;case"r":a+="\r",e+=2;break;case"\\":a+="\\",e+=2;break;case"a":a+="\x07",e+=2;break;case"b":a+="\b",e+=2;break;case"f":a+="\f",e+=2;break;case"v":a+="\v",e+=2;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let s="",n=e+1;for(;n<t.length&&n<e+4&&/[0-7]/.test(t[n]);)s+=t[n],n++;a+=String.fromCharCode(parseInt(s,8)),e=n;break}case"x":e+3<t.length&&/[0-9a-fA-F]{2}/.test(t.slice(e+2,e+4))?(a+=String.fromCharCode(parseInt(t.slice(e+2,e+4),16)),e+=4):(a+=t[e],e++);break;default:a+=t[e],e++}else a+=t[e],e++;return a}export{c as a,i as b,h as c};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as N}from"./chunk-UJMN5NLH.js";import{a as L,b as B,c as H}from"./chunk-TDJNT32M.js";import{a as I,b as O}from"./chunk-74CEPOFO.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=r>e.days:e.comparison==="less"?t=r<e.days:t=Math.floor(r)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let r;return e.comparison==="more"?r=s.size>n:e.comparison==="less"?r=s.size<n:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,r=e.mode&511,t;return e.matchType==="exact"?t=n===r:e.matchType==="all"?t=(n&r)===r:t=(n&r)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function G(e){let s=[],n=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(e),s}function j(e,s){let n=[],r=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let i=e[++t];if(i==="f"||i==="d")n.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${i}
|
|
2
|
+
`,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let i=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(a==="-size"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("-")?(c="all",o=i.slice(1)):i.startsWith("/")&&(c="any",o=i.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let i=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)i.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";r.push({type:"exec",command:i,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(a==="-print0")r.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let i=e[++t];r.push({type:"printf",format:i})}else if(a==="-delete")r.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
|
|
3
|
+
`,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:r};let m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:r}:{expr:m.expr,pathIndex:t,actions:r}}function _(e){let s=0;function n(){let i=r();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let o=r();if(!o)return i;i={type:"or",left:i,right:o}}else break}return i}function r(){let i=t();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else break}return i}function t(){if(s<e.length&&e[s].type==="not"){s++;let i=t();return i?{type:"not",expr:i}:null}return m()}function m(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:n()}}var K={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],r=null,t=null,m=!1,a=!1;for(let p=0;p<e.length;p++){let l=e[p];if(l==="-maxdepth"&&p+1<e.length)a=!0,r=parseInt(e[++p],10);else if(l==="-mindepth"&&p+1<e.length)a=!0,t=parseInt(e[++p],10);else if(l==="-depth")a=!0,m=!0;else if(l==="-exec")for(a=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):U.has(l)?(a=!0,p++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(p=>p.type==="print"),b=o.length===0,y=[],Y=o.some(p=>p.type==="printf"),F=[],T="",D=0,V=G(i),k=new Map;for(let p of V){let l=s.fs.resolvePath(s.cwd,p);try{let g=await s.fs.stat(l);k.set(p,g.mtime?.getTime()??Date.now())}catch{}}for(let p of n){let l=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(l)}catch{T+=`find: ${p}: No such file or directory
|
|
4
|
+
`,D=1;continue}async function g(u,d){if(r!==null&&d>r)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===l?E=p.split("/").pop()||p:E=u.split("/").pop()||"";let v=u===l?p:p==="."?`./${u.slice(l.length+1)}`:p+u.slice(l.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,$=!1;if(x&&i!==null){let J={name:E,relativePath:v,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},W=w(i,J);x=W.matches,h?$=W.printed:$=x}else x&&($=!0);$&&(y.push(v),Y&&F.push({path:v,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:p}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},z=!1;if(!m&&i!==null){let P={name:E,relativePath:v,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};z=w(i,P).pruned}m?(await A(),C()):(C(),z||await A())}await g(l,0)}let S="";if(o.length>0)for(let p of o)switch(p.type){case"print":S+=y.length>0?`${y.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let l=[...y].sort((g,u)=>u.length-g.length);for(let g of l){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
|
|
7
|
+
`,D=1}}break}case"printf":for(let l of F)S+=q(p.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
8
|
+
`,exitCode:1};if(p.batchMode){let l=[];for(let d of p.command)d==="{}"?l.push(...y):l.push(d);let g=l.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let l of y){let u=p.command.map(f=>f==="{}"?l:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[m,a,i]=B(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:r+="%"+(m!==0||a!==-1?`${m}.${a}`:"")+c,t++;continue}r+=L(o,m,a)}else r+=n[t],t++;return r}function Q(e,s){let n=e&511,r=s?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function X(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=s[e.getDay()],t=n[e.getMonth()],m=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),o=e.getFullYear();return`${r} ${t} ${m} ${a}:${i}:${c} ${o}`}function Z(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{oe as findCommand};
|
|
@@ -0,0 +1,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};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as N}from"./chunk-UJMN5NLH.js";import{a as L,b as B,c as H}from"./chunk-TDJNT32M.js";import{a as I,b as O}from"./chunk-74CEPOFO.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=r>e.days:e.comparison==="less"?t=r<e.days:t=Math.floor(r)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let r;return e.comparison==="more"?r=s.size>n:e.comparison==="less"?r=s.size<n:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,r=e.mode&511,t;return e.matchType==="exact"?t=n===r:e.matchType==="all"?t=(n&r)===r:t=(n&r)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function G(e){let s=[],n=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(e),s}function j(e,s){let n=[],r=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let i=e[++t];if(i==="f"||i==="d")n.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${i}
|
|
2
|
+
`,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let i=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(a==="-size"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("-")?(c="all",o=i.slice(1)):i.startsWith("/")&&(c="any",o=i.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let i=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)i.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";r.push({type:"exec",command:i,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(a==="-print0")r.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let i=e[++t];r.push({type:"printf",format:i})}else if(a==="-delete")r.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
|
|
3
|
+
`,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:r};let m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:r}:{expr:m.expr,pathIndex:t,actions:r}}function _(e){let s=0;function n(){let i=r();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let o=r();if(!o)return i;i={type:"or",left:i,right:o}}else break}return i}function r(){let i=t();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else break}return i}function t(){if(s<e.length&&e[s].type==="not"){s++;let i=t();return i?{type:"not",expr:i}:null}return m()}function m(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:n()}}var K={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],r=null,t=null,m=!1,a=!1;for(let p=0;p<e.length;p++){let l=e[p];if(l==="-maxdepth"&&p+1<e.length)a=!0,r=parseInt(e[++p],10);else if(l==="-mindepth"&&p+1<e.length)a=!0,t=parseInt(e[++p],10);else if(l==="-depth")a=!0,m=!0;else if(l==="-exec")for(a=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):U.has(l)?(a=!0,p++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(p=>p.type==="print"),b=o.length===0,y=[],Y=o.some(p=>p.type==="printf"),F=[],T="",D=0,V=G(i),k=new Map;for(let p of V){let l=s.fs.resolvePath(s.cwd,p);try{let g=await s.fs.stat(l);k.set(p,g.mtime?.getTime()??Date.now())}catch{}}for(let p of n){let l=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(l)}catch{T+=`find: ${p}: No such file or directory
|
|
4
|
+
`,D=1;continue}async function g(u,d){if(r!==null&&d>r)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===l?E=p.split("/").pop()||p:E=u.split("/").pop()||"";let $=u===l?p:p==="."?`./${u.slice(l.length+1)}`:p+u.slice(l.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,v=!1;if(x&&i!==null){let J={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},W=w(i,J);x=W.matches,h?v=W.printed:v=x}else x&&(v=!0);v&&(y.push($),Y&&F.push({path:$,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:p}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},z=!1;if(!m&&i!==null){let P={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};z=w(i,P).pruned}m?(await A(),C()):(C(),z||await A())}await g(l,0)}let S="";if(o.length>0)for(let p of o)switch(p.type){case"print":S+=y.length>0?`${y.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let l=[...y].sort((g,u)=>u.length-g.length);for(let g of l){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
|
|
7
|
+
`,D=1}}break}case"printf":for(let l of F)S+=q(p.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
8
|
+
`,exitCode:1};if(p.batchMode){let l=[];for(let d of p.command)d==="{}"?l.push(...y):l.push(d);let g=l.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let l of y){let u=p.command.map(f=>f==="{}"?l:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[m,a,i]=B(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:r+=`%${m!==0||a!==-1?`${m}.${a}`:""}${c}`,t++;continue}r+=L(o,m,a)}else r+=n[t],t++;return r}function Q(e,s){let n=e&511,r=s?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function X(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=s[e.getDay()],t=n[e.getMonth()],m=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),o=e.getFullYear();return`${r} ${t} ${m} ${a}:${i}:${c} ${o}`}function Z(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{oe as findCommand};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as k}from"./chunk-UJMN5NLH.js";import{a as $,b as S}from"./chunk-74CEPOFO.js";function g(e,s){switch(e.type){case"name":return{matches:k(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:k(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let t=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,t).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),n;return e.comparison==="more"?n=r>e.days:e.comparison==="less"?n=r<e.days:n=Math.floor(r)===e.days,{matches:n,pruned:!1,printed:!1}}case"newer":{let t=s.newerRefTimes.get(e.refPath);return t===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>t,pruned:!1,printed:!1}}case"size":{let t=e.value;switch(e.unit){case"c":t=e.value;break;case"k":t=e.value*1024;break;case"M":t=e.value*1024*1024;break;case"G":t=e.value*1024*1024*1024;break;case"b":t=e.value*512;break}let r;return e.comparison==="more"?r=s.size>t:e.comparison==="less"?r=s.size<t:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===t,{matches:r,pruned:!1,printed:!1}}case"perm":{let t=s.mode&511,r=e.mode&511,n;return e.matchType==="exact"?n=t===r:e.matchType==="all"?n=(t&r)===r:n=(t&r)!==0,{matches:n,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let t=g(e.expr,s);return{matches:!t.matches,pruned:t.pruned,printed:!1}}case"and":{let t=g(e.left,s);if(!t.matches)return{matches:!1,pruned:t.pruned,printed:!1};let r=g(e.right,s);return{matches:r.matches,pruned:t.pruned||r.pruned,printed:t.printed||r.printed}}case"or":{let t=g(e.left,s);if(t.matches)return t;let r=g(e.right,s);return{matches:r.matches,pruned:t.pruned||r.pruned,printed:r.printed}}}}function L(e){let s=[],t=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?t(r.expr):(r.type==="and"||r.type==="or")&&(t(r.left),t(r.right)))};return t(e),s}function O(e,s){let t=[],r=[],n=s;for(;n<e.length;){let l=e[n];if(l==="("||l==="\\("){t.push({type:"lparen"}),n++;continue}if(l===")"||l==="\\)"){t.push({type:"rparen"}),n++;continue}if(l==="-name"&&n+1<e.length)t.push({type:"expr",expr:{type:"name",pattern:e[++n]}});else if(l==="-iname"&&n+1<e.length)t.push({type:"expr",expr:{type:"name",pattern:e[++n],ignoreCase:!0}});else if(l==="-path"&&n+1<e.length)t.push({type:"expr",expr:{type:"path",pattern:e[++n]}});else if(l==="-ipath"&&n+1<e.length)t.push({type:"expr",expr:{type:"path",pattern:e[++n],ignoreCase:!0}});else if(l==="-regex"&&n+1<e.length)t.push({type:"expr",expr:{type:"regex",pattern:e[++n]}});else if(l==="-iregex"&&n+1<e.length)t.push({type:"expr",expr:{type:"regex",pattern:e[++n],ignoreCase:!0}});else if(l==="-type"&&n+1<e.length){let i=e[++n];if(i==="f"||i==="d")t.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:n,error:`find: Unknown argument to -type: ${i}
|
|
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 y=parseInt(f,10);Number.isNaN(y)||t.push({type:"expr",expr:{type:"mtime",days:y,comparison:o}})}else if(l==="-newer"&&n+1<e.length){let i=e[++n];t.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(l==="-size"&&n+1<e.length){let i=e[++n],o="exact",f=i;i.startsWith("+")?(o="more",f=i.slice(1)):i.startsWith("-")&&(o="less",f=i.slice(1));let y=f.match(/^(\d+)([ckMGb])?$/);if(y){let N=parseInt(y[1],10),d=y[2]||"b";t.push({type:"expr",expr:{type:"size",value:N,unit:d,comparison:o}})}}else if(l==="-perm"&&n+1<e.length){let i=e[++n],o="exact",f=i;i.startsWith("-")?(o="all",f=i.slice(1)):i.startsWith("/")&&(o="any",f=i.slice(1));let y=parseInt(f,8);Number.isNaN(y)||t.push({type:"expr",expr:{type:"perm",mode:y,matchType:o}})}else if(l==="-prune")t.push({type:"expr",expr:{type:"prune"}});else if(l==="-not"||l==="!")t.push({type:"not"});else if(l==="-o"||l==="-or")t.push({type:"op",op:"or"});else if(l==="-a"||l==="-and")t.push({type:"op",op:"and"});else if(l==="-maxdepth"||l==="-mindepth")n++;else if(l!=="-depth")if(l==="-exec"){let i=[];for(n++;n<e.length&&e[n]!==";"&&e[n]!=="+";)i.push(e[n]),n++;if(n>=e.length)return{expr:null,pathIndex:n,error:"find: missing argument to `-exec'\n",actions:[]};let o=e[n]==="+";r.push({type:"exec",command:i,batchMode:o})}else if(l==="-print")t.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(l==="-print0")r.push({type:"print0"});else if(l==="-delete")r.push({type:"delete"});else{if(l.startsWith("-"))return{expr:null,pathIndex:n,error:`find: unknown predicate '${l}'
|
|
3
|
+
`,actions:[]};if(t.length===0){n++;continue}break}n++}if(t.length===0)return{expr:null,pathIndex:n,actions:r};let w=j(t);return w.error?{expr:null,pathIndex:n,error:w.error,actions:r}:{expr:w.expr,pathIndex:n,actions:r}}function j(e){let s=0;function t(){let i=r();if(!i)return null;for(;s<e.length;){let o=e[s];if(o.type==="op"&&o.op==="or"){s++;let f=r();if(!f)return i;i={type:"or",left:i,right:f}}else break}return i}function r(){let i=n();if(!i)return null;for(;s<e.length;){let o=e[s];if(o.type==="op"&&o.op==="and"){s++;let f=n();if(!f)return i;i={type:"and",left:i,right:f}}else if(o.type==="expr"||o.type==="not"||o.type==="lparen"){let f=n();if(!f)return i;i={type:"and",left:i,right:f}}else break}return i}function n(){if(s<e.length&&e[s].type==="not"){s++;let i=n();return i?{type:"not",expr:i}:null}return w()}function w(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let o=t();return s<e.length&&e[s].type==="rparen"&&s++,o}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:t()}}var H={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-delete delete found files/directories"," --help display this help and exit"]},V=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),Q={name:"find",async execute(e,s){if(S(e))return $(H);let t=[],r=null,n=null,w=!1,l=!1;for(let p=0;p<e.length;p++){let a=e[p];if(a==="-maxdepth"&&p+1<e.length)l=!0,r=parseInt(e[++p],10);else if(a==="-mindepth"&&p+1<e.length)l=!0,n=parseInt(e[++p],10);else if(a==="-depth")l=!0,w=!0;else if(a==="-exec")for(l=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!a.startsWith("-")&&a!==";"&&a!=="+"&&a!=="("&&a!==")"&&a!=="\\("&&a!=="\\)"&&a!=="!"?l||t.push(a):V.has(a)?(l=!0,p++):(a.startsWith("-")||a==="("||a==="\\("||a==="!")&&(l=!0)}t.length===0&&t.push(".");let{expr:i,error:o,actions:f}=O(e,0);if(o)return{stdout:"",stderr:o,exitCode:1};let y=f.some(p=>p.type==="print"),N=f.length===0,d=[],b="",T=0,B=L(i),C=new Map;for(let p of B){let a=s.fs.resolvePath(s.cwd,p);try{let m=await s.fs.stat(a);C.set(p,m.mtime?.getTime()??Date.now())}catch{}}for(let p of t){let a=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(a)}catch{b+=`find: ${p}: No such file or directory
|
|
4
|
+
`,T=1;continue}async function m(u,h){if(r!==null&&h>r)return;let c;try{c=await s.fs.stat(u)}catch{return}if(!c)return;let v;u===a?v=p.split("/").pop()||p:v=u.split("/").pop()||"";let R=u===a?p:p==="."?`./${u.slice(a.length+1)}`:p+u.slice(a.length),D=null;c.isDirectory&&(D=await s.fs.readdir(u));let z=c.isFile?c.size===0:D!==null&&D.length===0,A=()=>{let x=n===null||h>=n,M=!1;if(x&&i!==null){let G={name:v,relativePath:R,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:z,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C},W=g(i,G);x=W.matches,y?M=W.printed:M=x}else x&&(M=!0);M&&d.push(R)},F=async()=>{if(D!==null)for(let P of D){let x=u==="/"?`/${P}`:`${u}/${P}`;await m(x,h+1)}},I=!1;if(!w&&i!==null){let P={name:v,relativePath:R,isFile:c.isFile,isDirectory:c.isDirectory,isEmpty:z,mtime:c.mtime?.getTime()??Date.now(),size:c.size??0,mode:c.mode??420,newerRefTimes:C};I=g(i,P).pruned}w?(await F(),A()):(A(),I||await F())}await m(a,0)}let E="";if(f.length>0)for(let p of f)switch(p.type){case"print":E+=d.length>0?`${d.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"";break;case"print0":E+=d.length>0?`${d.join("\0")}\0`:"";break;case"delete":{let a=[...d].sort((m,u)=>u.length-m.length);for(let m of a){let u=s.fs.resolvePath(s.cwd,m);try{await s.fs.rm(u,{recursive:!1})}catch(h){let c=h instanceof Error?h.message:String(h);b+=`find: cannot delete '${m}': ${c}
|
|
7
|
+
`,T=1}}break}case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
8
|
+
`,exitCode:1};if(p.batchMode){let a=[];for(let h of p.command)h==="{}"?a.push(...d):a.push(h);let m=a.map(h=>`"${h}"`).join(" "),u=await s.exec(m,{cwd:s.cwd});E+=u.stdout,b+=u.stderr,u.exitCode!==0&&(T=u.exitCode)}else for(let a of d){let u=p.command.map(c=>c==="{}"?a:c).map(c=>`"${c}"`).join(" "),h=await s.exec(u,{cwd:s.cwd});E+=h.stdout,b+=h.stderr,h.exitCode!==0&&(T=h.exitCode)}break}else N&&(E=d.length>0?`${d.join(`
|
|
9
|
+
`)}
|
|
10
|
+
`:"");return{stdout:E,stderr:b,exitCode:T}}};export{Q as findCommand};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{a as C,c as I}from"./chunk-TDJNT32M.js";import{a as w}from"./chunk-44UOCSGV.js";import{a as S,b as $}from"./chunk-74CEPOFO.js";import{sprintf as p}from"sprintf-js";var F={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},Q={name:"printf",async execute(e,l){if($(e))return S(F);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
2
|
+
`,exitCode:2};let t=null,s=0;for(;s<e.length;){let a=e[s];if(a==="--"){s++;break}if(a==="-v"){if(s+1>=e.length)return{stdout:"",stderr:`printf: -v: option requires an argument
|
|
3
|
+
`,exitCode:1};if(t=e[s+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[^\]]+\])?$/.test(t))return{stdout:"",stderr:`printf: \`${t}': not a valid identifier
|
|
4
|
+
`,exitCode:2};s+=2}else{if(a.startsWith("-")&&a!=="-")break;break}}if(s>=e.length)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
5
|
+
`,exitCode:1};let r=e[s],n=e.slice(s+1);try{let a=I(r),i="",c=0,o=!1,f="";do{let{result:g,argsConsumed:x,error:d,errMsg:h,stopped:E}=W(a,n,c);if(i+=g,c+=x,d&&(o=!0,h&&(f=h)),E)break}while(c<n.length&&c>0);return c===0&&n.length>0,t?(l.env[t]=i,{stdout:"",stderr:f,exitCode:o?1:0}):{stdout:i,stderr:f,exitCode:o?1:0}}catch(a){return{stdout:"",stderr:`printf: ${w(a)}
|
|
6
|
+
`,exitCode:1}}}};function W(e,l,t){let s="",r=0,n=0,a=!1,i="";for(;r<e.length;)if(e[r]==="%"&&r+1<e.length){let c=r;if(r++,e[r]==="%"){s+="%",r++;continue}for(;r<e.length&&"+-0 #'".includes(e[r]);)r++;let o=!1;if(e[r]==="*")o=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;let f=!1;if(e[r]===".")if(r++,e[r]==="*")f=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;r<e.length&&"hlL".includes(e[r])&&r++;let g=e[r]||"";r++;let d=e.slice(c,r);if(o){let b=parseInt(l[t+n]||"0",10);n++,d=d.replace("*",String(b))}if(f){let b=parseInt(l[t+n]||"0",10);n++,d=d.replace(".*",`.${b}`)}let h=l[t+n]||"";n++;let{value:E,parseError:M,parseErrMsg:v,stopped:k}=y(d,g,h);if(s+=E,M&&(a=!0,v&&(i=v)),k)return{result:s,argsConsumed:n,error:a,errMsg:i,stopped:!0}}else s+=e[r],r++;return{result:s,argsConsumed:n,error:a,errMsg:i,stopped:!1}}function y(e,l,t){let s=!1,r="";switch(l){case"d":case"i":{let n=m(t);return s=u,s&&(r=`printf: ${t}: invalid number
|
|
7
|
+
`),{value:A(e,n),parseError:s,parseErrMsg:r}}case"o":{let n=m(t);return s=u,s&&(r=`printf: ${t}: invalid number
|
|
8
|
+
`),{value:N(e,n),parseError:s,parseErrMsg:r}}case"u":{let n=m(t);s=u,s&&(r=`printf: ${t}: invalid number
|
|
9
|
+
`);let a=n<0?n>>>0:n;return{value:A(e.replace("u","d"),a),parseError:s,parseErrMsg:r}}case"x":case"X":{let n=m(t);return s=u,s&&(r=`printf: ${t}: invalid number
|
|
10
|
+
`),{value:j(e,n),parseError:s,parseErrMsg:r}}case"e":case"E":case"f":case"F":case"g":case"G":{let n=parseFloat(t)||0;return{value:U(e,l,n),parseError:!1,parseErrMsg:""}}case"c":return{value:t.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:z(e,t),parseError:!1,parseErrMsg:""};case"q":return{value:R(e,t),parseError:!1,parseErrMsg:""};case"b":{let n=X(t);return{value:n.value,parseError:!1,parseErrMsg:"",stopped:n.stopped}}default:try{return{value:p(e,t),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
|
|
11
|
+
`}}}}var u=!1;function m(e){u=!1;let l=e.trimStart(),t=l!==l.trimEnd();if(e=l.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let s=parseInt(e,16);return Number.isNaN(s)?(u=!0,0):(t&&(u=!0),s)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return t&&(u=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){u=!0;let s=e.match(/^(\d+)#/);return s?parseInt(s[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){u=!0;let s=parseInt(e,10);return Number.isNaN(s)?0:s}return t&&(u=!0),parseInt(e,10)||0}function A(e,l){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!t)return p(e.replace(/\.\d*/,""),l);let s=t[1]||"",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,a=l<0,i=Math.abs(l),c=String(i);n>=0&&(c=c.padStart(n,"0"));let o="";a?o="-":s.includes("+")?o="+":s.includes(" ")&&(o=" ");let f=o+c;return r>f.length&&(s.includes("-")?f=f.padEnd(r," "):s.includes("0")&&n<0?f=o+c.padStart(r-o.length,"0"):f=f.padStart(r," ")),f}function N(e,l){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!t)return p(e,l);let s=t[1]||"",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,a=Math.abs(l).toString(8);n>=0&&(a=a.padStart(n,"0")),s.includes("#")&&!a.startsWith("0")&&(a=`0${a}`);let i=a;return r>i.length&&(s.includes("-")?i=i.padEnd(r," "):s.includes("0")&&n<0?i=i.padStart(r,"0"):i=i.padStart(r," ")),i}function j(e,l){let t=e.includes("X"),s=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!s)return p(e,l);let r=s[1]||"",n=s[2]?parseInt(s[2],10):0,a=s[3]!==void 0?s[4]?parseInt(s[4],10):0:-1,i=Math.abs(l).toString(16);t&&(i=i.toUpperCase()),a>=0&&(i=i.padStart(a,"0"));let c="";r.includes("#")&&l!==0&&(c=t?"0X":"0x");let o=c+i;return n>o.length&&(r.includes("-")?o=o.padEnd(n," "):r.includes("0")&&a<0?o=c+i.padStart(n-c.length,"0"):o=o.padStart(n," ")),o}function q(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f]/.test(e)){let s="$'";for(let r of e){let n=r.charCodeAt(0);r==="'"?s+="\\'":r==="\\"?s+="\\\\":r===`
|
|
12
|
+
`?s+="\\n":r===" "?s+="\\t":r==="\r"?s+="\\r":r==="\x07"?s+="\\a":r==="\b"?s+="\\b":r==="\f"?s+="\\f":r==="\v"?s+="\\v":r==="\x1B"?s+="\\E":n<32||n>126?s+=`\\x${n.toString(16).padStart(2,"0")}`:r==='"'?s+='\\"':s+=r}return s+="'",s}let t="";for(let s of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(s)?t+=`\\${s}`:t+=s;return t}function z(e,l){let t=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!t)return p(e.replace(/0+(?=\d)/,""),l);let s=t[1]==="-",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,a=s?-r:r;return C(l,a,n)}function R(e,l){let t=q(l),s=e.match(/^%(-?)(\d*)q$/);if(!s)return t;let r=s[1]==="-",n=s[2]?parseInt(s[2],10):0,a=t;return n>a.length&&(r?a=a.padEnd(n," "):a=a.padStart(n," ")),a}function U(e,l,t){let s=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!s)return p(e,t);let r=s[1]||"",n=s[2]?parseInt(s[2],10):0,a=s[3]!==void 0?s[4]?parseInt(s[4],10):0:6,i,c=l.toLowerCase();if(c==="e"?(i=t.toExponential(a),i=i.replace(/e([+-])(\d)$/,"e$10$2"),l==="E"&&(i=i.toUpperCase())):c==="f"?(i=t.toFixed(a),r.includes("#")&&a===0&&!i.includes(".")&&(i+=".")):c==="g"?(i=t.toPrecision(a||1),r.includes("#")||(i=i.replace(/\.?0+$/,""),i=i.replace(/\.?0+e/,"e")),i=i.replace(/e([+-])(\d)$/,"e$10$2"),l==="G"&&(i=i.toUpperCase())):i=t.toString(),t>=0&&(r.includes("+")?i=`+${i}`:r.includes(" ")&&(i=` ${i}`)),n>i.length)if(r.includes("-"))i=i.padEnd(n," ");else if(r.includes("0")){let o=i.match(/^[+ -]/)?.[0]||"",f=o?i.slice(1):i;i=o+f.padStart(n-o.length,"0")}else i=i.padStart(n," ");return i}function X(e){let l="",t=0;for(;t<e.length;)if(e[t]==="\\"&&t+1<e.length)switch(e[t+1]){case"n":l+=`
|
|
13
|
+
`,t+=2;break;case"t":l+=" ",t+=2;break;case"r":l+="\r",t+=2;break;case"\\":l+="\\",t+=2;break;case"a":l+="\x07",t+=2;break;case"b":l+="\b",t+=2;break;case"f":l+="\f",t+=2;break;case"v":l+="\v",t+=2;break;case"c":return{value:l,stopped:!0};case"x":{let r="",n=t+2;for(;n<e.length&&n<t+4&&/[0-9a-fA-F]/.test(e[n]);)r+=e[n],n++;r?(l+=String.fromCharCode(parseInt(r,16)),t=n):(l+="\\x",t+=2);break}case"u":{let r="",n=t+2;for(;n<e.length&&n<t+6&&/[0-9a-fA-F]/.test(e[n]);)r+=e[n],n++;r?(l+=String.fromCodePoint(parseInt(r,16)),t=n):(l+="\\u",t+=2);break}case"0":{let r="",n=t+2;for(;n<e.length&&n<t+5&&/[0-7]/.test(e[n]);)r+=e[n],n++;r?l+=String.fromCharCode(parseInt(r,8)):l+="\0",t=n;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let r="",n=t+1;for(;n<e.length&&n<t+4&&/[0-7]/.test(e[n]);)r+=e[n],n++;l+=String.fromCharCode(parseInt(r,8)),t=n;break}default:l+=e[t],t++}else l+=e[t],t++;return{value:l,stopped:!1}}export{Q as printfCommand};
|
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-G2SBUNW3.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-522XP4ZY.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:`
|
|
@@ -56,6 +56,9 @@ export type FindAction = {
|
|
|
56
56
|
type: "print";
|
|
57
57
|
} | {
|
|
58
58
|
type: "print0";
|
|
59
|
+
} | {
|
|
60
|
+
type: "printf";
|
|
61
|
+
format: string;
|
|
59
62
|
} | {
|
|
60
63
|
type: "delete";
|
|
61
64
|
};
|
|
@@ -69,6 +72,8 @@ export interface EvalContext {
|
|
|
69
72
|
size: number;
|
|
70
73
|
mode: number;
|
|
71
74
|
newerRefTimes: Map<string, number>;
|
|
75
|
+
depth?: number;
|
|
76
|
+
startingPoint?: string;
|
|
72
77
|
}
|
|
73
78
|
export interface EvalResult {
|
|
74
79
|
matches: boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared escape sequence and formatting utilities
|
|
3
|
+
* Used by printf command and find -printf
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Apply width and alignment to a string value
|
|
7
|
+
* Supports: width (right-justify), -width (left-justify), .precision (truncate)
|
|
8
|
+
* @param value - The string value to format
|
|
9
|
+
* @param width - The field width (negative for left-justify)
|
|
10
|
+
* @param precision - Maximum length (-1 for no limit)
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyWidth(value: string, width: number, precision: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Parse a width/precision spec from a format directive
|
|
15
|
+
* Returns: [width, precision, charsConsumed]
|
|
16
|
+
* width: positive for right-justify, negative for left-justify
|
|
17
|
+
* precision: -1 if not specified
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseWidthPrecision(format: string, startIndex: number): [number, number, number];
|
|
20
|
+
/**
|
|
21
|
+
* Process escape sequences in a string
|
|
22
|
+
* Handles: \n, \t, \r, \\, \a, \b, \f, \v, \0NNN (octal), \xHH (hex)
|
|
23
|
+
*/
|
|
24
|
+
export declare function processEscapes(str: string): string;
|