just-bash 2.6.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/AGENTS.md +1 -1
- package/dist/bin/chunks/alias-MGDOL4KG.js +7 -0
- package/dist/bin/chunks/awk2-ASLLINAN.js +21 -0
- package/dist/bin/{shell/chunks/base64-O7TCK5TL.js → chunks/base64-43KPK6TL.js} +1 -1
- package/dist/bin/chunks/bash-OAUBNRSG.js +6 -0
- package/dist/bin/{shell/chunks/cat-AJXZOSPN.js → chunks/cat-HNXE2ES2.js} +1 -1
- package/dist/bin/chunks/chunk-4PRVMER6.js +2 -0
- package/dist/bin/chunks/chunk-C6FK2JV3.js +74 -0
- package/dist/bin/chunks/chunk-GZHFXDDO.js +10 -0
- package/dist/bin/chunks/chunk-JBABAK44.js +4 -0
- package/dist/bin/chunks/chunk-YNACG4DZ.js +6 -0
- package/dist/bin/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
- package/dist/bin/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
- package/dist/bin/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
- package/dist/bin/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
- package/dist/bin/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
- package/dist/bin/chunks/env-W6IMQ43Y.js +9 -0
- package/dist/bin/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
- package/dist/bin/chunks/{gzip-YXK3WZQL.js → gzip-5ILPB46W.js} +1 -1
- package/dist/bin/chunks/history-56DL6SXU.js +3 -0
- package/dist/bin/{shell/chunks/jq-RGZHJNXC.js → chunks/jq-M2WXBRXF.js} +1 -1
- package/dist/bin/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
- package/dist/bin/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
- package/dist/bin/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
- package/dist/bin/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
- package/dist/bin/{shell/chunks/printf-YPXD4CRE.js → chunks/printf-XPBSFXJE.js} +1 -1
- package/dist/bin/chunks/python3-ZWX5SFJ3.js +14 -0
- package/dist/bin/{shell/chunks/rm-2PKAWTSQ.js → chunks/rm-S7ASVG34.js} +1 -1
- package/dist/bin/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
- package/dist/bin/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
- package/dist/bin/{shell/chunks/tee-ZFIT2GTM.js → chunks/tee-XSKPK43X.js} +1 -1
- package/dist/bin/chunks/time-F4NVQOJH.js +14 -0
- package/dist/bin/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
- package/dist/bin/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
- package/dist/bin/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
- package/dist/bin/{shell/chunks/wc-SAOHEZYP.js → chunks/wc-CZ2TD6T6.js} +1 -1
- package/dist/bin/{shell/chunks/which-FCDFBOMN.js → chunks/which-5QEJAXNR.js} +1 -1
- package/dist/bin/chunks/worker.js +1038 -0
- package/dist/bin/chunks/xan-OPVCJ3ZA.js +140 -0
- package/dist/bin/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
- package/dist/bin/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
- package/dist/bin/just-bash.js +251 -251
- package/dist/bin/shell/chunks/alias-MGDOL4KG.js +7 -0
- package/dist/bin/shell/chunks/awk2-ASLLINAN.js +21 -0
- package/dist/bin/{chunks/base64-O7TCK5TL.js → shell/chunks/base64-43KPK6TL.js} +1 -1
- package/dist/bin/shell/chunks/bash-OAUBNRSG.js +6 -0
- package/dist/bin/{chunks/cat-AJXZOSPN.js → shell/chunks/cat-HNXE2ES2.js} +1 -1
- package/dist/bin/shell/chunks/chunk-4PRVMER6.js +2 -0
- package/dist/bin/shell/chunks/chunk-C6FK2JV3.js +74 -0
- package/dist/bin/shell/chunks/chunk-GZHFXDDO.js +10 -0
- package/dist/bin/shell/chunks/chunk-JBABAK44.js +4 -0
- package/dist/bin/shell/chunks/chunk-YNACG4DZ.js +6 -0
- package/dist/bin/shell/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
- package/dist/bin/shell/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
- package/dist/bin/shell/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
- package/dist/bin/shell/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
- package/dist/bin/shell/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
- package/dist/bin/shell/chunks/env-W6IMQ43Y.js +9 -0
- package/dist/bin/shell/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
- package/dist/bin/shell/chunks/{gzip-YXK3WZQL.js → gzip-5ILPB46W.js} +1 -1
- package/dist/bin/shell/chunks/history-56DL6SXU.js +3 -0
- package/dist/bin/{chunks/jq-RGZHJNXC.js → shell/chunks/jq-M2WXBRXF.js} +1 -1
- package/dist/bin/shell/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
- package/dist/bin/shell/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
- package/dist/bin/shell/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
- package/dist/bin/shell/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
- package/dist/bin/{chunks/printf-YPXD4CRE.js → shell/chunks/printf-XPBSFXJE.js} +1 -1
- package/dist/bin/shell/chunks/python3-ZWX5SFJ3.js +14 -0
- package/dist/bin/{chunks/rm-2PKAWTSQ.js → shell/chunks/rm-S7ASVG34.js} +1 -1
- package/dist/bin/shell/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
- package/dist/bin/shell/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
- package/dist/bin/{chunks/tee-ZFIT2GTM.js → shell/chunks/tee-XSKPK43X.js} +1 -1
- package/dist/bin/shell/chunks/time-F4NVQOJH.js +14 -0
- package/dist/bin/shell/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
- package/dist/bin/shell/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
- package/dist/bin/shell/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
- package/dist/bin/{chunks/wc-SAOHEZYP.js → shell/chunks/wc-CZ2TD6T6.js} +1 -1
- package/dist/bin/{chunks/which-FCDFBOMN.js → shell/chunks/which-5QEJAXNR.js} +1 -1
- package/dist/bin/shell/chunks/xan-OPVCJ3ZA.js +140 -0
- package/dist/bin/shell/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
- package/dist/bin/shell/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
- package/dist/bin/shell/shell.js +226 -226
- package/dist/bundle/browser.js +623 -623
- package/dist/bundle/chunks/alias-YGOORMWI.js +6 -0
- package/dist/bundle/chunks/awk2-5K7HVGCQ.js +20 -0
- package/dist/bundle/chunks/{base64-3BME25ON.js → base64-2JFR3HGT.js} +1 -1
- package/dist/bundle/chunks/bash-BYWM5OPC.js +5 -0
- package/dist/bundle/chunks/{cat-MV4K6AUA.js → cat-GPKR7D6K.js} +1 -1
- package/dist/bundle/chunks/chunk-76ZRJPDK.js +73 -0
- package/dist/bundle/chunks/chunk-F55TLFGB.js +9 -0
- package/dist/bundle/chunks/chunk-HWKDQ44K.js +3 -0
- package/dist/bundle/chunks/chunk-IEPFPINK.js +5 -0
- package/dist/bundle/chunks/chunk-OJDRYQWQ.js +1 -0
- package/dist/bundle/chunks/{column-XPDNNO5Y.js → column-R6OLMEUA.js} +1 -1
- package/dist/bundle/chunks/{cp-PBJT3GBF.js → cp-NJSENVKC.js} +1 -1
- package/dist/bundle/chunks/{curl-XLP4VABU.js → curl-QDCXHQMX.js} +1 -1
- package/dist/bundle/chunks/{diff-ZLJYSBRK.js → diff-ELUS3RW7.js} +1 -1
- package/dist/bundle/chunks/{du-NQXEC3EF.js → du-T4JUAAB2.js} +1 -1
- package/dist/bundle/chunks/env-M3AXY56V.js +8 -0
- package/dist/bundle/chunks/{expansion-RIGCFEMA.js → expansion-DXWR3WZB.js} +1 -1
- package/dist/bundle/chunks/{gzip-L3NDJG3F.js → gzip-4P4KGYT5.js} +1 -1
- package/dist/bundle/chunks/history-TMBGOQO6.js +2 -0
- package/dist/bundle/chunks/{jq-RLRYRPOJ.js → jq-KF5D2PYR.js} +1 -1
- package/dist/bundle/chunks/{ls-5W3NU5OJ.js → ls-PUJHEPXS.js} +1 -1
- package/dist/bundle/chunks/{mkdir-7UKY4B3B.js → mkdir-SF2UE4KB.js} +1 -1
- package/dist/bundle/chunks/{mv-FXHEKRTB.js → mv-JPBZPM4O.js} +1 -1
- package/dist/bundle/chunks/{paste-QTGVEPH5.js → paste-QAP6Y75J.js} +1 -1
- package/dist/bundle/chunks/{printf-66XGXFCD.js → printf-OAPYPRGV.js} +1 -1
- package/dist/bundle/chunks/python3-SKZGHYDO.js +13 -0
- package/dist/bundle/chunks/{rm-I2SRVF7H.js → rm-MJFRIDNT.js} +1 -1
- package/dist/bundle/chunks/{rmdir-XFQE4ZYV.js → rmdir-DU6C7ZEO.js} +1 -1
- package/dist/bundle/chunks/{stat-IVQBBOKN.js → stat-IOLJTP7U.js} +1 -1
- package/dist/bundle/chunks/{tee-2QU4NRSJ.js → tee-4KHTWVWB.js} +1 -1
- package/dist/bundle/chunks/time-EGF4KTWV.js +13 -0
- package/dist/bundle/chunks/{tr-EDGW5FG6.js → tr-P43NRVKL.js} +1 -1
- package/dist/bundle/chunks/{tree-MEM64BW3.js → tree-UFVZH4SS.js} +1 -1
- package/dist/bundle/chunks/{uniq-47QVBRNC.js → uniq-XBP4SJA3.js} +1 -1
- package/dist/bundle/chunks/{wc-HE5XARI4.js → wc-VDPK3LVS.js} +1 -1
- package/dist/bundle/chunks/{which-UBLRBDHN.js → which-GF77XMJD.js} +1 -1
- package/dist/bundle/chunks/worker.js +1038 -0
- package/dist/bundle/chunks/xan-RW5GSH6C.js +139 -0
- package/dist/bundle/chunks/{xan-view-DMFUMZG7.js → xan-view-ECQUO7AJ.js} +1 -1
- package/dist/bundle/chunks/{yq-L665QPQU.js → yq-EMWRPC7R.js} +1 -1
- package/dist/bundle/index.js +253 -253
- package/dist/commands/python3/fs-bridge-handler.d.ts +50 -0
- package/dist/commands/python3/protocol.d.ts +138 -0
- package/dist/commands/python3/python3.d.ts +11 -0
- package/dist/commands/python3/sync-fs-backend.d.ts +59 -0
- package/dist/commands/python3/worker.d.ts +16 -0
- package/dist/commands/query-engine/evaluator.d.ts +2 -2
- package/dist/commands/query-engine/safe-object.d.ts +49 -0
- package/dist/commands/query-engine/value-operations.d.ts +1 -0
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/xan/aggregation.d.ts +1 -1
- package/dist/commands/xan/csv.d.ts +16 -0
- package/dist/interpreter/alias-expansion.d.ts +1 -1
- package/dist/interpreter/helpers/ifs.d.ts +4 -4
- package/dist/interpreter/simple-command-assignments.d.ts +1 -1
- package/dist/interpreter/types.d.ts +2 -2
- package/dist/limits.d.ts +2 -0
- package/dist/types.d.ts +2 -2
- package/package.json +7 -5
- package/dist/bin/chunks/alias-EGIS5LUE.js +0 -7
- package/dist/bin/chunks/awk2-GFEJOWML.js +0 -21
- package/dist/bin/chunks/bash-PGDTHIM2.js +0 -6
- package/dist/bin/chunks/chunk-FSAGDARS.js +0 -74
- package/dist/bin/chunks/chunk-KD3EODLB.js +0 -6
- package/dist/bin/chunks/chunk-TA7RUHGQ.js +0 -4
- package/dist/bin/chunks/chunk-UUQYHLBO.js +0 -10
- package/dist/bin/chunks/env-7A4MH7BJ.js +0 -9
- package/dist/bin/chunks/history-G5C2J2OY.js +0 -3
- package/dist/bin/chunks/time-37F5EBPK.js +0 -14
- package/dist/bin/chunks/xan-5HNHTFMB.js +0 -140
- package/dist/bin/shell/chunks/alias-EGIS5LUE.js +0 -7
- package/dist/bin/shell/chunks/awk2-GFEJOWML.js +0 -21
- package/dist/bin/shell/chunks/bash-PGDTHIM2.js +0 -6
- package/dist/bin/shell/chunks/chunk-FSAGDARS.js +0 -74
- package/dist/bin/shell/chunks/chunk-KD3EODLB.js +0 -6
- package/dist/bin/shell/chunks/chunk-TA7RUHGQ.js +0 -4
- package/dist/bin/shell/chunks/chunk-UUQYHLBO.js +0 -10
- package/dist/bin/shell/chunks/env-7A4MH7BJ.js +0 -9
- package/dist/bin/shell/chunks/history-G5C2J2OY.js +0 -3
- package/dist/bin/shell/chunks/time-37F5EBPK.js +0 -14
- package/dist/bin/shell/chunks/xan-5HNHTFMB.js +0 -140
- package/dist/bundle/chunks/alias-ATFBB6D2.js +0 -6
- package/dist/bundle/chunks/awk2-6FBZTP57.js +0 -20
- package/dist/bundle/chunks/bash-OLRNM52U.js +0 -5
- package/dist/bundle/chunks/chunk-3AWP5CWK.js +0 -73
- package/dist/bundle/chunks/chunk-A263W2RD.js +0 -9
- package/dist/bundle/chunks/chunk-CZPA5RBA.js +0 -5
- package/dist/bundle/chunks/chunk-ZVV5VXYZ.js +0 -3
- package/dist/bundle/chunks/env-2UI6XINU.js +0 -8
- package/dist/bundle/chunks/history-MQDK2OPD.js +0 -2
- package/dist/bundle/chunks/time-UWXBG6CS.js +0 -13
- package/dist/bundle/chunks/xan-A6VPI4HJ.js +0 -139
package/dist/bin/shell/shell.js
CHANGED
|
@@ -1,156 +1,156 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{B as Zs,C as Gs,D as ne,E as Pe,F as K,G as ue,H as st,I as Ks,J as I,K as Xs,L as Ys,M as pe,N as Wt,O as nt,P as V,a as Fs,b as Ms,c as zs,d as et,e as q,f as M,g as de,h as J,i as he,j as be,k as It,l as tt,m as Vs,n as Tt,o as js,p as oe,q as ge,r as Bs,s as Hs,t as xt,u as Rt,v as Ee,w as Us,x as qs,y as fe,z as Lt}from"./chunks/chunk-FSAGDARS.js";import{a as re,b as ie,c as se,d as ae,e as Ls,f as z,g as Ce,h as Ye,i as Qe,j as Ws,k as te,l as ve,m as Je,n as ce}from"./chunks/chunk-K5IXNHO5.js";import"./chunks/chunk-OBH7XN5N.js";import{a as le}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import*as Cr from"node:fs";import*as Pr from"node:readline";var Oe=[{name:"echo",load:async()=>(await import("./chunks/echo-7I42V66Q.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-AJXZOSPN.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YPXD4CRE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-BEHQBUMC.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XJABRAUN.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-GOODLY5W.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-IBPHJBM3.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-2PKAWTSQ.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XXWRVG2D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-3ATZ2ABL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TYLTHXFR.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-L26WH2K4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TJHLLIMR.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YAUIERGN.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-SAOHEZYP.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-UEQ7KMY5.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-RSDLLECO.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-JPDTWF4W.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-GFEJOWML.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-KUHOCH5S.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IXHB2FVS.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-FT6WBQZG.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-MBLEXZBI.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-JJFZRWRC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-TSFEMTG6.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-ZFIT2GTM.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-PHDZK64M.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-DQBEJH47.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-XQPYLN3H.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-7A4MH7BJ.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-7A4MH7BJ.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-EGIS5LUE.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-EGIS5LUE.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-G5C2J2OY.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-PGDTHIM2.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-PGDTHIM2.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-RGZHJNXC.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-O7TCK5TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-GI3QVUGD.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-37F5EBPK.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-RMGXYNQJ.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-2VAAFCTS.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-67P4ME4N.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-MV3WQ4QF.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-6PCTL3MH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-7C5JICNL.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-FCDFBOMN.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-JVLUNKSG.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-KRKGC2U3.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Oe.push({name:"tar",load:async()=>(await import("./chunks/tar-LFENC54A.js")).tarCommand}),Oe.push({name:"yq",load:async()=>(await import("./chunks/yq-PFV4T2PV.js")).yqCommand}),Oe.push({name:"xan",load:async()=>(await import("./chunks/xan-5HNHTFMB.js")).xanCommand}),Oe.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-THMDBIGF.js")).sqlite3Command}));var Ir=[{name:"curl",load:async()=>(await import("./chunks/curl-TH7YRBSA.js")).curlCommand}],Qs=new Map;function Js(e){return{name:e.name,async execute(t,s){let n=Qs.get(e.name);return n||(n=await e.load(),Qs.set(e.name,n)),n.execute(t,s)}}}function en(e){return(e?Oe.filter(s=>e.includes(s.name)):Oe).map(Js)}function tn(){return Ir.map(Js)}function sn(e){return"load"in e&&typeof e.load=="function"}function nn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Tr=new TextEncoder,xr=new TextDecoder;function De(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Tr.encode(e)}function rt(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):xr.decode(e)}function $e(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var it=new TextEncoder;function Rr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Me=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))Rr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let a=$e(n),o=De(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=$e(s);return rt(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:it.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=$e(n),o=De(s,a);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:it.encode(i.content),f=new Uint8Array(l.length+o.length);f.set(l),f.set(o,l.length),this.data.set(r,{type:"file",content:f,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=it.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=it.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a<n.length-1;a++){let o=n[a];r=`${r}/${o}`;let l=this.data.get(r),f=0,c=40;for(;l&&l.type==="symlink"&&f<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),f++}if(f>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),l=0,f=40;for(;o&&o.type==="symlink"&&l<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,o.target),o=this.data.get(r),l++}if(l>=f)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==s&&o.startsWith(i)){let f=o.slice(i.length),c=f.split("/")[0];c&&!f.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.name<l.name?-1:o.name>l.name?1:0)}async rm(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let l of o){let f=r==="/"?`/${l}`:`${r}/${l}`,c=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(f,c,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function Lr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Wr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Fr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Mr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Fs}
|
|
2
|
+
import{B as Xs,C as Ys,D as se,E as Oe,F as K,G as ue,H as it,I as Qs,J as T,K as Js,L as en,M as me,N as zt,O as at,P as V,a as Vs,b as Bs,c as Hs,d as nt,e as q,f as F,g as he,h as Q,i as pe,j as Se,k as Rt,l as rt,m as js,n as Lt,o as Us,p as oe,q as we,r as qs,s as Zs,t as Wt,u as Mt,v as Ae,w as Gs,x as Ks,y as fe,z as Ft}from"./chunks/chunk-C6FK2JV3.js";import{a as $e,b as de}from"./chunks/chunk-4PRVMER6.js";import{a as re,b as ie,c as te,d as ae,e as Fs,f as z,g as ke,h as et,i as tt,j as zs,k as ee,l as Ee,m as st,n as ce}from"./chunks/chunk-K5IXNHO5.js";import"./chunks/chunk-OBH7XN5N.js";import{a as le}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import*as kr from"node:fs";import*as Or from"node:readline";var _e=[{name:"echo",load:async()=>(await import("./chunks/echo-7I42V66Q.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-HNXE2ES2.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-XPBSFXJE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5LN47VHU.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XMSNS6S5.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-OEMA5ZTD.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-IBPHJBM3.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-S7ASVG34.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-VFXCUKXO.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-P4KHB27X.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TYLTHXFR.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-L26WH2K4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TJHLLIMR.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YAUIERGN.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-CZ2TD6T6.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-ZZVPXHLF.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-RSDLLECO.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-JPDTWF4W.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-ASLLINAN.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-KUHOCH5S.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-NNXAFO6D.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-UCH462KK.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-FMT6JWLE.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-JJFZRWRC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-HQ4AK5DM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-XSKPK43X.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-PHDZK64M.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-WC3AXFHC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-PECPOFQT.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-56DL6SXU.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-M2WXBRXF.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-43KPK6TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZGXLP3DN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-F4NVQOJH.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-RMGXYNQJ.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-2VAAFCTS.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-67P4ME4N.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-MV3WQ4QF.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-6PCTL3MH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-7C5JICNL.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-5QEJAXNR.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-JVLUNKSG.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-KRKGC2U3.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(_e.push({name:"tar",load:async()=>(await import("./chunks/tar-LFENC54A.js")).tarCommand}),_e.push({name:"yq",load:async()=>(await import("./chunks/yq-JU6VN4X4.js")).yqCommand}),_e.push({name:"xan",load:async()=>(await import("./chunks/xan-OPVCJ3ZA.js")).xanCommand}),_e.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-THMDBIGF.js")).sqlite3Command}),_e.push({name:"python3",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).python3Command}),_e.push({name:"python",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).pythonCommand}));var xr=[{name:"curl",load:async()=>(await import("./chunks/curl-7IUASLUJ.js")).curlCommand}],tn=new Map;function sn(e){return{name:e.name,async execute(t,s){let n=tn.get(e.name);return n||(n=await e.load(),tn.set(e.name,n)),n.execute(t,s)}}}function nn(e){return(e?_e.filter(s=>e.includes(s.name)):_e).map(sn)}function rn(){return xr.map(sn)}function an(e){return"load"in e&&typeof e.load=="function"}function on(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Rr=new TextEncoder,Lr=new TextDecoder;function xe(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Rr.encode(e)}function ot(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Lr.decode(e)}function Ce(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var lt=new TextEncoder;function Wr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Be=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))Wr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let a=Ce(n),o=xe(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=Ce(s);return ot(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:lt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=Ce(n),o=xe(s,a);if(i?.type==="file"){let f=i.content instanceof Uint8Array?i.content:lt.encode(i.content),l=new Uint8Array(f.length+o.length);l.set(f),l.set(o,f.length),this.data.set(r,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=lt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=lt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a<n.length-1;a++){let o=n[a];r=`${r}/${o}`;let f=this.data.get(r),l=0,c=40;for(;f&&f.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,f.target),f=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),f=0,l=40;for(;o&&o.type==="symlink"&&f<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,o.target),o=this.data.get(r),f++}if(f>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,f]of this.data.entries())if(o!==s&&o.startsWith(i)){let l=o.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:f.type==="file",isDirectory:f.type==="directory",isSymbolicLink:f.type==="symlink"})}return Array.from(a.values()).sort((o,f)=>o.name<f.name?-1:o.name>f.name?1:0)}async rm(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let f of o){let l=r==="/"?`/${f}`:`${r}/${f}`,c=i==="/"?`/${f}`:`${i}/${f}`;await this.cp(l,c,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function Mr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Fr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function zr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Vr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Vs}
|
|
3
3
|
`),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
|
|
4
|
-
`),e.writeFileSync("/proc/self/status",
|
|
4
|
+
`),e.writeFileSync("/proc/self/status",Bs()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function ln(e,t){Mr(e)&&(Fr(e,t),zr(e),Vr(e))}var Br=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Hr=["braceexpand","hashall","interactive-comments"];function Vt(e){let t=[],s=[...Hr.map(n=>({name:n,enabled:!0})),...Br.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function Re(e){e.state.env.set("SHELLOPTS",Vt(e.state.options))}var jr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Bt(e){let t=[];for(let s of jr)e[s]&&t.push(s);return t.join(":")}function Ht(e){e.state.env.set("BASHOPTS",Bt(e.state.shoptOptions))}var Ur="BASH_ALIAS_";function cn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function fn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function un(e,t){return e.env.get(`${Ur}${t}`)}function jt(e,t,s){if(!t.name||!cn(t.name))return t;let n=fn(t.name);if(!n)return t;let r=un(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new F,a=r,o=r.endsWith(" ");if(!o)for(let u of t.args){let d=hn(u);a+=` ${d}`}let f;try{f=i.parse(a)}catch(u){if(u instanceof nt)throw u;return t}if(f.statements.length!==1||f.statements[0].pipelines.length!==1||f.statements[0].pipelines[0].commands.length!==1)return dn(t,r);let l=f.statements[0].pipelines[0].commands[0];if(l.type!=="SimpleCommand")return dn(t,r);let c={...l,assignments:[...t.assignments,...l.assignments],redirections:[...l.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let u=c.args[0];if(cn(u)){let d=fn(u);if(d&&un(e,d)){let h={type:"SimpleCommand",name:u,args:c.args.slice(1),assignments:[],redirections:[]},m=jt(e,h,s);m!==h&&(c={...c,name:m.name,args:[...m.args]})}}}return c}catch(i){throw s.delete(n),i}}function dn(e,t){let s=t;for(let a of e.args){let o=hn(a);s+=` ${o}`}let n=new F,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function hn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function pn(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",f=!1;for(let c of t.parts)if(c.type==="Literal"){let u=c.value;if(!a){let d=u.indexOf("=(");d!==-1&&(a=!0,u=u.slice(d+2))}if(a){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||f)&&(i.push(o),o="",f=!1):h&&(o+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=rt({type:"Word",parts:[c]});else{(o||f)&&(i.push(o),o="",f=!1);let d=await me(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(f=!0);let u=await T(e,{type:"Word",parts:[c]});o+=u}(o||f)&&i.push(o);let l=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${r}=(${l.join(" ")})`}async function mn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let v=g.value.indexOf("+=");if(v!==-1){let N=g.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)){s=p,n=v,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(N)){s=p,n=v,r=!0;break}}let $=g.value.indexOf("=");if($!==-1&&($===0||g.value[$-1]!=="+")){let N=g.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(N)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let o=r?2:1,f=a.value.slice(0,n),l=a.value.slice(n+o),c=t.parts.slice(s+1),u="";for(let p of i)u+=await T(e,{type:"Word",parts:[p]});u+=f;let d={type:"Word",parts:l!==""?[{type:"Literal",value:l},...c]:c},h=d.parts.length>0?await T(e,d):"";return`${u}${r?"+=":"="}${h}`}var qr=["tar","yq","xan","sqlite3","python3","python"];function yn(e){return qr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function W(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function U(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function ve(e,t,s="",n=""){throw new ee(e,t,s,n)}function Ut(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ee;return L}if(t.length>1)throw new z(1,"",`bash: break: too many arguments
|
|
5
5
|
`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(128,"",`bash: break: ${t[0]}: numeric argument required
|
|
6
|
-
`);s=n}throw new re(s)}async function
|
|
6
|
+
`);s=n}throw new re(s)}async function qt(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.get("HOME")||"/":a[0]==="-"?(s=e.state.previousDir,n=!0):s=a[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let u=e.state.env.get("CDPATH");if(u){let d=u.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,n=!0;break}}catch{}}}}let f=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(u=>u&&u!=="."),l="";for(let u of f)if(u==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${u}`:`/${u}`;try{if(!(await e.fs.stat(l)).isDirectory)return S(`bash: cd: ${s}: Not a directory
|
|
7
7
|
`)}catch{return S(`bash: cd: ${s}: No such file or directory
|
|
8
|
-
`)}}let c=
|
|
9
|
-
`:"")}function
|
|
10
|
-
`,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${
|
|
11
|
-
`,!1}return`${n}_${a}`
|
|
12
|
-
`,2):
|
|
13
|
-
`,2):_("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(
|
|
14
|
-
`,2):U(s.value)}async function
|
|
15
|
-
`)&&!n&&!r){a&&(t.push(s),s="",a=!1);continue}s+=o,a=!0}return a&&t.push(s),t}function
|
|
8
|
+
`)}}let c=l||"/";if(r)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),W(n?`${c}
|
|
9
|
+
`:"")}function Zt(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Zr=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function ct(e){return Zr.includes(e)}async function ft(e,t,s){let n=Zt(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var Gr=["-nt","-ot","-ef"];function ut(e){return Gr.includes(e)}async function dt(e,t,s,n){let r=Zt(e,s),i=Zt(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime<o.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,r),o=e.fs.resolvePath(e.state.cwd,i);return a===o}catch{return!1}default:return!1}}var Kr=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ht(e){return Kr.has(e)}function pt(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function He(e){return e==="="||e==="=="||e==="!="}function mt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=Le(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var Xr=new Set(["-z","-n"]);function yt(e){return Xr.has(e)}function gt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function wt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(f,l)=>e.state.env.get(l)||""),e.state.env.has(`${n}_${o}`)}let a;try{let o=new F,f=q(o,r);a=await V(e,f.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env.get(r);a=o?Number.parseInt(o,10):0}}if(a<0){let o=Q(e,n),f=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${n}: bad array subscript
|
|
10
|
+
`,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${n}: bad array subscript
|
|
11
|
+
`,!1}return e.state.env.has(`${n}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Se(e,t).length>0:Q(e,t).length>0}async function Pe(e,t){switch(t.type){case"CondBinary":{let s=await T(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await T(e,t.right);r=Ys(i)}else r=await Js(e,t.right);else He(t.operator)&&!n?r=await en(e,t.right):r=await T(e,t.right);if(He(t.operator)){let i=e.state.shoptOptions.nocasematch;return mt(t.operator,s,r,!n,i,!0)}if(ht(t.operator))return pt(t.operator,await wn(e,s),await wn(e,r));if(ut(t.operator))return dt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=ei(r),o=new RegExp(a,i?"i":""),f=s.match(o);if(pe(e,"BASH_REMATCH"),f)for(let l=0;l<f.length;l++)e.state.env.set(`BASH_REMATCH_${l}`,f[l]||"");return f!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await T(e,t.operand);return ct(t.operator)?ft(e,t.operator,s):yt(t.operator)?gt(t.operator,s):t.operator==="-v"?await wt(e,s):t.operator==="-o"?Kt(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await T(e,t.operand.expression.word)})`!=="":!await Pe(e,t.operand);case"CondAnd":return await Pe(e,t.left)?await Pe(e,t.right):!1;case"CondOr":return await Pe(e,t.left)?!0:await Pe(e,t.right);case"CondGroup":return await Pe(e,t.expression);case"CondWord":return await T(e,t.word)!=="";default:return!1}}async function je(e,t){if(t.length===0)return _("","",1);if(t.length===1)return U(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?S(`test: '(' without matching ')'
|
|
12
|
+
`,2):ct(n)?U(await ft(e,n,r)):yt(n)?U(gt(n,r)):n==="!"?U(!r):n==="-v"?U(await wt(e,r)):n==="-o"?U(Kt(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?S(`test: ${n}: unary operator expected
|
|
13
|
+
`,2):_("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(He(r))return U(mt(r,n,i));if(ht(r)){let a=vt(n),o=vt(i);return!a.valid||!o.valid?_("","",2):U(pt(r,a.value,o.value))}if(ut(r))return U(await dt(e,r,n,i));switch(r){case"-a":return U(n!==""&&i!=="");case"-o":return U(n!==""||i!=="");case">":return U(n>i);case"<":return U(n<i)}if(n==="!"){let a=await je(e,[r,i]);return _("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(n==="("&&i===")")return U(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await je(e,t.slice(1));return _("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return je(e,[t[1],t[2]])}let s=await bn(e,t,0);return s.pos<t.length?S(`test: too many arguments
|
|
14
|
+
`,2):U(s.value)}async function bn(e,t,s){return Yr(e,t,s)}async function Yr(e,t,s){let{value:n,pos:r}=await gn(e,t,s);for(;t[r]==="-o";){let i=await gn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function gn(e,t,s){let{value:n,pos:r}=await Gt(e,t,s);for(;t[r]==="-a";){let i=await Gt(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function Gt(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await Gt(e,t,s+1);return{value:!n,pos:r}}return Qr(e,t,s)}async function Qr(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:a}=await bn(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let r=t[s+1];if(He(r)){let i=n,a=t[s+2]??"";return{value:mt(r,i,a),pos:s+3}}if(ht(r)){let i=vt(n),a=vt(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:pt(r,i.value,a.value),pos:s+3}}if(ut(r)){let i=n,a=t[s+2]??"";return{value:await dt(e,r,i,a),pos:s+3}}if(ct(n)){let i=t[s+1]??"";return{value:await ft(e,n,i),pos:s+2}}if(yt(n)){let i=t[s+1]??"";return{value:gt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await wt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:Kt(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Le(e,t,s=!1,n=!1){let r=`^${En(t,n)}$`,i=s?"is":"s";return new RegExp(r,i).test(e)}function En(e,t){let s="";for(let n=0;n<e.length;n++){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=$n(e,n+1);if(i!==-1){let a=e.slice(n+2,i),o=Sn(a),f=o.map(c=>En(c,t)),l=f.length>0?f.join("|"):"(?:)";if(r==="@")s+=`(?:${l})`;else if(r==="*")s+=`(?:${l})*`;else if(r==="+")s+=`(?:${l})+`;else if(r==="?")s+=`(?:${l})?`;else if(r==="!")if(i<e.length-1){let u=o.map(h=>An(h,t));if(u.every(h=>h!==null)&&u.every(h=>h===u[0])&&u[0]!==null){let h=u[0];if(h===0)s+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${l})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${l})).)*?`}else s+=`(?!(?:${l})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function $n(e,t){let s=1,n=t+1;for(;n<e.length&&s>0;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function Sn(e){let t=[],s="",n=0,r=0;for(;r<e.length;){let i=e[r];if(i==="\\"){s+=i,r+1<e.length?(s+=e[r+1],r+=2):r++;continue}i==="("?(n++,s+=i):i===")"?(n--,s+=i):i==="|"&&n===0?(t.push(s),s=""):s+=i,r++}return t.push(s),t}function An(e,t){let s=0,n=0;for(;n<e.length;){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=$n(e,n+1);if(i!==-1){if(r==="@"){let a=e.slice(n+2,i),f=Sn(a).map(l=>An(l,t));if(f.every(l=>l!==null)&&f.every(l=>l===f[0])){s+=f[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Kt(e,t){let n=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return n?n():!1}async function wn(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return vn(t);try{let s=new F,n=q(s,t);return await V(e,n.expression)}catch{return vn(t)}}function Jr(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function vn(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=Jr(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function vt(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ei(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=ti(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function ti(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let a="",o=!1;for(;s<e.length;){let f=e[s];if(f==="]"){o=!0,s++;break}if(f==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l);a+=si(c),s=l+2;continue}}if(f==="["&&s+1<e.length){let l=e[s+1];if(l==="."||l==="="){let c=`${l}]`,u=e.indexOf(c,s+2);if(u!==-1){let d=e.slice(s+2,u);a+=d,s=u+2;continue}}}if(f==="\\"&&s+1<e.length){a+=f+e[s+1],s+=2;continue}a+=f,s++}return o?(r&&(n+="\\]"),i&&(n+="\\["),n+=a,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function si(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function ye(e){let t=[],s="",n=!1,r=!1,i=!1,a=!1;for(let o of e){if(i){s+=o,i=!1,a=!0;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!r){n||(a=!0),n=!n;continue}if(o==='"'&&!n){r||(a=!0),r=!r;continue}if((o===" "||o===" "||o===`
|
|
15
|
+
`)&&!n&&!r){a&&(t.push(s),s="",a=!1);continue}s+=o,a=!0}return a&&t.push(s),t}function bt(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)n+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)r+=e[s],s++;t.push([n,r])}return t}function _n(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ye(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let n=e.indexOf("=");return{name:e.slice(0,n),isArray:!1,value:e.slice(n+1)}}return{name:e,isArray:!1}}async function ni(e,t){try{let s=new F,n=q(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Cn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:f=!1,checkReadonly:l=!0}=s;if(l){let c=K(e,n);if(c)return c}if(r&&i){for(let c=0;c<i.length;c++)e.state.env.set(`${n}_${c}`,i[c]);e.state.env.set(`${n}__length`,String(i.length))}else if(o!==void 0&&a!==void 0){let c=await ni(e,o);e.state.env.set(`${n}_${c}`,a);let u=parseInt(e.state.env.get(`${n}__length`)??"0",10);c>=u&&e.state.env.set(`${n}__length`,String(c+1))}else a!==void 0&&e.state.env.set(n,a);return f&&se(e,n),null}function Ne(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function We(e,t){return e.state.localVarDepth?.get(t)}function Et(e,t){e.state.localVarDepth?.delete(t)}function Pn(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function $t(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Nn(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var Xt=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function kn(e){return Xt.has(e)}var Yt=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Ue=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function De(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
|
|
16
16
|
`;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
|
|
17
|
-
`}catch{}return null}function X(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function
|
|
18
|
-
`};s.set(n,await
|
|
17
|
+
`}catch{}return null}function X(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function ri(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),f=o.indexOf(":");if(f===-1)return null;let l=Number.parseInt(o.slice(0,f),10);if(Number.isNaN(l)||l<0)return null;let c=o.slice(f+1);return{path:i,position:l,content:c}}async function On(e,t){let s=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(r.target.type==="HereDoc")continue;if(r.operator===">&"||r.operator==="<&"){if(zt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
|
|
18
|
+
`};s.set(n,await T(e,r.target))}else{let a=await at(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function ii(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function St(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await T(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=ii(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await T(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&e.state.fileDescriptors.set(n,a);continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
|
|
19
19
|
`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);e.state.fileDescriptors.set(n,a)}catch{return _("",`bash: ${r}: No such file or directory
|
|
20
|
-
`,1)}}}return null}async function
|
|
20
|
+
`,1)}}}return null}async function ge(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await T(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await at(e,s.target);if("error"in o)return _("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";try{let o=await e.fs.stat(i);if(o.isDirectory)return _("",`bash: ${r}: Is a directory
|
|
21
21
|
`,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return _("",`bash: ${r}: cannot overwrite existing file
|
|
22
22
|
`,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return _("",`bash: /dev/full: No space left on device
|
|
23
|
-
`,1)}return null}async function
|
|
24
|
-
`,a=1,r="";continue}u=await
|
|
25
|
-
`,a=1,r="";break}let p=e.fs.resolvePath(e.state.cwd,u),g=await
|
|
26
|
-
`,a=1;break}if(u==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,u),g=await
|
|
27
|
-
`,a=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,u),p=await
|
|
28
|
-
`,a=1;break}let m=e.fs.resolvePath(e.state.cwd,u),p=await
|
|
29
|
-
`,a=1)}break}if(u==="2"||u==="&2")h===1&&(i+=r,r="");else if(u==="1"||u==="&1")r+=i,i="";else{let m=Number.parseInt(u,10);if(Number.isNaN(m)){if(c.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,u),g=await
|
|
23
|
+
`,1)}return null}async function B(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t;for(let l=0;l<s.length;l++){let c=s[l];if(c.target.type==="HereDoc")continue;let u,d=n?.get(l);if(d!==void 0)u=d;else if(c.operator===">&"||c.operator==="<&"){if(zt(e,c.target)){i+=`bash: $@: ambiguous redirect
|
|
24
|
+
`,a=1,r="";continue}u=await T(e,c.target)}else{let m=await at(e,c.target);if("error"in m){i+=m.error,a=1,r="";continue}u=m.target}if(!c.fdVariable)switch(c.operator){case">":case">|":{let h=c.fd??1,m=c.operator===">|";if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
25
|
+
`,a=1,r="";break}let p=e.fs.resolvePath(e.state.cwd,u),g=await De(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1,r="";break}await e.fs.writeFile(p,r,X(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
26
|
+
`,a=1;break}if(u==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,u),g=await De(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1;break}await e.fs.writeFile(p,i,X(i)),i=""}}break}case">>":{let h=c.fd??1;if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
27
|
+
`,a=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,u),p=await De(e,m,u,{});if(p){i+=p,a=1,r="";break}await e.fs.appendFile(m,r,X(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
28
|
+
`,a=1;break}let m=e.fs.resolvePath(e.state.cwd,u),p=await De(e,m,u,{});if(p){i+=p,a=1;break}await e.fs.appendFile(m,i,X(i)),i=""}break}case">&":case"<&":{let h=c.fd??1;if(u==="-")break;if(u.endsWith("-")){let m=u.slice(0,-1),p=Number.parseInt(m,10);if(!Number.isNaN(p)){let g=e.state.fileDescriptors?.get(p);g!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,g),p>=3&&e.state.fileDescriptors?.delete(p)):p===1||p===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupout__:${p}`)):p===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupin__:${p}`)):p>=3&&(i+=`bash: ${p}: Bad file descriptor
|
|
29
|
+
`,a=1)}break}if(u==="2"||u==="&2")h===1&&(i+=r,r="");else if(u==="1"||u==="&1")r+=i,i="";else{let m=Number.parseInt(u,10);if(Number.isNaN(m)){if(c.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,u),g=await De(e,p,u,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}if(c.fd==null){let v=r+i;await e.fs.writeFile(p,v,X(v)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,X(r)),r=""):h===2&&(await e.fs.writeFile(p,i,X(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let g=p.slice(9);h===1?(await e.fs.appendFile(g,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g,i,X(i)),i="")}else if(p?.startsWith("__rw__:")){let g=ri(p);g&&(h===1?(await e.fs.appendFile(g.path,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g.path,i,X(i)),i=""))}else if(p?.startsWith("__dupout__:")){let g=Number.parseInt(p.slice(11),10);if(g!==1)if(g===2)h===1&&(i+=r,r="");else{let v=e.state.fileDescriptors?.get(g);if(v?.startsWith("__file__:")){let $=v.slice(9);h===1?(await e.fs.appendFile($,r,X(r)),r=""):h===2&&(await e.fs.appendFile($,i,X(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
|
|
30
30
|
`,a=1,r=""):m>=3&&(i+=`bash: ${m}: Bad file descriptor
|
|
31
31
|
`,a=1,r="")}}break}case"&>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
|
|
32
|
-
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await
|
|
33
|
-
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await
|
|
34
|
-
`;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function
|
|
32
|
+
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await De(e,h,u,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.writeFile(h,p,X(p)),r="",i="";break}case"&>>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
|
|
33
|
+
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await De(e,h,u,{});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.appendFile(h,p,X(p)),r="",i="";break}}}let o=e.state.fileDescriptors?.get(1);if(o){if(o==="__dupout__:2")i+=r,r="";else if(o.startsWith("__file__:")){let l=o.slice(9);await e.fs.appendFile(l,r,X(r)),r=""}else if(o.startsWith("__file_append__:")){let l=o.slice(16);await e.fs.appendFile(l,r,X(r)),r=""}}let f=e.state.fileDescriptors?.get(2);if(f){if(f==="__dupout__:1")r+=i,i="";else if(f.startsWith("__file__:")){let l=f.slice(9);await e.fs.appendFile(l,i,X(i)),i=""}else if(f.startsWith("__file_append__:")){let l=f.slice(16);await e.fs.appendFile(l,i,X(i)),i=""}}return _(r,i,a)}function Dn(e,t){if(e.state.options.posix&&Xt.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
|
|
34
|
+
`;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function ai(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await T(e,r.content);r.stripTabs&&(i=i.split(`
|
|
35
35
|
`).map(o=>o.replace(/^\t+/,"")).join(`
|
|
36
|
-
`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await
|
|
37
|
-
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await
|
|
38
|
-
`,2);let
|
|
39
|
-
`,2);s.push(
|
|
36
|
+
`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await T(e,n.target)}
|
|
37
|
+
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function At(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,ve(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let l=0;l<s.length;l++)i.set(String(l+1),e.state.env.get(String(l+1))),e.state.env.set(String(l+1),s[l]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let a=()=>{let l=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[u,d]of c)d===void 0?e.state.env.delete(u):e.state.env.set(u,d);if(Nn(e,l),e.state.fullyUnsetLocals)for(let[u,d]of e.state.fullyUnsetLocals.entries())d===l&&e.state.fullyUnsetLocals.delete(u);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let u=e.state.localExportedVars.pop();if(u)for(let d of u)e.state.exportedVars?.delete(d)}for(let[u,d]of i)d===void 0?e.state.env.delete(u):e.state.env.set(u,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:o,error:f}=await On(e,t.redirections);if(f)return a(),_("",f,1);try{let l=await ai(e,t.redirections),c=n||l,u=await e.executeCommand(t.body,c);return a(),B(e,u,t.redirections,o)}catch(l){if(a(),l instanceof te){let c=_(l.stdout,l.stderr,l.exitCode);return B(e,c,t.redirections,o)}throw l}}var Tn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Jt=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],oi=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],li=Jt;async function es(e,t){let s=[],n=null,r="",i="",a=null,o=!1,f=!1,l=!1,c=null,u=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let w=t[y];if(w==="-v")s.push("variable");else if(w==="-e")s.push("export");else if(w==="-f")s.push("file");else if(w==="-d")s.push("directory");else if(w==="-k")s.push("keyword");else if(w==="-A"){if(y++,y>=t.length)return S(`compgen: -A: option requires an argument
|
|
38
|
+
`,2);let b=t[y];if(!m.includes(b))return S(`compgen: ${b}: invalid action name
|
|
39
|
+
`,2);s.push(b)}else if(w==="-W"){if(y++,y>=t.length)return S(`compgen: -W: option requires an argument
|
|
40
40
|
`,2);n=t[y]}else if(w==="-P"){if(y++,y>=t.length)return S(`compgen: -P: option requires an argument
|
|
41
41
|
`,2);r=t[y]}else if(w==="-S"){if(y++,y>=t.length)return S(`compgen: -S: option requires an argument
|
|
42
42
|
`,2);i=t[y]}else if(w==="-o"){if(y++,y>=t.length)return S(`compgen: -o: option requires an argument
|
|
43
|
-
`,2);let
|
|
43
|
+
`,2);let b=t[y];if(b==="plusdirs")o=!0;else if(b==="dirnames")f=!0;else if(b==="default")l=!0;else if(!(b==="filenames"||b==="nospace"||b==="bashdefault"||b==="noquote"))return S(`compgen: ${b}: invalid option name
|
|
44
44
|
`,2)}else if(w==="-F"){if(y++,y>=t.length)return S(`compgen: -F: option requires an argument
|
|
45
45
|
`,2);u=t[y]}else if(w==="-C"){if(y++,y>=t.length)return S(`compgen: -C: option requires an argument
|
|
46
46
|
`,2);d=t[y]}else if(w==="-X"){if(y++,y>=t.length)return S(`compgen: -X: option requires an argument
|
|
47
47
|
`,2);c=t[y]}else if(w==="-G"){if(y++,y>=t.length)return S(`compgen: -G: option requires an argument
|
|
48
|
-
`,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}a=h[0]??null;let p=[];if(
|
|
49
|
-
`);for(let C of
|
|
50
|
-
`,2);throw y}let
|
|
48
|
+
`,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}a=h[0]??null;let p=[];if(f){let y=await Qt(e,a);p.push(...y)}if(l){let y=await In(e,a);p.push(...y)}for(let y of s)if(y==="variable"){let w=ci(e,a);p.push(...w)}else if(y==="export"){let w=fi(e,a);p.push(...w)}else if(y==="function"){let w=ui(e,a);p.push(...w)}else if(y==="builtin"){let w=di(a);p.push(...w)}else if(y==="keyword"){let w=hi(a);p.push(...w)}else if(y==="alias"){let w=pi(e,a);p.push(...w)}else if(y==="shopt"){let w=mi(a);p.push(...w)}else if(y==="helptopic"){let w=yi(a);p.push(...w)}else if(y==="directory"){let w=await Qt(e,a);p.push(...w)}else if(y==="file"){let w=await In(e,a);p.push(...w)}else if(y==="user"){let w=gi(a);p.push(...w)}else if(y==="command"){let w=await wi(e,a);p.push(...w)}if(n!==null)try{let y=await vi(e,n),w=bi(e,y);for(let b of w)(a===null||b.startsWith(a))&&p.push(b)}catch{return _("","",1)}if(o){let y=await Qt(e,a);for(let w of y)p.includes(w)||p.push(w)}let g="";if(u!==null){let y=e.state.functions.get(u);if(y){let w=new Map;w.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),w.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),w.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),w.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let b=new Map;for(let O of e.state.env.keys())(O==="COMPREPLY"||O.startsWith("COMPREPLY_")||O==="COMPREPLY__length")&&(b.set(O,e.state.env.get(O)),e.state.env.delete(O));let C=["compgen",h[0]??"",""];try{let O=await At(e,y,C,"");if(O.exitCode!==0)return Me(e,w),Me(e,b),_("",O.stderr,1);g=O.stdout;let D=Ei(e);p.push(...D)}catch{return Me(e,w),Me(e,b),_("","",1)}Me(e,w),Me(e,b)}}if(d!==null)try{let y=he(d),w=await e.executeScript(y);if(w.exitCode!==0)return _("",w.stderr,w.exitCode);if(w.stdout){let b=w.stdout.split(`
|
|
49
|
+
`);for(let C of b)C.length>0&&p.push(C)}}catch(y){if(y.name==="ParseException")return S(`compgen: -C: ${y.message}
|
|
50
|
+
`,2);throw y}let v=p;if(c!==null){let y=c.startsWith("!"),w=y?c.slice(1):c;v=p.filter(b=>{let C=Le(b,w,!1,!0);return y?C:!C})}if(v.length===0&&a!==null)return _(g,"",1);let $=v.map(y=>`${r}${y}${i}`).join(`
|
|
51
51
|
`),N=g+($?`${$}
|
|
52
|
-
`:"");return W(N)}function
|
|
53
|
-
`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a<t.length;){let o=t[a];if(o==="\\"&&a+1<t.length){let
|
|
52
|
+
`:"");return W(N)}function ci(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function fi(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function ui(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function di(e){let t=[...Jt];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function hi(e){let t=[...Tn];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function pi(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function mi(e){let t=[...oi];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function yi(e){let t=[...li];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Qt(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function In(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),f=t.slice(0,o+1);s.push(f+a)}else s.push(a)}catch{}return s.sort()}function gi(e){return["root","nobody"]}async function wi(e,t){let s=new Set;for(let i of Jt)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Tn)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function vi(e,t){let n=new F().parseWordFromString(t,!1,!1);return await T(e,n)}function bi(e,t){let s=e.state.env.get("IFS")??`
|
|
53
|
+
`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a<t.length;){let o=t[a];if(o==="\\"&&a+1<t.length){let f=t[a+1];i+=f,a+=2}else n.has(o)?(i.length>0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function Me(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function Ei(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=fe(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else{let r=e.state.env.get("COMPREPLY");r!==void 0&&t.push(r)}return t}var $i=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ss(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,f=[],l=[],c=[];for(let u=0;u<t.length;u++){let d=t[u];if(d==="-p")s=!0;else if(d==="-r")n=!0;else if(d==="-D")r=!0;else if(d==="-W"){if(u++,u>=t.length)return S(`complete: -W: option requires an argument
|
|
54
54
|
`,2);i=t[u]}else if(d==="-F"){if(u++,u>=t.length)return S(`complete: -F: option requires an argument
|
|
55
55
|
`,2);a=t[u]}else if(d==="-o"){if(u++,u>=t.length)return S(`complete: -o: option requires an argument
|
|
56
|
-
`,2);let h=t[u];if(
|
|
57
|
-
`,2);
|
|
58
|
-
`,2);
|
|
56
|
+
`,2);let h=t[u];if(!$i.includes(h))return S(`complete: ${h}: invalid option name
|
|
57
|
+
`,2);f.push(h)}else if(d==="-A"){if(u++,u>=t.length)return S(`complete: -A: option requires an argument
|
|
58
|
+
`,2);l.push(t[u])}else if(d==="-C"){if(u++,u>=t.length)return S(`complete: -C: option requires an argument
|
|
59
59
|
`,2);o=t[u]}else if(d==="-G"){if(u++,u>=t.length)return S(`complete: -G: option requires an argument
|
|
60
60
|
`,2)}else if(d==="-P"){if(u++,u>=t.length)return S(`complete: -P: option requires an argument
|
|
61
61
|
`,2)}else if(d==="-S"){if(u++,u>=t.length)return S(`complete: -S: option requires an argument
|
|
62
62
|
`,2)}else if(d==="-X"){if(u++,u>=t.length)return S(`complete: -X: option requires an argument
|
|
63
|
-
`,2)}else if(d==="--"){c.push(...t.slice(u+1));break}else d.startsWith("-")||c.push(d)}if(n){if(c.length===0)return e.state.completionSpecs.clear(),W("");for(let u of c)e.state.completionSpecs.delete(u);return W("")}if(s)return c.length===0?
|
|
64
|
-
`,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),a!==void 0&&(u.function=a),o!==void 0&&(u.command=o),
|
|
63
|
+
`,2)}else if(d==="--"){c.push(...t.slice(u+1));break}else d.startsWith("-")||c.push(d)}if(n){if(c.length===0)return e.state.completionSpecs.clear(),W("");for(let u of c)e.state.completionSpecs.delete(u);return W("")}if(s)return c.length===0?ts(e):ts(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&f.length===0&&l.length===0&&!r)return ts(e);if(a&&c.length===0&&!r)return S(`complete: -F: option requires a command name
|
|
64
|
+
`,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),a!==void 0&&(u.function=a),o!==void 0&&(u.command=o),f.length>0&&(u.options=f),l.length>0&&(u.actions=l),e.state.completionSpecs.set("__default__",u),W("")}for(let u of c){let d={};i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),f.length>0&&(d.options=f),l.length>0&&(d.actions=l),e.state.completionSpecs.set(u,d)}return W("")}function ts(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
|
|
65
65
|
`;return _("",i,1)}return W("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return _(n.join(`
|
|
66
66
|
`)+(n.length>0?`
|
|
67
67
|
`:""),`complete: ${i}: no completion specification
|
|
68
|
-
`,1);continue}let o="complete";if(a.options)for(let
|
|
68
|
+
`,1);continue}let o="complete";if(a.options)for(let f of a.options)o+=` -o ${f}`;if(a.actions)for(let f of a.actions)o+=` -A ${f}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?W(""):W(`${n.join(`
|
|
69
69
|
`)}
|
|
70
|
-
`)}var
|
|
71
|
-
`,2);let
|
|
72
|
-
`,2);r.push(
|
|
73
|
-
`,2);let
|
|
74
|
-
`,2);i.push(
|
|
75
|
-
`,1)}function
|
|
70
|
+
`)}var xn=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ns(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o<t.length;o++){let f=t[o];if(f==="-D")s=!0;else if(f==="-E")n=!0;else if(f==="-o"){if(o++,o>=t.length)return S(`compopt: -o: option requires an argument
|
|
71
|
+
`,2);let l=t[o];if(!xn.includes(l))return S(`compopt: ${l}: invalid option name
|
|
72
|
+
`,2);r.push(l)}else if(f==="+o"){if(o++,o>=t.length)return S(`compopt: +o: option requires an argument
|
|
73
|
+
`,2);let l=t[o];if(!xn.includes(l))return S(`compopt: ${l}: invalid option name
|
|
74
|
+
`,2);i.push(l)}else if(f==="--"){a.push(...t.slice(o+1));break}else!f.startsWith("-")&&!f.startsWith("+")&&a.push(f)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},f=new Set(o.options??[]);for(let l of r)f.add(l);for(let l of i)f.delete(l);return o.options=f.size>0?Array.from(f):void 0,e.state.completionSpecs.set("__default__",o),W("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},f=new Set(o.options??[]);for(let l of r)f.add(l);for(let l of i)f.delete(l);return o.options=f.size>0?Array.from(f):void 0,e.state.completionSpecs.set("__empty__",o),W("")}if(a.length>0){for(let o of a){let f=e.state.completionSpecs.get(o)??{},l=new Set(f.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);f.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set(o,f)}return W("")}return S(`compopt: not currently executing completion function
|
|
75
|
+
`,1)}function rs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ee;return L}if(t.length>1)throw new z(1,"",`bash: continue: too many arguments
|
|
76
76
|
`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(1,"",`bash: continue: ${t[0]}: numeric argument required
|
|
77
|
-
`);s=n}throw new ie(s)}function
|
|
78
|
-
`;else{let u=c.map(d=>{let h=e.state.env
|
|
79
|
-
`}continue}let
|
|
80
|
-
`;continue}if(e.state.env
|
|
81
|
-
`;continue}let
|
|
77
|
+
`);s=n}throw new ie(s)}function H(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function is(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function as(e){let t="$'";for(let s=0;s<e.length;s++){let n=e[s],r=e.charCodeAt(s);r===7?t+="\\a":r===8?t+="\\b":r===9?t+="\\t":r===10?t+="\\n":r===11?t+="\\v":r===12?t+="\\f":r===13?t+="\\r":r===27?t+="\\e":r===39?t+="\\'":r===92?t+="\\\\":r<32||r===127?t+=`\\${r.toString(8).padStart(3,"0")}`:t+=n}return t+="'",t}function _t(e){return is(e)?as(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ie(e){return is(e)?as(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function os(e){return is(e)?as(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Rn(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),oe(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function ls(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Ln(e,t){let s="",n="",r=!1;for(let i of t){let a=Rn(e,i);if(e.state.associativeArrays?.has(i)){let c=Se(e,i);if(c.length===0)s+=`declare -A ${i}=()
|
|
78
|
+
`;else{let u=c.map(d=>{let h=e.state.env.get(`${i}_${d}`)??"",m=ls(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${u.join(" ")})
|
|
79
|
+
`}continue}let f=Q(e,i);if(f.length>0){let c=f.map(u=>{let d=e.state.env.get(`${i}_${u}`)??"";return`[${u}]=${Ie(d)}`});s+=`declare -a ${i}=(${c.join(" ")})
|
|
80
|
+
`;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=()
|
|
81
|
+
`;continue}let l=e.state.env.get(i);if(l!==void 0)s+=`declare ${a} ${i}=${os(l)}
|
|
82
82
|
`;else{let c=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);c||u?s+=`declare ${a} ${i}
|
|
83
83
|
`:(n+=`bash: declare: ${i}: not found
|
|
84
|
-
`,r=!0)}}return _(s,n,r?1:0)}function
|
|
85
|
-
`;else{let $=
|
|
86
|
-
`}continue}if(m.length>0){let
|
|
87
|
-
`;continue}if(e.state.env
|
|
88
|
-
`;continue}let g=e.state.env
|
|
89
|
-
`)}return W(
|
|
90
|
-
`;else{let i=r.map(a=>{let o=e.state.env
|
|
91
|
-
`}}return W(t)}function
|
|
92
|
-
`;else{let a=i.map(o=>{let
|
|
93
|
-
`}}return W(t)}function
|
|
94
|
-
`)}return W(t)}function
|
|
84
|
+
`,r=!0)}}return _(s,n,r?1:0)}function Wn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,f="",l=new Set;for(let u of e.state.env.keys()){if(u.startsWith("BASH_"))continue;if(u.endsWith("__length")){let h=u.slice(0,-8);l.add(h);continue}let d=u.lastIndexOf("_");if(d>0){let h=u.slice(0,d),m=u.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){l.add(h);continue}}l.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())l.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)l.add(u);let c=Array.from(l).sort();for(let u of c){let d=Rn(e,u),h=e.state.associativeArrays?.has(u),m=Q(e,u),p=!h&&(m.length>0||e.state.env.has(`${u}__length`));if(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!oe(e,u)))continue;if(h){let v=Se(e,u);if(v.length===0)f+=`declare -A ${u}=()
|
|
85
|
+
`;else{let $=v.map(N=>{let y=e.state.env.get(`${u}_${N}`)??"",w=ls(y);return`['${N}']=${w}`});f+=`declare -A ${u}=(${$.join(" ")})
|
|
86
|
+
`}continue}if(m.length>0){let v=m.map($=>{let N=e.state.env.get(`${u}_${$}`)??"";return`[${$}]=${Ie(N)}`});f+=`declare -a ${u}=(${v.join(" ")})
|
|
87
|
+
`;continue}if(e.state.env.has(`${u}__length`)){f+=`declare -a ${u}=()
|
|
88
|
+
`;continue}let g=e.state.env.get(u);g!==void 0&&(f+=`declare ${d} ${u}=${os(g)}
|
|
89
|
+
`)}return W(f)}function Mn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Se(e,n);if(r.length===0)t+=`declare -A ${n}=()
|
|
90
|
+
`;else{let i=r.map(a=>{let o=e.state.env.get(`${n}_${a}`)??"",f=ls(o);return`['${a}']=${f}`});t+=`declare -A ${n}=(${i.join(" ")})
|
|
91
|
+
`}}return W(t)}function Fn(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=Q(e,r);if(i.length===0)t+=`declare -a ${r}=()
|
|
92
|
+
`;else{let a=i.map(o=>{let f=e.state.env.get(`${r}_${o}`)??"";return`[${o}]=${Ie(f)}`});t+=`declare -a ${r}=(${a.join(" ")})
|
|
93
|
+
`}}return W(t)}function zn(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||Q(e,r).length>0||e.state.env.has(`${r}__length`))continue;let o=e.state.env.get(r);o!==void 0&&(t+=`${r}=${_t(o)}
|
|
94
|
+
`)}return W(t)}function cs(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function qe(e,t){return e.state.integerVars?.has(t)??!1}function fs(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Si(e,t){return e.state.lowercaseVars?.has(t)??!1}function us(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Ai(e,t){return e.state.uppercaseVars?.has(t)??!1}function Fe(e,t,s){return Si(e,t)?s.toLowerCase():Ai(e,t)?s.toUpperCase():s}async function Vn(e,t){try{let s=new F,n=q(s,t),r=await V(e,n.expression);return String(r)}catch{return"0"}}function _i(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let a=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let o=e.slice(n);return{name:s,indexExpr:a,value:o}}async function ds(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=!1,f=!1,l=!1,c=!1,u=!1,d=!1,h=!1,m=!1,p=!1,g=!1,v=[];for(let D=0;D<t.length;D++){let x=t[D];if(x==="-a")s=!0;else if(x==="-A")n=!0;else if(x==="-r")r=!0;else if(x==="-x")i=!0;else if(x==="-p")a=!0;else if(x==="-n")o=!0;else if(x==="+n")f=!0;else if(x==="+a")l=!0;else if(x==="+x")c=!0;else if(x==="--"){v.push(...t.slice(D+1));break}else if(x.startsWith("+")){for(let A of x.slice(1))if(A==="n")f=!0;else if(A==="a")l=!0;else if(A==="x")c=!0;else if(A!=="r"){if(A!=="i"){if(!(A==="f"||A==="F"))return _("",`bash: typeset: +${A}: invalid option
|
|
95
95
|
`,2)}}}else if(x==="-i")u=!0;else if(x==="-l")d=!0;else if(x==="-u")h=!0;else if(x==="-f")m=!0;else if(x==="-F")p=!0;else if(x==="-g")g=!0;else if(x.startsWith("-"))for(let A of x.slice(1))if(A==="a")s=!0;else if(A==="A")n=!0;else if(A==="r")r=!0;else if(A==="x")i=!0;else if(A==="p")a=!0;else if(A==="n")o=!0;else if(A==="i")u=!0;else if(A==="l")d=!0;else if(A==="u")h=!0;else if(A==="f")m=!0;else if(A==="F")p=!0;else if(A==="g")g=!0;else return _("",`bash: typeset: -${A}: invalid option
|
|
96
|
-
`,2);else
|
|
97
|
-
`;return W(P)}let
|
|
98
|
-
`:
|
|
96
|
+
`,2);else v.push(x)}let N=e.state.localScopes.length>0&&!g,y=D=>{if(!N)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(D)||x.set(D,e.state.env.get(D))},w=D=>{if(!N)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(D)||x.set(D,e.state.env.get(D));let A=`${D}_`;for(let I of e.state.env.keys())I.startsWith(A)&&!I.includes("__")&&(x.has(I)||x.set(I,e.state.env.get(I)));let P=`${D}__length`;e.state.env.has(P)&&!x.has(P)&&x.set(P,e.state.env.get(P))},b=D=>{N&&Ne(e,D)};if(p){if(v.length===0){let A=Array.from(e.state.functions.keys()).sort(),P="";for(let I of A)P+=`declare -f ${I}
|
|
97
|
+
`;return W(P)}let D=!0,x="";for(let A of v)e.state.functions.has(A)?x+=`${A}
|
|
98
|
+
`:D=!1;return _(x,"",D?0:1)}if(m){if(v.length===0){let x="",A=Array.from(e.state.functions.keys()).sort();for(let P of A)x+=`${P} ()
|
|
99
99
|
{
|
|
100
100
|
# function body
|
|
101
101
|
}
|
|
102
|
-
`;return W(x)}let
|
|
103
|
-
`,
|
|
104
|
-
`,
|
|
105
|
-
`,
|
|
106
|
-
`,
|
|
107
|
-
`,
|
|
108
|
-
`,
|
|
109
|
-
`}}return W(a)}for(let a of i){let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(o){let u=o[1],d=o[2],h=K(e,u);if(h)return h;let m=
|
|
110
|
-
`,2);n=t[o+1],o++}}else{if(
|
|
102
|
+
`;return W(x)}let D=!0;for(let x of v)e.state.functions.has(x)||(D=!1);return _("","",D?0:1)}if(a&&v.length>0)return Ln(e,v);if(a&&v.length===0)return Wn(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if(v.length===0&&n&&!a)return Mn(e);if(v.length===0&&s&&!a)return Fn(e);if(v.length===0&&!a)return zn(e);let C="",O=0;for(let D of v){let x=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(x&&!l){let E=x[1],k=x[2];if(n&&Q(e,E).length>0){C+=`bash: declare: ${E}: cannot convert indexed to associative array
|
|
103
|
+
`,O=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(E)){C+=`bash: declare: ${E}: cannot convert associative to indexed array
|
|
104
|
+
`,O=1;continue}if(w(E),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)),pe(e,E),e.state.env.delete(E),e.state.env.delete(`${E}__length`),n&&k.includes("[")){let R=bt(k);for(let[G,M]of R){let j=H(e,M);e.state.env.set(`${E}_${G}`,j)}}else if(n){let R=ye(k);for(let G=0;G<R.length;G+=2){let M=R[G],j=G+1<R.length?H(e,R[G+1]):"";e.state.env.set(`${E}_${M}`,j)}}else{let R=ye(k);if(R.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let j of R){let J=j.match(/^\[([^\]]+)\]=(.*)$/);if(J){let ne=J[1],Te=J[2],Dr=H(e,Te),Ve;if(/^-?\d+$/.test(ne))Ve=Number.parseInt(ne,10);else try{let Ir=new F,Tr=q(Ir,ne);Ve=await V(e,Tr.expression)}catch{Ve=0}e.state.env.set(`${E}_${Ve}`,Dr),M=Ve+1}else{let ne=H(e,j);e.state.env.set(`${E}_${M}`,ne),M++}}}else{for(let M=0;M<R.length;M++)e.state.env.set(`${E}_${M}`,R[M]);e.state.env.set(`${E}__length`,String(R.length))}}b(E),r&&se(e,E),i&&ue(e,E);continue}if(f){let E=D.includes("=")?D.slice(0,D.indexOf("=")):D;if(qs(e,E),!D.includes("="))continue}if(c){let E=D.includes("=")?D.slice(0,D.indexOf("=")):D;if(it(e,E),!D.includes("="))continue}let A=_i(D);if(A){let{name:E,indexExpr:k,value:R}=A,G=K(e,E);if(G)return G;w(E);let M;try{let J=new F,ne=q(J,k);M=await V(e,ne.expression)}catch{let J=parseInt(k,10);M=Number.isNaN(J)?0:J}e.state.env.set(`${E}_${M}`,R);let j=parseInt(e.state.env.get(`${E}__length`)??"0",10);M>=j&&e.state.env.set(`${E}__length`,String(M+1)),b(E),r&&se(e,E),i&&ue(e,E);continue}let P=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(P&&!l){let E=P[1],k=P[2],R=K(e,E);if(R)return R;w(E);let G=ye(k);if(e.state.associativeArrays?.has(E)){let M=bt(k);for(let[j,J]of M){let ne=H(e,J);e.state.env.set(`${E}_${j}`,ne)}}else{let M=Q(e,E),j=0,J=e.state.env.get(E);M.length===0&&J!==void 0?(e.state.env.set(`${E}_0`,J),e.state.env.delete(E),j=1):M.length>0&&(j=Math.max(...M)+1);for(let Te=0;Te<G.length;Te++)e.state.env.set(`${E}_${j+Te}`,H(e,G[Te]));let ne=j+G.length;e.state.env.set(`${E}__length`,String(ne))}b(E),r&&se(e,E),i&&ue(e,E);continue}let I=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(I){let E=I[1],k=H(e,I[2]),R=K(e,E);if(R)return R;y(E),u&&cs(e,E),d&&fs(e,E),h&&us(e,E);let M=Q(e,E).length>0||e.state.associativeArrays?.has(E);if(qe(e,E)){let j=e.state.env.get(E)??"0",J=parseInt(j,10)||0,ne=parseInt(await Vn(e,k),10)||0;k=String(J+ne),e.state.env.set(E,k)}else if(M){k=Fe(e,E,k);let j=`${E}_0`,J=e.state.env.get(j)??"";e.state.env.set(j,J+k)}else{k=Fe(e,E,k);let j=e.state.env.get(E)??"";e.state.env.set(E,j+k)}b(E),r&&se(e,E),i&&ue(e,E),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(E));continue}if(D.includes("=")){let E=D.indexOf("="),k=D.slice(0,E),R=D.slice(E+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){C+=`bash: typeset: \`${k}': not a valid identifier
|
|
105
|
+
`,O=1;continue}let G=K(e,k);if(G)return G;if(y(k),o){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){C+=`bash: declare: \`${R}': invalid variable name for name reference
|
|
106
|
+
`,O=1;continue}e.state.env.set(k,R),we(e,k),R!==""&&Mt(e,R)&&Wt(e,k),b(k),r&&se(e,k),i&&ue(e,k);continue}if(u&&cs(e,k),d&&fs(e,k),h&&us(e,k),qe(e,k)&&(R=await Vn(e,R)),R=Fe(e,k,R),oe(e,k)){let M=Ae(e,k);M&&M!==k?e.state.env.set(M,R):e.state.env.set(k,R)}else e.state.env.set(k,R);b(k),r&&se(e,k),i&&ue(e,k),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(k))}else{let E=D;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){C+=`bash: typeset: \`${E}': not a valid identifier
|
|
107
|
+
`,O=1;continue}if(s||n?w(E):y(E),o){we(e,E);let R=e.state.env.get(E);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?Zs(e,E):R&&Mt(e,R)&&Wt(e,E),b(E),r&&se(e,E),i&&ue(e,E);continue}if(u&&cs(e,E),d&&fs(e,E),h&&us(e,E),n){if(Q(e,E).length>0){C+=`bash: declare: ${E}: cannot convert indexed to associative array
|
|
108
|
+
`,O=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)}let k=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${E}_`)&&!R.startsWith(`${E}__length`));!e.state.env.has(E)&&!k&&(s||n?e.state.env.set(`${E}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(E))),b(E),r&&se(e,E),i&&ue(e,E)}}return _("",C,O)}async function hs(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a<t.length;a++){let o=t[a];if(o==="-a")s=!0;else if(o==="-A")n=!0;else if(o==="-p")r=!0;else if(o==="--"){i.push(...t.slice(a+1));break}else o.startsWith("-")||i.push(o)}if(i.length===0){let a="",o=Array.from(e.state.readonlyVars||[]).sort();for(let f of o){let l=e.state.env.get(f);if(l!==void 0){let c=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${f}="${c}"
|
|
109
|
+
`}}return W(a)}for(let a of i){let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(o){let u=o[1],d=o[2],h=K(e,u);if(h)return h;let m=ye(d);if(e.state.associativeArrays?.has(u)){let p=bt(d);for(let[g,v]of p){let $=H(e,v);e.state.env.set(`${u}_${g}`,$)}}else{let p=Q(e,u),g=0,v=e.state.env.get(u);p.length===0&&v!==void 0?(e.state.env.set(`${u}_0`,v),e.state.env.delete(u),g=1):p.length>0&&(g=Math.max(...p)+1);for(let N=0;N<m.length;N++)e.state.env.set(`${u}_${g+N}`,H(e,m[N]));let $=g+m.length;e.state.env.set(`${u}__length`,String($))}se(e,u);continue}let f=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(f){let u=f[1],d=H(e,f[2]),h=K(e,u);if(h)return h;let m=e.state.env.get(u)??"";e.state.env.set(u,m+d),se(e,u);continue}let l=_n(a);if(l.value===void 0&&!l.isArray){se(e,l.name);continue}let c=await Cn(e,l,{makeReadonly:!0});if(c)return c}return L}function ps(e){return e.state.directoryStack??=[],e.state.directoryStack}function Ze(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Ci(e){let t=e.split("/").filter(n=>n&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function ms(e,t){let s=ps(e),n;for(let o=0;o<t.length;o++){let f=t[o];if(f==="--"){if(o+1<t.length){if(n!==void 0)return S(`bash: pushd: too many arguments
|
|
110
|
+
`,2);n=t[o+1],o++}}else{if(f.startsWith("-")&&f!=="-")return S(`bash: pushd: ${f}: invalid option
|
|
111
111
|
`,2);if(n!==void 0)return S(`bash: pushd: too many arguments
|
|
112
|
-
`,2);n=
|
|
113
|
-
`,1);let o=s[0];s[0]=s[1],s[1]=o,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let o=e.state.cwd.split("/").filter(
|
|
112
|
+
`,2);n=f}}if(n===void 0){if(s.length<2)return S(`bash: pushd: no other directory
|
|
113
|
+
`,1);let o=s[0];s[0]=s[1],s[1]=o,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let o=e.state.cwd.split("/").filter(f=>f);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.get("HOME")||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Ci(r);try{if(!(await e.fs.stat(r)).isDirectory)return S(`bash: pushd: ${n}: Not a directory
|
|
114
114
|
`,1)}catch{return S(`bash: pushd: ${n}: No such file or directory
|
|
115
|
-
`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.PWD
|
|
116
|
-
`;return W(a)}function
|
|
115
|
+
`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[r,...s].map(o=>Ze(o,i)).join(" ")}
|
|
116
|
+
`;return W(a)}function ys(e,t){let s=ps(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?S(`bash: popd: ${a}: invalid option
|
|
117
117
|
`,2):S(`bash: popd: too many arguments
|
|
118
118
|
`,2);if(s.length===0)return S(`bash: popd: directory stack empty
|
|
119
119
|
`,1);let n=s.shift();if(!n)return S(`bash: popd: directory stack empty
|
|
120
|
-
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.PWD
|
|
121
|
-
`;return W(i)}function
|
|
120
|
+
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let r=e.state.env.get("HOME")||"",i=`${[n,...s].map(a=>Ze(a,r)).join(" ")}
|
|
121
|
+
`;return W(i)}function gs(e,t){let s=ps(e),n=!1,r=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let u of c.slice(1))if(u==="c")n=!0;else if(u==="l")r=!0;else if(u==="p")i=!0;else if(u==="v")i=!0,a=!0;else return S(`bash: dirs: -${u}: invalid option
|
|
122
122
|
`,2);else return S(`bash: dirs: too many arguments
|
|
123
|
-
`,1);if(n)return e.state.directoryStack=[],L;let o=[e.state.cwd,...s],
|
|
124
|
-
`),
|
|
125
|
-
`):i?
|
|
123
|
+
`,1);if(n)return e.state.directoryStack=[],L;let o=[e.state.cwd,...s],f=e.state.env.get("HOME")||"",l;return a?(l=o.map((c,u)=>{let d=r?c:Ze(c,f);return` ${u} ${d}`}).join(`
|
|
124
|
+
`),l+=`
|
|
125
|
+
`):i?l=o.map(c=>r?c:Ze(c,f)).join(`
|
|
126
126
|
`)+`
|
|
127
|
-
`:
|
|
128
|
-
`,W(
|
|
127
|
+
`:l=o.map(c=>r?c:Ze(c,f)).join(" ")+`
|
|
128
|
+
`,W(l)}async function Ct(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return S(`bash: eval: ${o}: invalid option
|
|
129
129
|
eval: usage: eval [arg ...]
|
|
130
|
-
`,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=
|
|
131
|
-
`);throw o}finally{e.state.groupStdin=i}}function
|
|
132
|
-
`,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function
|
|
133
|
-
`}}return W(a)}if(s){for(let a of n){let o,
|
|
134
|
-
`,i=1;continue}if(
|
|
135
|
-
`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env
|
|
136
|
-
`,r||
|
|
137
|
-
`,r||
|
|
138
|
-
`,1);o=t[
|
|
130
|
+
`,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=he(r);return await e.executeScript(o)}catch(o){if(o instanceof re||o instanceof ie||o instanceof te||o instanceof z)throw o;if(o.name==="ParseException")return S(`bash: eval: ${o.message}
|
|
131
|
+
`);throw o}finally{e.state.groupStdin=i}}function ws(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required
|
|
132
|
+
`,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function vs(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,f=Array.from(o).sort();for(let l of f){let c=e.state.env.get(l);if(c!==void 0){let u=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${l}="${u}"
|
|
133
|
+
`}}return W(a)}if(s){for(let a of n){let o,f;if(a.includes("=")){let l=a.indexOf("=");o=a.slice(0,l),f=H(e,a.slice(l+1)),e.state.env.set(o,f)}else o=a;it(e,o)}return L}let r="",i=0;for(let a of n){let o,f,l=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],f=H(e,c[2]),l=!0;else if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),f=H(e,a.slice(u+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier
|
|
134
|
+
`,i=1;continue}if(f!==void 0)if(l){let u=e.state.env.get(o)??"";e.state.env.set(o,u+f)}else e.state.env.set(o,f);else e.state.env.has(o)||e.state.env.set(o,"");ue(e,o)}return _("",r,i)}function Pt(e,t){if(t.length<2)return S(`bash: getopts: usage: getopts optstring name [arg ...]
|
|
135
|
+
`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let g=1;g<=p;g++)o.push(e.state.env.get(String(g))||"")}let f=Number.parseInt(e.state.env.get("OPTIND")||"1",10);f<1&&(f=1);let l=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),f>o.length)return r||e.state.env.set(n,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:1,stdout:"",stderr:""};let c=o[f-1];if(!c||c==="-"||!c.startsWith("-"))return r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};let u=l===0?1:l,d=c[u];if(!d)return e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Pt(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d}
|
|
136
|
+
`,r||e.state.env.set(n,"?"),u+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(u+1)),e.state.env.set("OPTIND",String(f))):(e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:r?2:0,stdout:"",stderr:p}}if(h+1<a.length&&a[h+1]===":")if(u+1<c.length)e.state.env.set("OPTARG",c.slice(u+1)),e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(f>=o.length){let p="";return i?(e.state.env.set("OPTARG",d),r||e.state.env.set(n,":")):(p=`bash: option requires an argument -- ${d}
|
|
137
|
+
`,r||e.state.env.set(n,"?")),e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",o[f]),e.state.env.set("OPTIND",String(f+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else u+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(u+1)),e.state.env.set("OPTIND",String(f))):(e.state.env.set("OPTIND",String(f+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return r||e.state.env.set(n,d),{exitCode:r?2:0,stdout:"",stderr:""}}async function bs(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,n=!1,r=!1,i=!1,a=!1,o="",f=[],l=0;for(;l<t.length;){let m=t[l];if(m==="--"){l++,f.push(...t.slice(l));break}if(m==="-r")s=!0,l++;else if(m==="-d")n=!0,l++;else if(m==="-l")r=!0,l++;else if(m==="-t")a=!0,l++;else if(m==="-p"){if(i=!0,l++,l>=t.length)return S(`bash: hash: -p: option requires an argument
|
|
138
|
+
`,1);o=t[l],l++}else if(m.startsWith("-")&&m.length>1){for(let p of m.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")a=!0;else return p==="p"?S(`bash: hash: -p: option requires an argument
|
|
139
139
|
`,1):S(`bash: hash: -${p}: invalid option
|
|
140
|
-
`,1);
|
|
141
|
-
`,1);let m=!1,p="";for(let g of
|
|
142
|
-
`,m=!0);return m?S(p,1):L}if(a){if(
|
|
143
|
-
`,1);let m="",p=!1,g="";for(let
|
|
140
|
+
`,1);l++}else f.push(m),l++}if(s)return e.state.hashTable.clear(),L;if(n){if(f.length===0)return S(`bash: hash: -d: option requires an argument
|
|
141
|
+
`,1);let m=!1,p="";for(let g of f)e.state.hashTable.has(g)?e.state.hashTable.delete(g):(p+=`bash: hash: ${g}: not found
|
|
142
|
+
`,m=!0);return m?S(p,1):L}if(a){if(f.length===0)return S(`bash: hash: -t: option requires an argument
|
|
143
|
+
`,1);let m="",p=!1,g="";for(let v of f){let $=e.state.hashTable.get(v);$?f.length>1?m+=`${v} ${$}
|
|
144
144
|
`:m+=`${$}
|
|
145
|
-
`:(g+=`bash: hash: ${
|
|
146
|
-
`,p=!0)}return p?{exitCode:1,stdout:m,stderr:g}:W(m)}if(i){if(
|
|
147
|
-
`,1);let m=
|
|
145
|
+
`:(g+=`bash: hash: ${v}: not found
|
|
146
|
+
`,p=!0)}return p?{exitCode:1,stdout:m,stderr:g}:W(m)}if(i){if(f.length===0)return S(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
|
|
147
|
+
`,1);let m=f[0];return e.state.hashTable.set(m,o),L}if(f.length===0){if(e.state.hashTable.size===0)return W(`hash: hash table empty
|
|
148
148
|
`);let m="";if(r)for(let[p,g]of e.state.hashTable)m+=`builtin hash -p ${g} ${p}
|
|
149
149
|
`;else{m=`hits command
|
|
150
150
|
`;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
|
|
151
|
-
`}return W(m)}let c=!1,u="",h=(e.state.env.PATH||"/usr/bin:/bin").split(":");for(let m of
|
|
152
|
-
`,c=!0;continue}let p=!1;for(let g of h){if(!g)continue;let
|
|
153
|
-
`,c=!0)}return c?S(u,1):L}var
|
|
151
|
+
`}return W(m)}let c=!1,u="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let m of f){if(m.includes("/")){u+=`bash: hash: ${m}: cannot use / in name
|
|
152
|
+
`,c=!0;continue}let p=!1;for(let g of h){if(!g)continue;let v=`${g}/${m}`;if(await e.fs.exists(v)){e.state.hashTable.set(m,v),p=!0;break}}p||(u+=`bash: hash: ${m}: not found
|
|
153
|
+
`,c=!0)}return c?S(u,1):L}var Bn={":":[": [arguments]",`Null command.
|
|
154
154
|
No effect; the command does nothing.
|
|
155
155
|
Exit Status:
|
|
156
156
|
Always succeeds.`],".":[". filename [arguments]",`Execute commands from a file in the current shell.
|
|
@@ -495,29 +495,29 @@ eval: usage: eval [arg ...]
|
|
|
495
495
|
job specification, and reports its termination status.
|
|
496
496
|
Exit Status:
|
|
497
497
|
Returns the status of the last ID; fails if ID is invalid or an invalid
|
|
498
|
-
option is given.`]},
|
|
499
|
-
`,2)}r++}else n.push(
|
|
500
|
-
`,a=!0;continue}for(let c of
|
|
498
|
+
option is given.`]},Hn=Object.keys(Bn).sort();function Es(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let f=t[r];if(f==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(f.startsWith("-")&&f.length>1){for(let l=1;l<f.length;l++){let c=f[l];if(c==="s")s=!0;else return S(`bash: help: -${c}: invalid option
|
|
499
|
+
`,2)}r++}else n.push(f),r++}if(n.length===0)return Ni();let i="",a=!1,o="";for(let f of n){let l=Pi(f);if(l.length===0){o+=`bash: help: no help topics match \`${f}'. Try \`help help' or \`man -k ${f}' or \`info ${f}'.
|
|
500
|
+
`,a=!0;continue}for(let c of l){let[u,d]=Bn[c];s?i+=`${c}: ${u}
|
|
501
501
|
`:i+=`${c}: ${u}
|
|
502
502
|
${d}
|
|
503
|
-
`}}return{exitCode:a?1:0,stdout:i,stderr:o}}function
|
|
503
|
+
`}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Pi(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=new RegExp(`^${t}$`);return Hn.filter(n=>s.test(n))}function Ni(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=Hn.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",a=s[r+n]||"",o=i.padEnd(t);e.push(a?`${o}${a}`:i)}return W(`${e.join(`
|
|
504
504
|
`)}
|
|
505
|
-
`)}function
|
|
506
|
-
`);let s=
|
|
507
|
-
`)}return _("","",n===0?1:0)}async function
|
|
508
|
-
`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,
|
|
509
|
-
`)}return _(
|
|
510
|
-
`,r=1;continue}if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env
|
|
511
|
-
`,r=1;continue}let g=s.has(c);if(u!==void 0){let
|
|
512
|
-
`,r=1;continue}e.state.env
|
|
513
|
-
`,r=0,i=0,a=0,o=!1,
|
|
514
|
-
`,
|
|
515
|
-
`,a="",o=-1,
|
|
516
|
-
`){P+=2,N=P;continue}if(
|
|
517
|
-
`){A+=2;continue}if(
|
|
505
|
+
`)}function ki(e){let t=[],s="",n=0;for(let r of e){for(let i of r)i==="("?n++:i===")"&&n--;s?s+=` ${r}`:s=r,n===0&&(t.push(s),s="")}return s&&t.push(s),t}async function $s(e,t){if(t.length===0)return S(`bash: let: expression expected
|
|
506
|
+
`);let s=ki(t),n=0;for(let r of s)try{let a=he(`(( ${r} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await V(e,o.expression.expression))}}catch(i){return S(`bash: let: ${r}: ${i.message}
|
|
507
|
+
`)}return _("","",n===0?1:0)}async function Ss(e,t){if(e.state.localScopes.length===0)return S(`bash: local: can only be used in a function
|
|
508
|
+
`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,f=[];for(let l of t)if(l==="-n")i=!0;else if(l==="-a")a=!0;else if(l==="-p")o=!0;else if(l.startsWith("-")&&!l.includes("="))for(let c of l.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(o=!0);else f.push(l);if(f.length===0){let l="",c=Array.from(s.keys()).filter(u=>!u.includes("_")||!u.match(/_\d+$/)).filter(u=>!u.includes("__length")).sort();for(let u of c){let d=e.state.env.get(u);d!==void 0&&(l+=`${u}=${d}
|
|
509
|
+
`)}return _(l,"",0)}for(let l of f){let c,u,d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let v=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${l}': not a valid identifier
|
|
510
|
+
`,r=1;continue}if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let y=`${c}_`;for(let w of e.state.env.keys())w.startsWith(y)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)))}let $=`${c}_`;for(let y of e.state.env.keys())y.startsWith($)&&!y.includes("__")&&e.state.env.delete(y);let N=ye(v);for(let y=0;y<N.length;y++)e.state.env.set(`${c}_${y}`,N[y]);e.state.env.set(`${c}__length`,String(N.length)),Ne(e,c),i&&we(e,c);continue}let h=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){c=h[1];let v=h[2];if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let C=`${c}_`;for(let D of e.state.env.keys())D.startsWith(C)&&!D.includes("__")&&(s.has(D)||s.set(D,e.state.env.get(D)));let O=`${c}__length`;e.state.env.has(O)&&!s.has(O)&&s.set(O,e.state.env.get(O))}let $=ye(v),N=Q(e,c),y=0,w=e.state.env.get(c);N.length===0&&w!==void 0?(e.state.env.set(`${c}_0`,w),e.state.env.delete(c),y=1):N.length>0&&(y=Math.max(...N)+1);for(let C=0;C<$.length;C++)e.state.env.set(`${c}_${y+C}`,H(e,$[C]));let b=y+$.length;e.state.env.set(`${c}__length`,String(b)),Ne(e,c),i&&we(e,c);continue}let m=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){c=m[1];let v=H(e,m[2]);K(e,c,"bash"),s.has(c)||s.set(c,e.state.env.get(c));let $=e.state.env.get(c)??"";e.state.env.set(c,$+v),Ne(e,c),i&&we(e,c);continue}let p=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){c=p[1];let v=p[2],$=H(e,p[3]);if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let w=`${c}_`;for(let C of e.state.env.keys())C.startsWith(w)&&!C.includes("__")&&(s.has(C)||s.set(C,e.state.env.get(C)));let b=`${c}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}let N;try{let w=new F,b=q(w,v);N=await V(e,b.expression)}catch{let w=parseInt(v,10);N=Number.isNaN(w)?0:w}e.state.env.set(`${c}_${N}`,$);let y=parseInt(e.state.env.get(`${c}__length`)??"0",10);N>=y&&e.state.env.set(`${c}__length`,String(N+1)),Ne(e,c),i&&we(e,c);continue}if(l.includes("=")){let v=l.indexOf("=");c=l.slice(0,v),u=H(e,l.slice(v+1))}else c=l;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${l}': not a valid identifier
|
|
511
|
+
`,r=1;continue}let g=s.has(c);if(u!==void 0){let v=e.state.env.get(c);if(e.state.tempEnvBindings){let $=e.state.accessedTempEnvVars?.has(c),N=e.state.mutatedTempEnvVars?.has(c);if(!$&&!N)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let w=e.state.tempEnvBindings[y];if(w.has(c)){v=w.get(c);break}}}Pn(e,c,v)}if(!g){let v=e.state.env.get(c);if(e.state.tempEnvBindings)for(let $=e.state.tempEnvBindings.length-1;$>=0;$--){let N=e.state.tempEnvBindings[$];if(N.has(c)){v=N.get(c);break}}if(s.set(c,v),a){let $=`${c}_`;for(let y of e.state.env.keys())y.startsWith($)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let N=`${c}__length`;e.state.env.has(N)&&!s.has(N)&&s.set(N,e.state.env.get(N))}}if(a&&u===void 0){let v=`${c}_`;for(let $ of e.state.env.keys())$.startsWith(v)&&!$.includes("__")&&e.state.env.delete($);e.state.env.set(`${c}__length`,"0")}else if(u!==void 0){if(K(e,c,"bash"),i&&u!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(u)){n+=`bash: local: \`${u}': invalid variable name for name reference
|
|
512
|
+
`,r=1;continue}e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let v=e.state.tempEnvBindings?.some($=>$.has(c));!g&&!v&&e.state.env.delete(c)}Ne(e,c),i&&we(e,c)}return _("",n,r)}function As(e,t,s){let n=`
|
|
513
|
+
`,r=0,i=0,a=0,o=!1,f="MAPFILE",l=0;for(;l<t.length;){let v=t[l];v==="-d"&&l+1<t.length?(n=t[l+1]===""?"\0":t[l+1]||`
|
|
514
|
+
`,l+=2):v==="-n"&&l+1<t.length?(r=Number.parseInt(t[l+1],10)||0,l+=2):v==="-O"&&l+1<t.length?(i=Number.parseInt(t[l+1],10)||0,l+=2):v==="-s"&&l+1<t.length?(a=Number.parseInt(t[l+1],10)||0,l+=2):v==="-t"?(o=!0,l++):v==="-u"||v==="-C"||v==="-c"?l+=2:(v.startsWith("-")||(f=v),l++)}let c=s;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let u=[],d=c,h=0,m=0;for(;d.length>0;){let v=d.indexOf(n);if(v===-1){if(d.length>0){if(m<a)m++;else if(r===0||h<r){let y=d,w=y.indexOf("\0");w!==-1&&(y=y.substring(0,w)),u.push(y),h++}}break}let $=d.substring(0,v),N=$.indexOf("\0");if(N!==-1&&($=$.substring(0,N)),!o&&n!=="\0"&&($+=n),d=d.substring(v+n.length),m<a){m++;continue}if(r>0&&h>=r)break;u.push($),h++}i===0&&pe(e,f);for(let v=0;v<u.length;v++)e.state.env.set(`${f}_${i+v}`,u[v]);let p=parseInt(e.state.env.get(`${f}__length`)||"0",10),g=i+u.length;return e.state.env.set(`${f}__length`,String(Math.max(p,g))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),_("","",0)}function Oi(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),f=o.indexOf(":");if(f===-1)return null;let l=Number.parseInt(o.slice(0,f),10);if(Number.isNaN(l)||l<0)return null;let c=o.slice(f+1);return{path:i,position:l,content:c}}function Di(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function _s(e,t,s,n=-1){let r=!1,i=`
|
|
515
|
+
`,a="",o=-1,f=-1,l=null,c=-1,u=-1,d=[],h=0,m=!1,p=(A,P)=>{let I=1;for(;I<A.length;){let E=A[I];if(E==="r")r=!0,I++;else if(E==="s")I++;else{if(E==="d")return I+1<A.length?(i=A.substring(I+1),{nextArgIndex:P+1}):P+1<t.length?(i=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="n"){if(I+1<A.length){let k=A.substring(I+1);return o=Number.parseInt(k,10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:P+1}}else if(P+1<t.length)return o=Number.parseInt(t[P+1],10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(E==="N"){if(I+1<A.length){let k=A.substring(I+1);return f=Number.parseInt(k,10),(Number.isNaN(f)||f<0)&&(m=!0,f=0),{nextArgIndex:P+1}}else if(P+1<t.length)return f=Number.parseInt(t[P+1],10),(Number.isNaN(f)||f<0)&&(m=!0,f=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else{if(E==="a")return I+1<A.length?(l=A.substring(I+1),{nextArgIndex:P+1}):P+1<t.length?(l=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="p")return I+1<A.length?(a=A.substring(I+1),{nextArgIndex:P+1}):P+1<t.length?(a=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="u"){if(I+1<A.length){let k=A.substring(I+1);return c=Number.parseInt(k,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:P+1}}else if(P+1<t.length)return c=Number.parseInt(t[P+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(E==="t"){if(I+1<A.length){let k=A.substring(I+1);return u=Number.parseFloat(k),Number.isNaN(u)&&(u=0),{nextArgIndex:P+1}}else if(P+1<t.length)return u=Number.parseFloat(t[P+1]),Number.isNaN(u)&&(u=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(E==="e"||E==="i"||E==="P"){if(E==="i"&&P+1<t.length)return{nextArgIndex:P+2};I++}else I++}}}return{nextArgIndex:P+1}};for(;h<t.length;){let A=t[h];if(A.startsWith("-")&&A.length>1&&A!=="--"){let P=p(A,h);if(P.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(P.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=P.nextArgIndex}else if(A==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(A),h++}if(m)return _("","",1);if(d.length===0&&l===null&&d.push("REPLY"),u===0){if(l)pe(e,l);else{for(let A of d)e.state.env.set(A,"");d.length===0&&e.state.env.set("REPLY","")}return _("","",0)}if(u<0&&u!==-1)return _("","",1);let g=s;c>=0?e.state.fileDescriptors?g=e.state.fileDescriptors.get(c)||"":g="":!g&&e.state.groupStdin!==void 0&&(g=e.state.groupStdin);let v=i===""?"\0":i,$="",N=0,y=!0,w=A=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,g.substring(A));else if(n>=0&&e.state.fileDescriptors){let P=e.state.fileDescriptors.get(n);if(P?.startsWith("__rw__:")){let I=Oi(P);if(I){let E=I.position+A;e.state.fileDescriptors.set(n,Di(I.path,E,I.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=g.substring(A))};if(f>=0){let A=Math.min(f,g.length);$=g.substring(0,A),N=A,y=A>=f,w(N);let P=d[0]||"REPLY";e.state.env.set(P,$);for(let I=1;I<d.length;I++)e.state.env.set(d[I],"");return _("","",y?0:1)}else if(o>=0){let A=0,P=0,I=!1;for(;P<g.length&&A<o;){let E=g[P];if(E===v){N=P+1,I=!0;break}if(!r&&E==="\\"&&P+1<g.length){let k=g[P+1];if(k===v&&v===`
|
|
516
|
+
`){P+=2,N=P;continue}if(k===v){P+=2,A++,$+=k,N=P;continue}$+=k,P+=2,A++,N=P}else $+=E,P++,A++,N=P}y=A>=o||I,w(N)}else{N=0;let A=0;for(;A<g.length;){let P=g[A];if(P===v){N=A+v.length,y=!0;break}if(!r&&P==="\\"&&A+1<g.length){let I=g[A+1];if(I===`
|
|
517
|
+
`){A+=2;continue}if(I===v){$+=I,A+=2;continue}$+=P,$+=I,A+=2;continue}$+=P,A++}if(A>=g.length&&(y=!1,N=A,$.length===0&&g.length===0)){for(let P of d)e.state.env.set(P,"");return l&&pe(e,l),_("","",1)}w(N)}v===`
|
|
518
518
|
`&&$.endsWith(`
|
|
519
|
-
`)&&($=$.slice(0,-1));let
|
|
520
|
-
`,2);s=(r%256+256)%256}throw new
|
|
519
|
+
`)&&($=$.slice(0,-1));let b=A=>r?A:A.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",b($)),_("","",y?0:1);let C=js(e.state.env);if(l){let{words:A}=Lt($,C,void 0,r);pe(e,l);for(let P=0;P<A.length;P++)e.state.env.set(`${l}_${P}`,b(A[P]));return _("","",y?0:1)}let O=d.length,{words:D,wordStarts:x}=Lt($,C,O,r);for(let A=0;A<d.length;A++){let P=d[A];if(A<d.length-1)e.state.env.set(P,b(D[A]??""));else if(A<x.length){let I=$.substring(x[A]);I=Us(I,C,r),I=b(I),e.state.env.set(P,I)}else e.state.env.set(P,"")}return _("","",y?0:1)}function Cs(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return S("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return S(`bash: return: ${n}: numeric argument required
|
|
520
|
+
`,2);s=(r%256+256)%256}throw new te(s)}var Nt=`set: usage: set [-eux] [+eux] [-o option] [+o option]
|
|
521
521
|
Options:
|
|
522
522
|
-e Exit immediately if a command exits with non-zero status
|
|
523
523
|
+e Disable -e
|
|
@@ -533,148 +533,148 @@ Options:
|
|
|
533
533
|
+o pipefail Disable pipefail
|
|
534
534
|
-o xtrace Same as -x
|
|
535
535
|
+o xtrace Disable xtrace
|
|
536
|
-
`,
|
|
536
|
+
`,jn=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Un=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),qn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Zn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Gn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,Re(e))}function Ii(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Ti(e,t){let s=Q(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${r}]=${Ie(i)}`});return`${t}=(${n.join(" ")})`}function xi(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ri(e,t){let s=Se(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${xi(r)}]=${Ie(i)}`});return`${t}=(${n.join(" ")} )`}function Li(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function Wi(e){return e.state.associativeArrays??new Set}function Ns(e,t){if(t.includes("--help"))return W(Nt);if(t.length===0){let n=Li(e),r=Wi(e),i=f=>{for(let l of r){let c=`${l}_`,u=`${l}__length`;if(f!==u&&f.startsWith(c)){if(f.slice(c.length).startsWith("_length"))continue;return!0}}return!1},a=[];for(let[f,l]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)||n.has(f)||r.has(f))continue;let c=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(c&&n.has(c[1]))continue;let u=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&n.has(u[1])||i(f)||u&&r.has(u[1])||a.push([f,l])}let o=[];for(let[f,l]of a.sort(([c],[u])=>c<u?-1:c>u?1:0))o.push(`${f}=${_t(l)}`);for(let f of[...n].sort((l,c)=>l<c?-1:l>c?1:0))o.push(Ti(e,f));for(let f of[...r].sort((l,c)=>l<c?-1:l>c?1:0))o.push(Ri(e,f));return o.sort((f,l)=>{let c=f.split("=")[0],u=l.split("=")[0];return c<u?-1:c>u?1:0}),W(o.length>0?`${o.join(`
|
|
537
537
|
`)}
|
|
538
|
-
`:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&
|
|
539
|
-
${
|
|
538
|
+
`:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&Ii(t,s)){let r=t[s+1];if(!Un.has(r)){let i=`bash: set: ${r}: invalid option name
|
|
539
|
+
${Nt}`;if(e.state.options.posix)throw new ce(1,"",i);return S(i)}Gn(e,Un.get(r)??null,n==="-o"),s+=2;continue}if(n==="-o"){let r=qn.map(o=>`${o.padEnd(16)}${e.state.options[o]?"on":"off"}`),i=Zn.map(o=>`${o.padEnd(16)}off`),a=[...r,...i].sort();return W(`${a.join(`
|
|
540
540
|
`)}
|
|
541
|
-
`)}if(n==="+o"){let r=
|
|
541
|
+
`)}if(n==="+o"){let r=qn.map(o=>`set ${e.state.options[o]?"-o":"+o"} ${o}`),i=Zn.map(o=>`set +o ${o}`),a=[...r,...i].sort();return W(`${a.join(`
|
|
542
542
|
`)}
|
|
543
|
-
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!(a
|
|
544
|
-
${
|
|
545
|
-
${
|
|
546
|
-
`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}s=a}let n=Number.parseInt(e.state.env
|
|
547
|
-
`;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}if(s===0)return L;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env
|
|
548
|
-
`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let
|
|
549
|
-
`);let a=
|
|
550
|
-
`);throw
|
|
551
|
-
`,r=1;continue}let $=await
|
|
543
|
+
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!jn.has(a)){let o=`bash: set: ${n[0]}${a}: invalid option
|
|
544
|
+
${Nt}`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}Gn(e,jn.get(a)??null,r)}s++;continue}if(n==="--")return Ps(e,t.slice(s+1)),L;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Re(e),s+1<t.length)return Ps(e,t.slice(s+1)),L;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
|
|
545
|
+
${Nt}`;if(e.state.options.posix)throw new ce(1,"",r);return S(r)}return Ps(e,t.slice(s)),L}return L}function Ps(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;for(let n=0;n<t.length;n++)e.state.env.set(String(n+1),t[n]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function ks(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required
|
|
546
|
+
`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}s=a}let n=Number.parseInt(e.state.env.get("#")||"0",10);if(s>n){let a=`bash: shift: shift count out of range
|
|
547
|
+
`;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}if(s===0)return L;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env.get(String(a))||"");let i=r.slice(s);for(let a=1;a<=n;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),L}async function Os(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return _("",`bash: source: filename argument required
|
|
548
|
+
`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let l=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(l),r=l}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(u=>u);for(let u of c){let d=e.fs.resolvePath(e.state.cwd,`${u}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}}if(i===null)return S(`bash: ${n}: No such file or directory
|
|
549
|
+
`);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let l=s.slice(1);e.state.env.set("#",String(l.length)),e.state.env.set("@",l.join(" "));for(let c=0;c<l.length&&c<9;c++)e.state.env.set(String(c+1),l[c]);for(let c=l.length+1;c<=9;c++)e.state.env.delete(String(c))}let o=e.state.currentSource,f=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[l,c]of a)c===void 0?e.state.env.delete(l):e.state.env.set(l,c)};e.state.sourceDepth++,e.state.currentSource=n;try{let l=he(i),c=await e.executeScript(l);return f(),c}catch(l){if(f(),l instanceof z)throw l;if(l instanceof te)return _(l.stdout,l.stderr,l.exitCode);if(l.name==="ParseException")return S(`bash: ${n}: ${l.message}
|
|
550
|
+
`);throw l}}function Kn(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Mi(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Xn(e,t){if(Mi(t))return null;try{let s=new F,n=q(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Yn(e,t){if(e.state.localVarStack?.has(t)){let n=$t(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)Et(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Ds(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Et(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||Et(e,t),!0}}return!1}function Ds(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function Qn(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new F().parseWordFromString(s,!0,!1);return T(e,r)}if(t.includes("$")){let n=new F().parseWordFromString(t,!1,!1);return T(e,n)}return t}async function Is(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let d=l[1],h=l[2];if(h==="@"||h==="*"){let N=fe(e,d);for(let[y]of N)e.state.env.delete(`${d}_${y}`);e.state.env.delete(d);continue}let m=e.state.associativeArrays?.has(d);if(m){let N=await Qn(e,h);e.state.env.delete(`${d}_${N}`);continue}let p=Ft(e,d),g=e.state.declaredVars?.has(d);if((e.state.env.has(d)||g)&&!p&&!m){n+=`bash: unset: ${d}: not an array variable
|
|
551
|
+
`,r=1;continue}let $=await Xn(e,h);if($===null&&p){n+=`bash: unset: ${h}: not a valid identifier
|
|
552
552
|
`,r=1;continue}if($===null)continue;if($<0){let N=fe(e,d),y=N.length,w=e.state.currentLine;if(y===0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
|
|
553
|
-
`,r=1;continue}let
|
|
554
|
-
`,r=1;continue}let C=N[
|
|
555
|
-
`,r=1;continue}let c=i;if(oe(e,i)){let d=
|
|
556
|
-
`,r=1;continue}let u=
|
|
557
|
-
`,r=1;continue}let m=await
|
|
558
|
-
`,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,
|
|
559
|
-
`,r=1;continue}let $=g+m;if($<0){n+=`bash: line ${
|
|
560
|
-
`,r=1;continue}let N=p[$][0];
|
|
561
|
-
`,r=1;continue}let o=i;if(oe(e,i)){let
|
|
562
|
-
`,r=1;continue}let
|
|
563
|
-
`}}}
|
|
564
|
-
`};if(o.length===0){if(s||n){let h=[];for(let m of
|
|
553
|
+
`,r=1;continue}let b=y+$;if(b<0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
|
|
554
|
+
`,r=1;continue}let C=N[b][0];e.state.env.delete(`${d}_${C}`);continue}e.state.env.delete(`${d}_${$}`);continue}if(!Kn(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
555
|
+
`,r=1;continue}let c=i;if(oe(e,i)){let d=Ae(e,i);d&&d!==i&&(c=d)}if(Oe(e,c)){n+=`bash: unset: ${c}: cannot unset: readonly variable
|
|
556
|
+
`,r=1;continue}let u=We(e,c);if(u!==void 0&&u!==e.state.callDepth)Yn(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(u!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let m=$t(e,c);m?m.value===void 0?e.state.env.delete(c):e.state.env.set(c,m.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Ds(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let l=a[1],c=a[2];if(c==="@"||c==="*"){let p=fe(e,l);for(let[g]of p)e.state.env.delete(`${l}_${g}`);e.state.env.delete(l);continue}let u=e.state.associativeArrays?.has(l);if(u){let p=await Qn(e,c);e.state.env.delete(`${l}_${p}`);continue}let d=Ft(e,l);if(e.state.env.has(l)&&!d&&!u){n+=`bash: unset: ${l}: not an array variable
|
|
557
|
+
`,r=1;continue}let m=await Xn(e,c);if(m===null&&d){n+=`bash: unset: ${c}: not a valid identifier
|
|
558
|
+
`,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,l),g=p.length,v=e.state.currentLine;if(g===0){n+=`bash: line ${v}: unset: [${m}]: bad array subscript
|
|
559
|
+
`,r=1;continue}let $=g+m;if($<0){n+=`bash: line ${v}: unset: [${m}]: bad array subscript
|
|
560
|
+
`,r=1;continue}let N=p[$][0];e.state.env.delete(`${l}_${N}`);continue}e.state.env.delete(`${l}_${m}`);continue}if(!Kn(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
561
|
+
`,r=1;continue}let o=i;if(oe(e,i)){let l=Ae(e,i);l&&l!==i&&(o=l)}if(Oe(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable
|
|
562
|
+
`,r=1;continue}let f=We(e,o);if(f!==void 0&&f!==e.state.callDepth)Yn(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(f!==void 0){let l=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((l||c)&&e.state.localVarStack?.has(o)){let u=$t(e,o);u?u.value===void 0?e.state.env.delete(o):e.state.env.set(o,u.value):e.state.env.delete(o)}else e.state.env.delete(o)}else Ds(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return _("",n,r)}var Ts=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Fi=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function kt(e){return Ts.includes(e)}function zi(e){return Fi.includes(e)}function Jn(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],f=0;for(;f<t.length;){let d=t[f];if(d==="--"){f++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
|
|
563
|
+
`}}}f++}else break}for(;f<t.length;)o.push(t[f]),f++;if(a)return Vi(e,o,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
|
|
564
|
+
`};if(o.length===0){if(s||n){let h=[];for(let m of Ts){let p=e.state.shoptOptions[m];s&&p?h.push(r?`shopt -s ${m}`:`${m} on`):n&&!p&&h.push(r?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
|
|
565
565
|
`)}
|
|
566
|
-
`:"",stderr:""}}let d=[];for(let h of
|
|
566
|
+
`:"",stderr:""}}let d=[];for(let h of Ts){let m=e.state.shoptOptions[h];d.push(r?`shopt ${m?"-s":"-u"} ${h}`:`${h} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
|
|
567
567
|
`)}
|
|
568
|
-
`,stderr:""}}let
|
|
569
|
-
`,
|
|
568
|
+
`,stderr:""}}let l=!1,c="",u=[];for(let d of o){if(!kt(d)&&!zi(d)){c+=`shopt: ${d}: invalid shell option name
|
|
569
|
+
`,l=!0;continue}if(s)kt(d)&&(e.state.shoptOptions[d]=!0,Ht(e));else if(n)kt(d)&&(e.state.shoptOptions[d]=!1,Ht(e));else if(kt(d)){let h=e.state.shoptOptions[d];i?h||(l=!0):r?(u.push(`shopt ${h?"-s":"-u"} ${d}`),h||(l=!0)):(u.push(`${d} ${h?"on":"off"}`),h||(l=!0))}else i?l=!0:r?(u.push(`shopt -u ${d}`),l=!0):(u.push(`${d} off`),l=!0)}return{exitCode:l?1:0,stdout:u.length>0?`${u.join(`
|
|
570
570
|
`)}
|
|
571
|
-
`:"",stderr:c}}function
|
|
571
|
+
`:"",stderr:c}}function Vi(e,t,s,n,r,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],f=[...a.keys(),...o].sort();if(t.length===0){let d=[];for(let h of f){let m=o.includes(h),p=a.get(h),g=m||!p?!1:e.state.options[p];s&&!g||n&&g||d.push(r?`set ${g?"-o":"+o"} ${h}`:`${h} ${g?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
|
|
572
572
|
`)}
|
|
573
|
-
`:"",stderr:""}}let
|
|
574
|
-
`,
|
|
573
|
+
`:"",stderr:""}}let l=!1,c="",u=[];for(let d of t){let h=a.has(d),m=o.includes(d);if(!h&&!m){c+=`shopt: ${d}: invalid option name
|
|
574
|
+
`,l=!0;continue}if(m){s||n||(i?l=!0:r?(u.push(`set +o ${d}`),l=!0):(u.push(`${d} off`),l=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,Re(e);else if(n)e.state.options[p]=!1,Re(e);else{let g=e.state.options[p];i?g||(l=!0):r?(u.push(`set ${g?"-o":"+o"} ${d}`),g||(l=!0)):(u.push(`${d} ${g?"on":"off"}`),g||(l=!0))}}return{exitCode:l?1:0,stdout:u.length>0?`${u.join(`
|
|
575
575
|
`)}
|
|
576
|
-
`:"",stderr:c}}async function
|
|
577
|
-
`;h=!0,g=!0}}else{let
|
|
578
|
-
`,h=!0,g=!0)}g||(m=!0);continue}let
|
|
579
|
-
`;else{let
|
|
580
|
-
`;c+=C}g=!0}let $=e.state.env
|
|
576
|
+
`:"",stderr:c}}async function er(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,f=e.commands.get(o);try{let l=await e.fs.stat(a);return l.isDirectory?{error:"permission_denied",path:a}:f?{cmd:f,path:a}:(l.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let f=await e.fs.stat(a);if(!f.isDirectory&&(f.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let f=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(f))try{let l=await e.fs.stat(f);if(l.isDirectory)continue;let c=(l.mode&73)!==0,u=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(u&&d)return{cmd:u,path:f};if(c){if(u&&!d)return{script:!0,path:f};if(!u)return{script:!0,path:f}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function Ot(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}async function rr(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,f=!1,l=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let g of p.slice(1))g==="t"?r=!0:g==="p"?i=!0:g==="P"?a=!0:g==="a"?o=!0:g==="f"&&(f=!0);else l.push(p);let c="",u="",d=0,h=!1,m=!1;for(let p of l){let g=!1;if(a){if(o){let b=await n(p);if(b.length>0){for(let C of b)c+=`${C}
|
|
577
|
+
`;h=!0,g=!0}}else{let b=await s(p);b&&(c+=`${b}
|
|
578
|
+
`,h=!0,g=!0)}g||(m=!0);continue}let v=!f&&e.state.functions.has(p);if(o&&v){if(!i)if(r)c+=`function
|
|
579
|
+
`;else{let b=e.state.functions.get(p),C=b?tr(p,b):`${p} is a function
|
|
580
|
+
`;c+=C}g=!0}let $=e.state.env.get(`BASH_ALIAS_${p}`);if($!==void 0&&(o||!g)&&(i||(r?c+=`alias
|
|
581
581
|
`:c+=`${p} is aliased to \`${$}'
|
|
582
|
-
`),g=!0,!o)||
|
|
582
|
+
`),g=!0,!o)||Yt.has(p)&&(o||!g)&&(i||(r?c+=`keyword
|
|
583
583
|
`:c+=`${p} is a shell keyword
|
|
584
|
-
`),g=!0,!o))continue;if(!o&&
|
|
585
|
-
`;else{let
|
|
586
|
-
`;c+=C}g=!0;continue}if(!(
|
|
584
|
+
`),g=!0,!o))continue;if(!o&&v&&!g){if(!i)if(r)c+=`function
|
|
585
|
+
`;else{let b=e.state.functions.get(p),C=b?tr(p,b):`${p} is a function
|
|
586
|
+
`;c+=C}g=!0;continue}if(!(Ue.has(p)&&(o||!g)&&(i||(r?c+=`builtin
|
|
587
587
|
`:c+=`${p} is a shell builtin
|
|
588
|
-
`),g=!0,!o))){if(o){let
|
|
588
|
+
`),g=!0,!o))){if(o){let b=await n(p);for(let C of b)i?c+=`${C}
|
|
589
589
|
`:r?c+=`file
|
|
590
590
|
`:c+=`${p} is ${C}
|
|
591
|
-
`,h=!0,g=!0}else if(!g){let
|
|
591
|
+
`,h=!0,g=!0}else if(!g){let b=await s(p);b&&(i?c+=`${b}
|
|
592
592
|
`:r?c+=`file
|
|
593
|
-
`:c+=`${p} is ${
|
|
594
|
-
`,h=!0,g=!0)}if(!g&&(m=!0,!r&&!i)){let
|
|
595
|
-
`)}}}return i?d=m&&!h?1:0:d=m?1:0,_(c,u,d)}function
|
|
593
|
+
`:c+=`${p} is ${b}
|
|
594
|
+
`,h=!0,g=!0)}if(!g&&(m=!0,!r&&!i)){let b=!0;if(p.includes("/")){let C=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(C)&&(b=!1)}b&&(u+=`bash: type: ${p}: not found
|
|
595
|
+
`)}}}return i?d=m&&!h?1:0:d=m?1:0,_(c,u,d)}function tr(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>Ge(r)).join("; "):s=Ge(t.body),`${e} is a function
|
|
596
596
|
${e} ()
|
|
597
597
|
{
|
|
598
598
|
${s}
|
|
599
599
|
}
|
|
600
|
-
`}function
|
|
601
|
-
`:r+=`alias ${o}='${
|
|
602
|
-
`;else if(
|
|
600
|
+
`}function Ge(e){if(Array.isArray(e))return e.map(t=>Ge(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(Bi(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(sr(t.name));for(let n of t.args)s.push(sr(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>Ge(n)).join("; ")}; }`:"..."}function Bi(e){let t=e.commands.map(s=>Ge(s));return(e.negated?"! ":"")+t.join(" | ")}function sr(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>nr(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=nr(s);return t}function nr(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function ir(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let f=e.state.env.get(`BASH_ALIAS_${o}`);if(f!==void 0)n?r+=`${o} is an alias for "${f}"
|
|
601
|
+
`:r+=`alias ${o}='${f}'
|
|
602
|
+
`;else if(Yt.has(o))n?r+=`${o} is a shell keyword
|
|
603
603
|
`:r+=`${o}
|
|
604
|
-
`;else if(
|
|
604
|
+
`;else if(Ue.has(o))n?r+=`${o} is a shell builtin
|
|
605
605
|
`:r+=`${o}
|
|
606
606
|
`;else if(e.state.functions.has(o))n?r+=`${o} is a function
|
|
607
607
|
`:r+=`${o}
|
|
608
|
-
`;else if(o.includes("/")){let
|
|
608
|
+
`;else if(o.includes("/")){let l=e.fs.resolvePath(e.state.cwd,o),c=!1;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);u.isDirectory||(u.mode&73)!==0&&(n?r+=`${o} is ${o}
|
|
609
609
|
`:r+=`${o}
|
|
610
610
|
`,c=!0)}catch{}c||(n&&(i+=`${o}: not found
|
|
611
|
-
`),a=1)}else if(e.commands.has(o)){let c=(e.state.env.PATH??"/usr/bin:/bin").split(":"),u=null;for(let d of c){if(!d)continue;let h=`${d}/${o}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){u=h;break}}catch{}}u||(u=`/usr/bin/${o}`),n?r+=`${o} is ${u}
|
|
611
|
+
`),a=1)}else if(e.commands.has(o)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),u=null;for(let d of c){if(!d)continue;let h=`${d}/${o}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){u=h;break}}catch{}}u||(u=`/usr/bin/${o}`),n?r+=`${o} is ${u}
|
|
612
612
|
`:r+=`${u}
|
|
613
613
|
`}else n&&(i+=`${o}: not found
|
|
614
|
-
`),a=1}return _(r,i,a)}async function
|
|
615
|
-
`);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function
|
|
614
|
+
`),a=1}return _(r,i,a)}async function ar(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function or(e,t,s,n,r,i,a,o){let{ctx:f,runCommand:l}=e;if(t==="export")return vs(f,s);if(t==="unset")return Is(f,s);if(t==="exit")return ws(f,s);if(t==="local")return Ss(f,s);if(t==="set")return Ns(f,s);if(t==="break")return Ut(f,s);if(t==="continue")return rs(f,s);if(t==="return")return Cs(f,s);if(t==="eval"&&f.state.options.posix)return Ct(f,s,r);if(t==="shift")return ks(f,s);if(t==="getopts")return Pt(f,s);if(t==="compgen")return es(f,s);if(t==="complete")return ss(f,s);if(t==="compopt")return ns(f,s);if(t==="pushd")return await ms(f,s);if(t==="popd")return ys(f,s);if(t==="dirs")return gs(f,s);if(t==="source"||t===".")return Os(f,s);if(t==="read")return _s(f,s,r,o);if(t==="mapfile"||t==="readarray")return As(f,s,r);if(t==="declare"||t==="typeset")return ds(f,s);if(t==="readonly")return hs(f,s);if(!i){let c=f.state.functions.get(t);if(c)return At(f,c,s,r)}if(t==="eval")return Ct(f,s,r);if(t==="cd")return await qt(f,s);if(t===":"||t==="true")return L;if(t==="false")return U(!1);if(t==="let")return $s(f,s);if(t==="command")return Hi(e,s,r);if(t==="builtin")return ji(e,s,r);if(t==="shopt")return Jn(f,s);if(t==="exec"){if(s.length===0)return L;let[c,...u]=s;return l(c,u,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await rr(f,s,c=>ar(f,c),c=>Ot(f,c));if(t==="hash")return bs(f,s);if(t==="help")return Es(f,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return S("[: missing `]'\n",2);c=s.slice(0,-1)}return je(f,c)}return null}async function Hi(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,a=!1,o=!1,f=t;for(;f.length>0&&f[0].startsWith("-");){let u=f[0];if(u==="--"){f=f.slice(1);break}for(let d of u.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);f=f.slice(1)}if(f.length===0)return L;if(o||a)return await ir(n,f,o,a);let[l,...c]=f;return r(l,c,[],s,!0,i,-1)}async function ji(e,t,s){let{runCommand:n}=e;if(t.length===0)return L;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return L;let i=r[0];if(!Ue.has(i))return S(`bash: builtin: ${i}: not a shell builtin
|
|
615
|
+
`);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function lr(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,l=await er(i,t,r?"/usr/bin:/bin":void 0);if(!l)return yn(t)?S(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
|
|
616
616
|
`,127):S(`bash: ${t}: command not found
|
|
617
|
-
`,127);if("error"in
|
|
617
|
+
`,127);if("error"in l)return l.error==="permission_denied"?S(`bash: ${t}: Permission denied
|
|
618
618
|
`,126):S(`bash: ${t}: No such file or directory
|
|
619
|
-
`,127);if("script"in
|
|
620
|
-
`)}}async function
|
|
621
|
-
`,exitCode:1}}async function
|
|
622
|
-
`,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function
|
|
623
|
-
`);let o=[];if(t.words===null)o=(e.state.env
|
|
619
|
+
`,127);if("script"in l)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,l.path)),await o(l.path,s,n);let{cmd:c,path:u}=l;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u));let d=n||i.state.groupStdin||"",h=a(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo};try{return await c.execute(s,m)}catch(p){return S(`${t}: ${le(p)}
|
|
620
|
+
`)}}async function xs(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function Ke(e,t,s,n){if(e instanceof re)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof te||e instanceof ae||e instanceof z||e instanceof ee)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=le(e);return{action:"error",stdout:t,stderr:`${s}${r}
|
|
621
|
+
`,exitCode:1}}async function Dt(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let f=await e.executeStatement(o);r+=f.stdout,i+=f.stderr,a=f.exitCode}}catch(o){if(st(o)||o instanceof ae||o instanceof z||o instanceof ee||o instanceof Ee)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${le(o)}
|
|
622
|
+
`,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function cr(e,t){let s="",n="";for(let r of t.clauses){let i=await xs(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return Dt(e,r.body,s,n)}return t.elseBody?Dt(e,t.elseBody,s,n):_(s,n,0)}async function fr(e,t){let s=await ge(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return S(`bash: \`${t.variable}': not a valid identifier
|
|
623
|
+
`);let o=[];if(t.words===null)o=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let l of t.words){let c=await me(e,l);o.push(...c.values)}}catch(l){if(l instanceof tt)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of o){a++,a>e.limits.maxLoopIterations&&ve(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,l);try{for(let c of t.body){let u=await e.executeStatement(c);n+=u.stdout,r+=u.stderr,i=u.exitCode}}catch(c){let u=Ke(c,n,r,e.state.loopDepth);if(n=u.stdout,r=u.stderr,u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let d=_(n,r,u.exitCode??1);return B(e,d,t.redirections)}throw u.error}}}finally{e.state.loopDepth--}let f=_(n,r,i);return B(e,f,t.redirections)}async function ur(e,t){let s=await ge(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",a=0,o=0;t.init&&await V(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&ve(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await V(e,t.condition.expression)===0));){try{for(let l of t.body){let c=await e.executeStatement(l);r+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(l){let c=Ke(l,r,i,e.state.loopDepth);if(r=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await V(e,t.update.expression);continue}if(c.action==="error"){let u=_(r,i,c.exitCode??1);return B(e,u,t.redirections)}throw c.error}t.update&&await V(e,t.update.expression)}}finally{e.state.loopDepth--}let f=_(r,i,a);return B(e,f,t.redirections)}async function dr(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let c=l.target,u=await T(e,c.content);c.stripTabs&&(u=u.split(`
|
|
624
624
|
`).map(d=>d.replace(/^\t+/,"")).join(`
|
|
625
|
-
`)),o=u}else if(
|
|
626
|
-
`;else if(
|
|
627
|
-
`)}let
|
|
628
|
-
`,t||
|
|
629
|
-
`),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let
|
|
630
|
-
`?
|
|
631
|
-
`}async function
|
|
632
|
-
`:""}async function
|
|
625
|
+
`)),o=u}else if(l.operator==="<<<"&&l.target.type==="Word")o=`${await T(e,l.target)}
|
|
626
|
+
`;else if(l.operator==="<"&&l.target.type==="Word")try{let c=await T(e,l.target),u=e.fs.resolvePath(e.state.cwd,c);o=await e.fs.readFile(u)}catch{let c=await T(e,l.target);return S(`bash: ${c}: No such file or directory
|
|
627
|
+
`)}let f=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&ve(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let l=0,c=!1,u=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,l=m.exitCode}}catch(h){if(h instanceof re){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;c=!0}else if(h instanceof ie){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;u=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!u){if(l!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=Ke(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return _(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=f}return _(n,r,i)}async function hr(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&ve(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await xs(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let f=await e.executeStatement(o);s+=f.stdout,n+=f.stderr,r=f.exitCode}}catch(o){let f=Ke(o,s,n,e.state.loopDepth);if(s=f.stdout,n=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return _(s,n,f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--}return _(s,n,r)}async function pr(e,t){let s=await ge(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await T(e,t.word),o=!1;for(let l=0;l<t.items.length;l++){let c=t.items[l],u=o;if(!o)for(let d of c.patterns){let h=await T(e,d);Qs(d)&&(h=Xs(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(Le(a,h,m,p)){u=!0;break}}if(u){let d=await Dt(e,c.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,c.terminator===";;")break;c.terminator===";&"?o=!0:o=!1}else o=!1}let f=_(n,r,i);return B(e,f,t.redirections)}function Rs(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function mr(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),f=o.indexOf(":");if(f===-1)return null;let l=Number.parseInt(o.slice(0,f),10);if(Number.isNaN(l)||l<0)return null;let c=o.slice(f+1);return{path:i,position:l,content:c}}var yr="+ ";async function gr(e){let t=e.state.env.get("PS4");if(t===void 0)return yr;if(t==="")return"";try{let n=new F().parseWordFromString(t,!1,!1);return await T(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
|
|
628
|
+
`,t||yr}}function Ui(e){return e.map(t=>qi(t)).join(" ")}function qi(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
|
|
629
|
+
`),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let f="";for(let l of e){let c=l.charCodeAt(0);l===`
|
|
630
|
+
`?f+="\\n":l===" "?f+="\\t":l==="\\"?f+="\\\\":l==="'"?f+="'":l==='"'?f+='"':c<32||c===127?c<256?f+=`\\x${c.toString(16).padStart(2,"0")}`:f+=`\\u${c.toString(16).padStart(4,"0")}`:f+=l}return`$'${f}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function wr(e,t,s){if(!e.state.options.xtrace)return"";let n=await gr(e),r=[t,...s],i=Ui(r);return`${n}${i}
|
|
631
|
+
`}async function vr(e,t,s){return e.state.options.xtrace?`${await gr(e)}${t}=${s}
|
|
632
|
+
`:""}async function br(e,t,s){let n=t.timed?performance.now():0,r="",i=L,a=0,o=[],f=t.commands.length>1,l=e.state.lastArg;for(let u=0;u<t.commands.length;u++){let d=t.commands[u],h=u===t.commands.length-1;f&&(e.state.lastArg="");let p=f&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,g;try{g=await s(d,r)}catch(v){if(v instanceof et)g={stdout:v.stdout,stderr:v.stderr,exitCode:1};else if(v instanceof z&&t.commands.length>1)g={stdout:v.stdout,stderr:v.stderr,exitCode:v.exitCode};else if(v instanceof ae&&t.commands.length>1)g={stdout:v.stdout,stderr:v.stderr,exitCode:v.exitCode};else throw p&&(e.state.env=p),v}p&&(e.state.env=p),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),h?i=g:t.pipeStderr?.[u]??!1?(r=g.stderr+g.stdout,i={stdout:"",stderr:"",exitCode:g.exitCode}):(r=g.stdout,i={stdout:"",stderr:g.stderr,exitCode:g.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let u of e.state.env.keys())u.startsWith("PIPESTATUS_")&&e.state.env.delete(u);for(let u=0;u<o.length;u++)e.state.env.set(`PIPESTATUS_${u}`,String(o[u]));e.state.env.set("PIPESTATUS__length",String(o.length))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
|
|
633
633
|
user 0.00
|
|
634
634
|
sys 0.00
|
|
635
635
|
`:p=`
|
|
636
636
|
real ${`${h}m${m.toFixed(3)}s`}
|
|
637
637
|
user 0m0.000s
|
|
638
638
|
sys 0m0.000s
|
|
639
|
-
`,i={...i,stderr:i.stderr+p}}return
|
|
640
|
-
`,1)};let
|
|
641
|
-
`,1)};if(oe(e,s)){let c=
|
|
642
|
-
`,1)}}if(
|
|
643
|
-
`,{continueToNext:!0,xtraceOutput:a};let c=K(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let o=e.state.associativeArrays?.has(s),
|
|
644
|
-
`)}}async function
|
|
645
|
-
`,1)};o=u}}if(
|
|
646
|
-
`;if(i.fatal)throw new z(1,"",
|
|
639
|
+
`,i={...i,stderr:i.stderr+p}}return f&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=l),i}async function Er(e,t){let s=new Map,n="";for(let r of t.assignments){let i=r.name;if(r.array){let c=await Zi(e,t,i,r.array,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};if(n+=c.xtraceOutput,c.continueToNext)continue}let a=r.value?await T(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:_("",`bash: ${i}: bad array subscript
|
|
640
|
+
`,1)};let f=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let c=await Qi(e,t,f[1],f[2],a,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let l=await ea(e,t,i,a,r.append,s);if(l.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:l.error};n+=l.xtraceOutput,l.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function Zi(e,t,s,n,r,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
|
|
641
|
+
`,1)};if(oe(e,s)){let c=Gs(e,s);if(c===void 0||c==="")throw new z(1,"","");let u=Ae(e,s);if(u&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(u))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
|
|
642
|
+
`,1)}}if(Oe(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
|
|
643
|
+
`,{continueToNext:!0,xtraceOutput:a};let c=K(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let o=e.state.associativeArrays?.has(s),f=Gi(n),l=()=>{let c=`${s}_`;for(let u of e.state.env.keys())u.startsWith(c)&&!u.includes("__")&&e.state.env.delete(u);e.state.env.delete(s)};if(o&&f?await Ki(e,t,s,n,r,l,c=>{a+=c}):f?await Xi(e,s,n,r,l):await Yi(e,s,n,r,l),t.name){i.set(s,e.state.env.get(s));let u=`(${n.map(d=>rt(d)).join(" ")})`;e.state.env.set(s,u)}return{continueToNext:!0,xtraceOutput:a}}function Gi(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function Ki(e,t,s,n,r,i,a){let o=[];for(let f of n){let l=Rt(f);if(l){let{key:c,valueParts:u,append:d}=l,h;u.length>0?h=await T(e,{type:"Word",parts:u}):h="",h=H(e,h),o.push({type:"keyed",key:c,value:h,append:d})}else{let c=await T(e,f);o.push({type:"invalid",expandedValue:c})}}r||i();for(let f of o)if(f.type==="keyed")if(f.append){let l=e.state.env.get(`${s}_${f.key}`)??"";e.state.env.set(`${s}_${f.key}`,l+f.value)}else e.state.env.set(`${s}_${f.key}`,f.value);else{let l=t.line??e.state.currentLine??1;a(`bash: line ${l}: ${s}: ${f.expandedValue}: must use subscript when assigning associative array
|
|
644
|
+
`)}}async function Xi(e,t,s,n,r){let i=[];for(let o of s){let f=Rt(o);if(f){let{key:l,valueParts:c,append:u}=f,d;c.length>0?d=await T(e,{type:"Word",parts:c}):d="",d=H(e,d),i.push({type:"keyed",indexExpr:l,value:d,append:u})}else{let l=await me(e,o);i.push({type:"non-keyed",values:l.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let f;try{let l=new F,c=q(l,o.indexExpr);f=await V(e,c.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))f=Number.parseInt(o.indexExpr,10);else{let l=e.state.env.get(o.indexExpr);f=l?Number.parseInt(l,10):0,Number.isNaN(f)&&(f=0)}}if(o.append){let l=e.state.env.get(`${t}_${f}`)??"";e.state.env.set(`${t}_${f}`,l+o.value)}else e.state.env.set(`${t}_${f}`,o.value);a=f+1}else for(let f of o.values)e.state.env.set(`${t}_${a++}`,f)}async function Yi(e,t,s,n,r){let i=[];for(let o of s){let f=await me(e,o);i.push(...f.values)}let a=0;if(n){let o=fe(e,t);if(o.length>0)a=Math.max(...o.map(([l])=>typeof l=="number"?l:0))+1;else{let f=e.state.env.get(t);f!==void 0&&(e.state.env.set(`${t}_0`,f),e.state.env.delete(t),a=1)}}else r();for(let o=0;o<i.length;o++)e.state.env.set(`${t}_${a+o}`,i[o]);n||e.state.env.set(`${t}__length`,String(i.length))}async function Qi(e,t,s,n,r,i,a){let o=s;if(oe(e,s)){let u=Ae(e,s);if(u&&u!==s){if(u.includes("["))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: \`${u}': not a valid identifier
|
|
645
|
+
`,1)};o=u}}if(Oe(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let f=e.state.associativeArrays?.has(o),l;if(f)l=await $r(e,o,n);else{let u=await Ji(e,o,n);if(u.error)return{continueToNext:!1,xtraceOutput:"",error:u.error};l=`${o}_${u.index}`}let c=i?(e.state.env.get(l)||"")+r:r;if(t.name)a.set(l,e.state.env.get(l)),e.state.env.set(l,c);else{let u=We(e,o);if(u!==void 0&&u===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(l)||d.set(l,e.state.env.get(l))}e.state.env.set(l,c)}return{continueToNext:!0,xtraceOutput:""}}async function $r(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),a=new F().parseWordFromString(r,!0,!1);n=await T(e,a)}else if(s.includes("$")){let i=new F().parseWordFromString(s,!1,!1);n=await T(e,i)}else n=s;return`${t}_${n}`}async function Ji(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new F,a=q(i,n);r=await V(e,a.expression,!1)}catch(i){if(i instanceof ke){let f=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
|
|
646
|
+
`;if(i.fatal)throw new z(1,"",f);return{index:0,error:_("",f,1)}}let a=e.state.env.get(s);r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=fe(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:_("",`bash: line ${o}: ${t}[${s}]: bad array subscript
|
|
647
647
|
`,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:_("",`bash: line ${o}: ${t}[${s}]: bad array subscript
|
|
648
|
-
`,1)}}}return{index:r}}async function
|
|
649
|
-
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};o=u;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(
|
|
650
|
-
`,{continueToNext:!0,xtraceOutput:a};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let
|
|
651
|
-
`,1);return
|
|
648
|
+
`,1)}}}return{index:r}}async function ea(e,t,s,n,r,i){let a="",o=s,f=null;if(oe(e,s)){let u=Ks(e,s,n);if(u===void 0)return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: circular name reference
|
|
649
|
+
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};o=u;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(f={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Oe(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
|
|
650
|
+
`,{continueToNext:!0,xtraceOutput:a};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let l;if(qe(e,o))try{let u=new F;if(r){let h=`(${e.state.env.get(o)||"0"}) + (${n})`,m=q(u,h);l=String(await V(e,m.expression))}else{let d=q(u,n);l=String(await V(e,d.expression))}}catch{l="0"}else{let{isArray:u}=await import("./chunks/expansion-IEMZ6T22.js"),d=u(e,o)?`${o}_0`:o;l=r?(e.state.env.get(d)||"")+n:n}l=Fe(e,o,l),a+=await vr(e,o,l);let c=o;if(f)c=await ta(e,f);else{let{isArray:u}=await import("./chunks/expansion-IEMZ6T22.js");u(e,o)&&(c=`${o}_0`)}return t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,l)):(e.state.env.set(c,l),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(u=>u.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function ta(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return $r(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new F,o=q(a,n);i=await V(e,o.expression,!1)}catch{let a=e.state.env.get(n);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=fe(e,s);a.length>0&&(i=Math.max(...a.map(f=>f[0]))+1+i)}return`${s}_${i}`}async function Sr(e,t,s,n){let r=await ge(e,t.redirections);if(r)return r;let i=new Map(e.state.env),a=e.state.cwd,o={...e.state.options},f=e.state.localScopes,l=e.state.localVarStack,c=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=f.map(b=>new Map(b)),l){e.state.localVarStack=new Map;for(let[b,C]of l.entries())e.state.localVarStack.set(b,C.map(O=>({...O})))}c&&(e.state.localVarDepth=new Map(c)),u&&(e.state.fullyUnsetLocals=new Map(u));let d=e.state.loopDepth,h=e.state.parentHasLoopContext;e.state.parentHasLoopContext=d>0,e.state.loopDepth=0;let m=e.state.lastArg,p=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let g=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",$="",N=0,y=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.localScopes=f,e.state.localVarStack=l,e.state.localVarDepth=c,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=g,e.state.bashPid=p,e.state.lastArg=m};try{for(let b of t.body){let C=await n(b);v+=C.stdout,$+=C.stderr,N=C.exitCode}}catch(b){if(y(),b instanceof ee)throw b;if(b instanceof Ee){v+=b.stdout,$+=b.stderr;let O=_(v,$,0);return B(e,O,t.redirections)}if(b instanceof re||b instanceof ie){v+=b.stdout,$+=b.stderr;let O=_(v,$,0);return B(e,O,t.redirections)}if(b instanceof z){v+=b.stdout,$+=b.stderr;let O=_(v,$,b.exitCode);return B(e,O,t.redirections)}if(b instanceof te){v+=b.stdout,$+=b.stderr;let O=_(v,$,b.exitCode);return B(e,O,t.redirections)}if(b instanceof ae){let O=_(v+b.stdout,$+b.stderr,b.exitCode);return B(e,O,t.redirections)}let C=_(v,`${$}${le(b)}
|
|
651
|
+
`,1);return B(e,C,t.redirections)}y();let w=_(v,$,N);return B(e,w,t.redirections)}async function Ar(e,t,s,n){let r="",i="",a=0,o=await St(e,t.redirections);if(o)return o;let f=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let d=u.target,h=await T(e,d.content);d.stripTabs&&(h=h.split(`
|
|
652
652
|
`).map(p=>p.replace(/^\t+/,"")).join(`
|
|
653
|
-
`));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):
|
|
654
|
-
`;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await
|
|
655
|
-
`,1)}let
|
|
656
|
-
`,1)}e.state.groupStdin=
|
|
653
|
+
`));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):f=h}else if(u.operator==="<<<"&&u.target.type==="Word")f=`${await T(e,u.target)}
|
|
654
|
+
`;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await T(e,u.target),h=e.fs.resolvePath(e.state.cwd,d);f=await e.fs.readFile(h)}catch{let d=await T(e,u.target);return _("",`bash: ${d}: No such file or directory
|
|
655
|
+
`,1)}let l=e.state.groupStdin;f&&(e.state.groupStdin=f);try{for(let u of t.body){let d=await n(u);r+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(u){if(e.state.groupStdin=l,u instanceof ee)throw u;if(st(u)||u instanceof ae||u instanceof z)throw u.prependOutput(r,i),u;return _(r,`${i}${le(u)}
|
|
656
|
+
`,1)}e.state.groupStdin=l;let c=_(r,i,a);return B(e,c,t.redirections)}async function _r(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return S(`bash: ${t}: No such file or directory
|
|
657
657
|
`,127)}if(i.startsWith("#!")){let g=i.indexOf(`
|
|
658
|
-
`);g!==-1&&(i=i.slice(g+1))}let a=
|
|
659
|
-
`);throw g}}var
|
|
660
|
-
`);let r=0,i=-1,a=!1;for(let
|
|
661
|
-
`).map(
|
|
662
|
-
`));let C=y.fd??0;C!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(C,
|
|
663
|
-
`;continue}if(y.operator==="<"&&y.target.type==="Word")try{let w=await
|
|
664
|
-
`)}if(y.operator==="<&"&&y.target.type==="Word"){let w=await
|
|
665
|
-
`,127)}if(c==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let w=await
|
|
666
|
-
`)}break}case"<>":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let
|
|
667
|
-
`);return
|
|
668
|
-
`,r);return
|
|
669
|
-
|
|
658
|
+
`);g!==-1&&(i=i.slice(g+1))}let a=new Map(e.state.env),o=e.state.cwd,f={...e.state.options},l=e.state.loopDepth,c=e.state.parentHasLoopContext,u=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=l>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let g=0;g<s.length&&g<9;g++)e.state.env.set(String(g+1),s[g]);for(let g=s.length+1;g<=9;g++)e.state.env.delete(String(g));let p=()=>{e.state.env=a,e.state.cwd=o,e.state.options=f,e.state.loopDepth=l,e.state.parentHasLoopContext=c,e.state.lastArg=u,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let v=new F().parse(i),$=await r(v);return p(),$}catch(g){if(p(),g instanceof z||g instanceof ee)throw g;if(g.name==="ParseException")return S(`bash: ${t}: ${g.message}
|
|
659
|
+
`);throw g}}var Xe=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let a=this.ctx.state.env.get(i);a!==void 0&&(r[i]=a)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let a=await this.executeStatement(i);s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(a){if(a instanceof z)throw a.prependOutput(s,n),a;if(a instanceof ce)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:$e(this.ctx.state.env)};if(a instanceof ee)throw a;if(a instanceof ae)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:$e(this.ctx.state.env)};if(a instanceof Fs)return s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:$e(this.ctx.state.env)};if(a instanceof et)return s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:$e(this.ctx.state.env)};if(a instanceof ke){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(a instanceof zs){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(a instanceof re||a instanceof ie){if(this.ctx.state.loopDepth>0)throw a.prependOutput(s,n),a;s+=a.stdout,n+=a.stderr;continue}throw a instanceof te&&a.prependOutput(s,n),a}return{stdout:s,stderr:n,exitCode:r,env:$e(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return _r(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&ve(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new nt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
|
|
660
|
+
`);let r=0,i=-1,a=!1;for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let d=await this.executePipeline(c);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=l,a=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let o=i<t.pipelines.length-1,f=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||a||f,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!f)throw new ae(r,s,n);return _(s,n,r)}async executePipeline(t){return br(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return cr(this.ctx,t);case"For":return fr(this.ctx,t);case"CStyleFor":return ur(this.ctx,t);case"While":return dr(this.ctx,t,s);case"Until":return hr(this.ctx,t);case"Case":return pr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Dn(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof tt)return S(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,w=100;for(;w>0;){let b=this.expandAlias(y);if(b===y)break;y=b,w--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Er(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let w=await ge(this.ctx,t.redirections);if(w)return w;let b=_("",i,0);return B(this.ctx,b,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",_("",y,this.ctx.state.lastExitCode)}let a=t.name&&Rs(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(r.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of o)this.ctx.state.tempExportedVars.add(y)}let f=await St(this.ctx,t.redirections);if(f){for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);return f}let l=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let w=y.target,b=await T(this.ctx,w.content);w.stripTabs&&(b=b.split(`
|
|
661
|
+
`).map(O=>O.replace(/^\t+/,"")).join(`
|
|
662
|
+
`));let C=y.fd??0;C!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(C,b)):s=b;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await T(this.ctx,y.target)}
|
|
663
|
+
`;continue}if(y.operator==="<"&&y.target.type==="Word")try{let w=await T(this.ctx,y.target),b=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);s=await this.ctx.fs.readFile(b)}catch{let w=await T(this.ctx,y.target);for(let[b,C]of r)C===void 0?this.ctx.state.env.delete(b):this.ctx.state.env.set(b,C);return S(`bash: ${w}: No such file or directory
|
|
664
|
+
`)}if(y.operator==="<&"&&y.target.type==="Word"){let w=await T(this.ctx,y.target),b=Number.parseInt(w,10);if(!Number.isNaN(b)&&this.ctx.state.fileDescriptors){let C=this.ctx.state.fileDescriptors.get(b);if(C!==void 0)if(C.startsWith("__rw__:")){let O=mr(C);O&&(s=O.content.slice(O.position),l=b)}else C.startsWith("__file__:")||C.startsWith("__file_append__:")||(s=C)}}}let c=await T(this.ctx,t.name),u=[],d=[];if(Rs(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let y of t.args){let w=await pn(this.ctx,y);if(w)u.push(w),d.push(!0);else{let b=await mn(this.ctx,y);if(b!==null)u.push(b),d.push(!0);else{let C=await me(this.ctx,y);for(let O of C.values)u.push(O),d.push(C.quoted)}}}else for(let y of t.args){let w=await me(this.ctx,y);for(let b of w.values)u.push(b),d.push(w.quoted)}if(!c){if(t.name.parts.every(w=>w.type==="CommandSubstitution"||w.type==="ParameterExpansion"||w.type==="ArithmeticExpansion")){if(u.length>0){let w=u.shift();return d.shift(),await this.runCommand(w,u,d,s,!1,!1,l)}return _("","",this.ctx.state.lastExitCode)}return S(`bash: : command not found
|
|
665
|
+
`,127)}if(c==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let w=await T(this.ctx,y.target),b=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);await this.ctx.fs.writeFile(C,"","utf8"),this.ctx.state.fileDescriptors.set(b,`__file__:${C}`);break}case">>":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);this.ctx.state.fileDescriptors.set(b,`__file_append__:${C}`);break}case"<":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let O=await this.ctx.fs.readFile(C);this.ctx.state.fileDescriptors.set(b,O)}catch{return S(`bash: ${w}: No such file or directory
|
|
666
|
+
`)}break}case"<>":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let O=await this.ctx.fs.readFile(C);this.ctx.state.fileDescriptors.set(b,`__rw__:${C.length}:${C}:0:${O}`)}catch{await this.ctx.fs.writeFile(C,"","utf8"),this.ctx.state.fileDescriptors.set(b,`__rw__:${C.length}:${C}:0:`)}break}case">&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let C=w.slice(0,-1),O=Number.parseInt(C,10);if(!Number.isNaN(O)){let D=this.ctx.state.fileDescriptors.get(O);D!==void 0?this.ctx.state.fileDescriptors.set(b,D):this.ctx.state.fileDescriptors.set(b,`__dupout__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let C=Number.parseInt(w,10);Number.isNaN(C)||this.ctx.state.fileDescriptors.set(b,`__dupout__:${C}`)}break}case"<&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let C=w.slice(0,-1),O=Number.parseInt(C,10);if(!Number.isNaN(O)){let D=this.ctx.state.fileDescriptors.get(O);D!==void 0?this.ctx.state.fileDescriptors.set(b,D):this.ctx.state.fileDescriptors.set(b,`__dupin__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let C=Number.parseInt(w,10);Number.isNaN(C)||this.ctx.state.fileDescriptors.set(b,`__dupin__:${C}`)}break}}}for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return L}let m=await wr(this.ctx,c,u);r.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let p,g=null;try{p=await this.runCommand(c,u,d,s,!1,!1,l)}catch(y){if(y instanceof re||y instanceof ie)g=y,p=L;else throw y}let v=i+m;if(v&&(p={...p,stderr:v+p.stderr}),p=await B(this.ctx,p,t.redirections),g)throw g;if(u.length>0){let y=u[u.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let w=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);w&&(y=w[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=c;let $=kn(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!$)for(let[y,w]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,a=!1,o=-1){let f={ctx:this.ctx,runCommand:(c,u,d,h,m,p,g)=>this.runCommand(c,u,d,h,m,p,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,u,d)=>this.executeUserScript(c,u,d)},l=await or(f,t,s,n,r,i,a,o);return l!==null?l:lr(f,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return jt(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Ot(this.ctx,t)}async executeSubshell(t,s=""){return Sr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return Ar(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ge(this.ctx,t.redirections);if(s)return s;try{let n=await V(this.ctx,t.expression.expression),r=U(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),B(this.ctx,r,t.redirections)}catch(n){let r=S(`bash: arithmetic expression: ${n.message}
|
|
667
|
+
`);return B(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ge(this.ctx,t.redirections);if(s)return s;try{let n=await Pe(this.ctx,t.expression),r=U(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),B(this.ctx,r,t.redirections)}catch(n){let r=n instanceof ke?1:2,i=S(`bash: conditional expression: ${n.message}
|
|
668
|
+
`,r);return B(this.ctx,i,t.redirections)}}};var be={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4};function Cr(e){return e?{maxCallDepth:e.maxCallDepth??be.maxCallDepth,maxCommandCount:e.maxCommandCount??be.maxCommandCount,maxLoopIterations:e.maxLoopIterations??be.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??be.maxAwkIterations,maxSedIterations:e.maxSedIterations??be.maxSedIterations,maxJqIterations:e.maxJqIterations??be.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??be.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??be.maxPythonTimeoutMs}:{...be}}function Pr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function sa(e){let t=Pr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function na(e,t){let s=Pr(e);if(!s)return!1;let n=sa(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function Ls(e,t){return!t||t.length===0?!1:t.some(s=>na(e,s))}var Ye=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},Qe=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Je=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},It=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var ra=20,ia=3e4,aa=["GET","HEAD"],oa=new Set(["GET","HEAD","OPTIONS"]),la=new Set([301,302,303,307,308]);function Ws(e){let t=e.maxRedirects??ra,s=e.timeoutMs??ia,n=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??aa;function r(o){if(!e.dangerouslyAllowFullInternetAccess&&!Ls(o,e.allowedUrlPrefixes??[]))throw new Ye(o)}function i(o){if(e.dangerouslyAllowFullInternetAccess)return;let f=o.toUpperCase();if(!n.includes(f))throw new It(f,n)}async function a(o,f={}){let l=f.method?.toUpperCase()??"GET";r(o),i(l);let c=o,u=0,d=f.followRedirects??!0,h=f.timeoutMs!==void 0?Math.min(f.timeoutMs,s):s;for(;;){let m=new AbortController,p=setTimeout(()=>m.abort(),h);try{let g={method:l,headers:f.headers,signal:m.signal,redirect:"manual"};f.body&&!oa.has(l)&&(g.body=f.body);let v=await fetch(c,g);if(la.has(v.status)&&d){let $=v.headers.get("location");if(!$)return await Nr(v,c);let N=new URL($,c).href;if(!e.dangerouslyAllowFullInternetAccess&&!Ls(N,e.allowedUrlPrefixes??[]))throw new Je(N);if(u++,u>t)throw new Qe(t);c=N;continue}return await Nr(v,c)}finally{clearTimeout(p)}}}return a}async function Nr(e,t){let s=Object.create(null);return e.headers.forEach((n,r)=>{s[r.toLowerCase()]=n}),{status:e.status,statusText:e.statusText,headers:s,body:await e.text(),url:t}}var Tt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(t={}){let s=t.fs??new Be(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
669
|
+
`],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",n],["OLDPWD",n],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=Cr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Ws(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Vt(this.state.options)),this.state.env.set("BASHOPTS",Bt(this.state.shoptOptions)),ln(s,this.useDefaultLayout),n!=="/"&&s instanceof Be)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of nn(t.commands))this.registerCommand(i);if(t.network)for(let i of rn())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)an(i)?this.registerCommand(on(i)):this.registerCommand(i)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
|
|
670
670
|
# Built-in command: ${t.name}
|
|
671
671
|
`;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
|
|
672
|
-
`,exitCode:1,env:
|
|
673
|
-
`,exitCode:2,env:
|
|
674
|
-
`,exitCode:2,env:
|
|
675
|
-
`,exitCode:1,env:
|
|
676
|
-
`),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let
|
|
677
|
-
`)}import*as Z from"node:fs";import*as We from"node:path";var la="/home/user/project",Dt=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=We.resolve(t.root);let s=t.mountPoint??la;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!Z.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!Z.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let a of r)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=We.join(this.root,n),i=We.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await Z.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=$e(s);return rt(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.readFileBuffer(a,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await Z.promises.lstat(i);if(a.isSymbolicLink()){let l=await Z.promises.readlink(i),f=this.resolveSymlink(n,l);return this.readFileBuffer(f,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let o=await Z.promises.readFile(i);return new Uint8Array(o)}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):a}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=$e(n),a=De(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=$e(n),a=De(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let l=new Uint8Array(o.length+a.length);l.set(o),l.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await Z.promises.stat(i);return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):a}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await Z.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),f=l.split("/")[0];f&&!l.includes("/",f.length)&&r.add(f)}for(let[o,l]of this.memory)if(o!==s&&o.startsWith(i)){let f=o.slice(i.length),c=f.split("/")[0];c&&!r.has(c)&&!f.includes("/",1)&&n.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.toRealPath(s);if(a)try{let o=await Z.promises.readdir(a,{withFileTypes:!0});for(let l of o)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(o.code!=="ENOTDIR")throw o}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.toRealPath(n);if(!l)return{normalized:n,outsideOverlay:!0};try{if((await Z.promises.lstat(l)).isSymbolicLink()){let c=await Z.promises.readlink(l),u=this.resolveSymlink(n,c);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(l,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let f of l){let c=r==="/"?`/${f}`:`${r}/${f}`,u=i==="/"?`/${f}`:`${i}/${f}`;await this.cp(c,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=Z.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=We.join(n,i);Z.statSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await Z.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),f="";for(let c of l){if(f=`${f}/${c}`,n.has(f))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(f))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(f),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(f),f=this.resolveSymlink(f,u.target),d++,n.has(f))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(f))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(f)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(f);if(m)try{if((await Z.promises.lstat(m)).isSymbolicLink()){let g=await Z.promises.readlink(m);return n.add(f),f=this.resolveSymlink(f,g),r(f)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return f||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};var Y={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},Rs=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new Dt({root:s,mountPoint:"/"});this.env=new Ot({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Pr.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
|
|
672
|
+
`,exitCode:1,env:de(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:de(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let a=new Map(this.state.env);if(s?.env)for(let[l,c]of Object.entries(s.env))a.set(l,c);r!==void 0&&a.set("PWD",r);let o={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},f=t;s?.rawScript||(f=ca(t));try{let l=he(f),c={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},d=await new Xe(c,o).executeScript(l);return this.logResult(d)}catch(l){if(l instanceof z)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:de(this.state.env,s?.env)});if(l instanceof ce)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:de(this.state.env,s?.env)});if(l instanceof ke)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:1,env:de(this.state.env,s?.env)});if(l instanceof ee)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:ee.EXIT_CODE,env:de(this.state.env,s?.env)});if(l.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${l.message}
|
|
673
|
+
`,exitCode:2,env:de(this.state.env,s?.env)});if(l instanceof Hs)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
674
|
+
`,exitCode:2,env:de(this.state.env,s?.env)});if(l instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
675
|
+
`,exitCode:1,env:de(this.state.env,s?.env)});throw l}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return $e(this.state.env)}};function ca(e){let t=e.split(`
|
|
676
|
+
`),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let f=n[n.length-1];if((f.stripTabs?i.replace(/^\t+/,""):i)===f.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let f of a.matchAll(o)){let l=f[1]==="-",c=f[3];n.push({delimiter:c,stripTabs:l})}}return s.join(`
|
|
677
|
+
`)}import*as Z from"node:fs";import*as ze from"node:path";var fa="/home/user/project",xt=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=ze.resolve(t.root);let s=t.mountPoint??fa;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!Z.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!Z.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let a of r)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=ze.join(this.root,n),i=ze.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await Z.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=Ce(s);return ot(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.readFileBuffer(a,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await Z.promises.lstat(i);if(a.isSymbolicLink()){let f=await Z.promises.readlink(i),l=this.resolveSymlink(n,f);return this.readFileBuffer(l,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let o=await Z.promises.readFile(i);return new Uint8Array(o)}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):a}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=Ce(n),a=xe(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=Ce(n),a=xe(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let f=new Uint8Array(o.length+a.length);f.set(o),f.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:f,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await Z.promises.stat(i);return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):a}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await Z.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let f=o.slice(i.length),l=f.split("/")[0];l&&!f.includes("/",l.length)&&r.add(l)}for(let[o,f]of this.memory)if(o!==s&&o.startsWith(i)){let l=o.slice(i.length),c=l.split("/")[0];c&&!r.has(c)&&!l.includes("/",1)&&n.set(c,{name:c,isFile:f.type==="file",isDirectory:f.type==="directory",isSymbolicLink:f.type==="symlink"})}let a=this.toRealPath(s);if(a)try{let o=await Z.promises.readdir(a,{withFileTypes:!0});for(let f of o)!r.has(f.name)&&!n.has(f.name)&&n.set(f.name,{name:f.name,isFile:f.isFile(),isDirectory:f.isDirectory(),isSymbolicLink:f.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(o.code!=="ENOTDIR")throw o}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let f=this.toRealPath(n);if(!f)return{normalized:n,outsideOverlay:!0};try{if((await Z.promises.lstat(f)).isSymbolicLink()){let c=await Z.promises.readlink(f),u=this.resolveSymlink(n,c);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let f=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(f,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let f=await this.readFileBuffer(r);await this.writeFile(i,f)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let f=await this.readdir(r);for(let l of f){let c=r==="/"?`/${l}`:`${r}/${l}`,u=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=Z.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=ze.join(n,i);Z.statSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let f=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:f,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await Z.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async o=>{let f=o==="/"?[]:o.slice(1).split("/"),l="";for(let c of f){if(l=`${l}/${c}`,n.has(l))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(l))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(l),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(l),l=this.resolveSymlink(l,u.target),d++,n.has(l))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(l))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(l)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(l);if(m)try{if((await Z.promises.lstat(m)).isSymbolicLink()){let g=await Z.promises.readlink(m);return n.add(l),l=this.resolveSymlink(l,g),r(l)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return l||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let f=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:f,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};var Y={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},Ms=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new xt({root:s,mountPoint:"/"});this.env=new Tt({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Or.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
|
|
678
678
|
`),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
|
|
679
679
|
Goodbye!`),process.exit(0)})}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),s=this.env.getEnv().HOME||"/home/user",n=t;return t===s?n="~":t.startsWith(`${s}/`)&&(n=`~${t.slice(s.length)}`),`${Y.green}${Y.bold}user@virtual${Y.reset}:${Y.blue}${Y.bold}${n}${Y.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let n=s.split(/\s+/),r=n[1]?parseInt(n[1],10):0;console.log("exit"),process.exit(r)}this.syncHistory();try{let n=await this.env.exec(s);n.stdout&&process.stdout.write(n.stdout),n.stderr&&process.stderr.write(`${Y.red}${n.stderr}${Y.reset}`)}catch(n){console.error(`${Y.red}Error: ${le(n)}${Y.reset}`)}}}printWelcome(){console.log(`
|
|
680
680
|
${Y.cyan}${Y.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
@@ -686,7 +686,7 @@ ${Y.dim}Exploring: ${process.cwd()}${Y.reset}
|
|
|
686
686
|
|
|
687
687
|
Type ${Y.green}help${Y.reset} for available commands, ${Y.green}exit${Y.reset} to quit.
|
|
688
688
|
Reads from real filesystem, writes stay in memory (OverlayFs).
|
|
689
|
-
`)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function
|
|
689
|
+
`)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function ua(){let e=process.argv.slice(2),t={network:!0};for(let s=0;s<e.length;s++)if(e[s]==="--cwd"&&e[s+1])t.cwd=e[++s];else if(e[s]==="--files"&&e[s+1]){let n=e[++s];try{let r=kr.readFileSync(n,"utf-8");t.files=JSON.parse(r)}catch(r){console.error(`Error reading files from ${n}:`,r),process.exit(1)}}else e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
|
|
690
690
|
Usage: pnpm shell [options]
|
|
691
691
|
|
|
692
692
|
Interactive shell using OverlayFs - reads from the current directory,
|
|
@@ -700,4 +700,4 @@ Options:
|
|
|
700
700
|
Example:
|
|
701
701
|
pnpm shell
|
|
702
702
|
pnpm shell --no-network
|
|
703
|
-
`),process.exit(0));return t}var
|
|
703
|
+
`),process.exit(0));return t}var da=ua(),ha=new Ms(da);ha.run();
|