just-bash 2.5.5 → 2.6.0
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 +2 -2
- package/dist/AGENTS.md +2 -2
- package/dist/ast/types.d.ts +100 -11
- package/dist/bin/chunks/alias-EGIS5LUE.js +7 -0
- package/dist/bin/chunks/awk2-GFEJOWML.js +21 -0
- package/dist/bin/chunks/bash-PGDTHIM2.js +6 -0
- package/dist/bin/chunks/chmod-TYLTHXFR.js +9 -0
- package/dist/bin/chunks/chunk-D5WP4CKS.js +3 -0
- package/dist/bin/chunks/chunk-FSAGDARS.js +74 -0
- package/dist/bin/chunks/chunk-FSZWFMB4.js +16 -0
- package/dist/bin/chunks/chunk-IRUD2E3M.js +17 -0
- package/dist/bin/chunks/chunk-K5IXNHO5.js +8 -0
- package/dist/bin/chunks/chunk-KD3EODLB.js +6 -0
- package/dist/bin/{shell/chunks/echo-WSKTON6U.js → chunks/echo-7I42V66Q.js} +2 -2
- package/dist/bin/chunks/env-7A4MH7BJ.js +9 -0
- package/dist/bin/chunks/expansion-BOR3ELLC.js +2 -0
- package/dist/bin/{shell/chunks/find-CBEJ35BR.js → chunks/find-PHDZK64M.js} +1 -1
- package/dist/bin/{shell/chunks/grep-IIVQXFNI.js → chunks/grep-VX7MJMVN.js} +2 -2
- package/dist/bin/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
- package/dist/bin/{shell/chunks/jq-XXZPU5CA.js → chunks/jq-RGZHJNXC.js} +1 -1
- package/dist/bin/chunks/od-KRKGC2U3.js +5 -0
- package/dist/bin/chunks/printf-YPXD4CRE.js +15 -0
- package/dist/bin/chunks/pwd-L26WH2K4.js +3 -0
- package/dist/bin/{shell/chunks/rg-Q4OTJOEF.js → chunks/rg-RSDLLECO.js} +1 -1
- package/dist/bin/chunks/rmdir-GOODLY5W.js +14 -0
- package/dist/bin/chunks/sed-JPDTWF4W.js +100 -0
- package/dist/bin/{shell/chunks/tail-BES27CZT.js → chunks/tail-YAUIERGN.js} +1 -1
- package/dist/bin/{shell/chunks/tar-C27YYUAS.js → chunks/tar-LFENC54A.js} +7 -7
- package/dist/bin/chunks/time-37F5EBPK.js +14 -0
- package/dist/bin/chunks/touch-IBPHJBM3.js +7 -0
- package/dist/bin/chunks/wc-SAOHEZYP.js +6 -0
- package/dist/bin/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
- package/dist/bin/chunks/whoami-JVLUNKSG.js +3 -0
- package/dist/bin/{shell/chunks/xan-6K2NGTHM.js → chunks/xan-5HNHTFMB.js} +19 -19
- package/dist/bin/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
- package/dist/bin/just-bash.js +659 -135
- package/dist/bin/shell/chunks/alias-EGIS5LUE.js +7 -0
- package/dist/bin/shell/chunks/awk2-GFEJOWML.js +21 -0
- package/dist/bin/shell/chunks/bash-PGDTHIM2.js +6 -0
- package/dist/bin/shell/chunks/chmod-TYLTHXFR.js +9 -0
- package/dist/bin/shell/chunks/chunk-D5WP4CKS.js +3 -0
- package/dist/bin/shell/chunks/chunk-FSAGDARS.js +74 -0
- package/dist/bin/shell/chunks/chunk-FSZWFMB4.js +16 -0
- package/dist/bin/shell/chunks/chunk-IRUD2E3M.js +17 -0
- package/dist/bin/shell/chunks/chunk-K5IXNHO5.js +8 -0
- package/dist/bin/shell/chunks/chunk-KD3EODLB.js +6 -0
- package/dist/bin/{chunks/echo-WSKTON6U.js → shell/chunks/echo-7I42V66Q.js} +2 -2
- package/dist/bin/shell/chunks/env-7A4MH7BJ.js +9 -0
- package/dist/bin/shell/chunks/expansion-BOR3ELLC.js +2 -0
- package/dist/bin/{chunks/find-CBEJ35BR.js → shell/chunks/find-PHDZK64M.js} +1 -1
- package/dist/bin/{chunks/grep-IIVQXFNI.js → shell/chunks/grep-VX7MJMVN.js} +2 -2
- package/dist/bin/shell/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
- package/dist/bin/{chunks/jq-XXZPU5CA.js → shell/chunks/jq-RGZHJNXC.js} +1 -1
- package/dist/bin/shell/chunks/od-KRKGC2U3.js +5 -0
- package/dist/bin/shell/chunks/printf-YPXD4CRE.js +15 -0
- package/dist/bin/shell/chunks/pwd-L26WH2K4.js +3 -0
- package/dist/bin/{chunks/rg-Q4OTJOEF.js → shell/chunks/rg-RSDLLECO.js} +1 -1
- package/dist/bin/shell/chunks/rmdir-GOODLY5W.js +14 -0
- package/dist/bin/shell/chunks/sed-JPDTWF4W.js +100 -0
- package/dist/bin/{chunks/tail-BES27CZT.js → shell/chunks/tail-YAUIERGN.js} +1 -1
- package/dist/bin/{chunks/tar-C27YYUAS.js → shell/chunks/tar-LFENC54A.js} +7 -7
- package/dist/bin/shell/chunks/time-37F5EBPK.js +14 -0
- package/dist/bin/shell/chunks/touch-IBPHJBM3.js +7 -0
- package/dist/bin/shell/chunks/wc-SAOHEZYP.js +6 -0
- package/dist/bin/shell/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
- package/dist/bin/shell/chunks/whoami-JVLUNKSG.js +3 -0
- package/dist/bin/{chunks/xan-6K2NGTHM.js → shell/chunks/xan-5HNHTFMB.js} +19 -19
- package/dist/bin/shell/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
- package/dist/bin/shell/shell.js +664 -140
- package/dist/bundle/browser.js +1251 -606
- package/dist/bundle/chunks/alias-ATFBB6D2.js +6 -0
- package/dist/bundle/chunks/awk2-6FBZTP57.js +20 -0
- package/dist/bundle/chunks/bash-OLRNM52U.js +5 -0
- package/dist/bundle/chunks/chmod-ODWUR7E6.js +8 -0
- package/dist/bundle/chunks/chunk-3AWP5CWK.js +73 -0
- package/dist/bundle/chunks/chunk-CXEWLFNE.js +16 -0
- package/dist/bundle/chunks/chunk-CZPA5RBA.js +5 -0
- package/dist/bundle/chunks/chunk-EEXR5ZDP.js +2 -0
- package/dist/bundle/chunks/chunk-HDQ56CKY.js +15 -0
- package/dist/bundle/chunks/chunk-PSW6BMXW.js +7 -0
- package/dist/bundle/chunks/{echo-VUHWYV6L.js → echo-6S7WE7XB.js} +2 -2
- package/dist/bundle/chunks/env-2UI6XINU.js +8 -0
- package/dist/bundle/chunks/expansion-RIGCFEMA.js +1 -0
- package/dist/bundle/chunks/{find-ACOAWALE.js → find-YGMSVGUV.js} +1 -1
- package/dist/bundle/chunks/{grep-ACVE42JK.js → grep-NIC6JNLH.js} +2 -2
- package/dist/bundle/chunks/{head-FZ6IQHYW.js → head-SA7P5NJ7.js} +1 -1
- package/dist/bundle/chunks/{jq-3YU5HRKE.js → jq-RLRYRPOJ.js} +1 -1
- package/dist/bundle/chunks/od-3FPDPLWJ.js +4 -0
- package/dist/bundle/chunks/printf-66XGXFCD.js +14 -0
- package/dist/bundle/chunks/pwd-S4NVAMC4.js +2 -0
- package/dist/bundle/chunks/{rg-YLZJWCEJ.js → rg-SRMB7L6G.js} +1 -1
- package/dist/bundle/chunks/rmdir-XFQE4ZYV.js +13 -0
- package/dist/bundle/chunks/sed-IV6HLDXU.js +99 -0
- package/dist/bundle/chunks/{tail-PD4RZR6J.js → tail-52LRAWXT.js} +1 -1
- package/dist/bundle/chunks/{tar-QWBXMF7K.js → tar-LWIHPMT6.js} +7 -7
- package/dist/bundle/chunks/time-UWXBG6CS.js +13 -0
- package/dist/bundle/chunks/touch-TDTEBHHI.js +6 -0
- package/dist/bundle/chunks/wc-HE5XARI4.js +5 -0
- package/dist/bundle/chunks/{which-M5MQ6QXQ.js → which-UBLRBDHN.js} +1 -1
- package/dist/bundle/chunks/whoami-YUDAIS32.js +2 -0
- package/dist/bundle/chunks/{xan-2R2APJJ4.js → xan-A6VPI4HJ.js} +19 -19
- package/dist/bundle/chunks/{yq-KANM4MD2.js → yq-L665QPQU.js} +1 -1
- package/dist/bundle/index.js +657 -133
- package/dist/commands/awk/ast.d.ts +1 -0
- package/dist/commands/awk/interpreter/context.d.ts +14 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +2 -0
- package/dist/commands/awk/interpreter/{helpers.d.ts → type-coercion.d.ts} +4 -1
- package/dist/commands/awk/parser2-print.d.ts +35 -0
- package/dist/commands/awk/parser2.d.ts +42 -34
- package/dist/commands/printf/strftime.d.ts +9 -0
- package/dist/commands/query-engine/builtins/array-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/control-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/date-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/format-builtins.d.ts +11 -0
- package/dist/commands/query-engine/builtins/index-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/index.d.ts +17 -0
- package/dist/commands/query-engine/builtins/math-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/navigation-builtins.d.ts +18 -0
- package/dist/commands/query-engine/builtins/object-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/path-builtins.d.ts +20 -0
- package/dist/commands/query-engine/builtins/sql-builtins.d.ts +16 -0
- package/dist/commands/query-engine/builtins/string-builtins.d.ts +15 -0
- package/dist/commands/query-engine/builtins/type-builtins.d.ts +11 -0
- package/dist/commands/query-engine/evaluator.d.ts +10 -2
- package/dist/commands/query-engine/parser-types.d.ts +171 -0
- package/dist/commands/query-engine/parser.d.ts +2 -132
- package/dist/commands/query-engine/path-operations.d.ts +15 -0
- package/dist/commands/query-engine/value-operations.d.ts +39 -0
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/rmdir/rmdir.d.ts +2 -0
- package/dist/commands/sed/lexer.d.ts +12 -0
- package/dist/commands/sed/parser.d.ts +9 -0
- package/dist/commands/sed/sed-regex.d.ts +23 -0
- package/dist/commands/sed/types.d.ts +13 -1
- package/dist/commands/tar/tar-options.d.ts +36 -0
- package/dist/commands/time/time.d.ts +25 -0
- package/dist/commands/whoami/whoami.d.ts +9 -0
- package/dist/commands/xan/moonblade-tokenizer.d.ts +25 -0
- package/dist/fs/in-memory-fs/in-memory-fs.d.ts +12 -0
- package/dist/fs/interface.d.ts +16 -0
- package/dist/fs/mountable-fs/mountable-fs.d.ts +12 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +13 -1
- package/dist/fs/read-write-fs/read-write-fs.d.ts +13 -1
- package/dist/interpreter/alias-expansion.d.ts +23 -0
- package/dist/interpreter/arithmetic.d.ts +1 -6
- package/dist/interpreter/assignment-expansion.d.ts +24 -0
- package/dist/interpreter/builtin-dispatch.d.ts +39 -0
- package/dist/interpreter/builtins/compgen.d.ts +26 -0
- package/dist/interpreter/builtins/complete.d.ts +17 -0
- package/dist/interpreter/builtins/compopt.d.ts +28 -0
- package/dist/interpreter/builtins/declare-array-parsing.d.ts +14 -0
- package/dist/interpreter/builtins/declare-print.d.ts +39 -0
- package/dist/interpreter/builtins/declare.d.ts +10 -4
- package/dist/interpreter/builtins/dirs.d.ts +29 -0
- package/dist/interpreter/builtins/eval.d.ts +1 -1
- package/dist/interpreter/builtins/export.d.ts +1 -0
- package/dist/interpreter/builtins/getopts.d.ts +18 -0
- package/dist/interpreter/builtins/hash.d.ts +19 -0
- package/dist/interpreter/builtins/help.d.ts +12 -0
- package/dist/interpreter/builtins/index.d.ts +9 -1
- package/dist/interpreter/builtins/local.d.ts +1 -1
- package/dist/interpreter/builtins/read.d.ts +1 -1
- package/dist/interpreter/builtins/set.d.ts +3 -0
- package/dist/interpreter/builtins/shift.d.ts +3 -0
- package/dist/interpreter/builtins/shopt.d.ts +7 -0
- package/dist/interpreter/builtins/unset.d.ts +5 -1
- package/dist/interpreter/builtins/variable-assignment.d.ts +66 -0
- package/dist/interpreter/command-resolution.d.ts +43 -0
- package/dist/interpreter/conditionals.d.ts +1 -1
- package/dist/interpreter/errors.d.ts +36 -1
- package/dist/interpreter/expansion/analysis.d.ts +15 -17
- package/dist/interpreter/expansion/arith-text-expansion.d.ts +20 -0
- package/dist/interpreter/expansion/array-pattern-ops.d.ts +21 -0
- package/dist/interpreter/expansion/array-prefix-suffix.d.ts +46 -0
- package/dist/interpreter/expansion/array-slice-transform.d.ts +36 -0
- package/dist/interpreter/expansion/array-word-expansion.d.ts +39 -0
- package/dist/interpreter/expansion/command-substitution.d.ts +23 -0
- package/dist/interpreter/expansion/glob-escape.d.ts +32 -0
- package/dist/interpreter/expansion/indirect-expansion.d.ts +42 -0
- package/dist/interpreter/expansion/parameter-ops.d.ts +113 -0
- package/dist/interpreter/expansion/pattern-expansion.d.ts +23 -0
- package/dist/interpreter/expansion/pattern-removal.d.ts +18 -0
- package/dist/interpreter/expansion/pattern.d.ts +2 -1
- package/dist/interpreter/expansion/positional-params.d.ts +59 -0
- package/dist/interpreter/expansion/prompt.d.ts +39 -0
- package/dist/interpreter/expansion/quoting.d.ts +13 -0
- package/dist/interpreter/expansion/tilde.d.ts +12 -0
- package/dist/interpreter/expansion/unquoted-expansion.d.ts +76 -0
- package/dist/interpreter/expansion/variable-attrs.d.ts +19 -0
- package/dist/interpreter/expansion/variable.d.ts +10 -1
- package/dist/interpreter/expansion/word-glob-expansion.d.ts +33 -0
- package/dist/interpreter/expansion/word-split.d.ts +11 -6
- package/dist/interpreter/expansion.d.ts +30 -4
- package/dist/interpreter/functions.d.ts +1 -1
- package/dist/interpreter/helpers/array.d.ts +20 -0
- package/dist/interpreter/helpers/ifs.d.ts +66 -5
- package/dist/interpreter/helpers/nameref.d.ts +65 -0
- package/dist/interpreter/helpers/quoting.d.ts +24 -0
- package/dist/interpreter/helpers/readonly.d.ts +28 -4
- package/dist/interpreter/helpers/shell-constants.d.ts +25 -0
- package/dist/interpreter/helpers/shellopts.d.ts +28 -0
- package/dist/interpreter/helpers/string-compare.d.ts +3 -1
- package/dist/interpreter/helpers/tilde.d.ts +13 -0
- package/dist/interpreter/helpers/variable-tests.d.ts +1 -1
- package/dist/interpreter/helpers/word-matching.d.ts +26 -0
- package/dist/interpreter/helpers/xtrace.d.ts +18 -0
- package/dist/interpreter/interpreter.d.ts +13 -14
- package/dist/interpreter/pipeline-execution.d.ts +16 -0
- package/dist/interpreter/redirections.d.ts +38 -1
- package/dist/interpreter/simple-command-assignments.d.ts +29 -0
- package/dist/interpreter/subshell-group.d.ts +32 -0
- package/dist/interpreter/type-command.d.ts +37 -0
- package/dist/interpreter/types.d.ts +255 -21
- package/dist/parser/arithmetic-parser.d.ts +2 -4
- package/dist/parser/arithmetic-primaries.d.ts +45 -0
- package/dist/parser/compound-parser.d.ts +21 -7
- package/dist/parser/expansion-parser.d.ts +7 -1
- package/dist/parser/lexer.d.ts +57 -0
- package/dist/parser/parser-substitution.d.ts +62 -0
- package/dist/parser/parser.d.ts +39 -2
- package/dist/parser/types.d.ts +1 -0
- package/dist/types.d.ts +17 -0
- package/package.json +4 -1
- package/dist/bin/chunks/alias-PCMLRCRW.js +0 -7
- package/dist/bin/chunks/awk2-D2US2LMM.js +0 -20
- package/dist/bin/chunks/bash-UT3MT5UU.js +0 -7
- package/dist/bin/chunks/chmod-3DIKREF7.js +0 -9
- package/dist/bin/chunks/chunk-ACRTDIBO.js +0 -6
- package/dist/bin/chunks/chunk-DV5HL4K2.js +0 -17
- package/dist/bin/chunks/chunk-J7BCMQDI.js +0 -16
- package/dist/bin/chunks/chunk-NWWB2XRE.js +0 -6
- package/dist/bin/chunks/chunk-PM2DS2YW.js +0 -3
- package/dist/bin/chunks/env-YLLSNZZN.js +0 -9
- package/dist/bin/chunks/od-SLM7SRWU.js +0 -7
- package/dist/bin/chunks/printf-HWUQKYUM.js +0 -14
- package/dist/bin/chunks/pwd-53KG2MCJ.js +0 -3
- package/dist/bin/chunks/sed-5LQMJYRJ.js +0 -80
- package/dist/bin/chunks/touch-TSNAXMZ2.js +0 -4
- package/dist/bin/chunks/wc-QSBRKIF5.js +0 -6
- package/dist/bin/shell/chunks/alias-PCMLRCRW.js +0 -7
- package/dist/bin/shell/chunks/awk2-D2US2LMM.js +0 -20
- package/dist/bin/shell/chunks/bash-UT3MT5UU.js +0 -7
- package/dist/bin/shell/chunks/chmod-3DIKREF7.js +0 -9
- package/dist/bin/shell/chunks/chunk-ACRTDIBO.js +0 -6
- package/dist/bin/shell/chunks/chunk-DV5HL4K2.js +0 -17
- package/dist/bin/shell/chunks/chunk-J7BCMQDI.js +0 -16
- package/dist/bin/shell/chunks/chunk-NWWB2XRE.js +0 -6
- package/dist/bin/shell/chunks/chunk-PM2DS2YW.js +0 -3
- package/dist/bin/shell/chunks/env-YLLSNZZN.js +0 -9
- package/dist/bin/shell/chunks/od-SLM7SRWU.js +0 -7
- package/dist/bin/shell/chunks/printf-HWUQKYUM.js +0 -14
- package/dist/bin/shell/chunks/pwd-53KG2MCJ.js +0 -3
- package/dist/bin/shell/chunks/sed-5LQMJYRJ.js +0 -80
- package/dist/bin/shell/chunks/touch-TSNAXMZ2.js +0 -4
- package/dist/bin/shell/chunks/wc-QSBRKIF5.js +0 -6
- package/dist/bundle/chunks/alias-4UGRF4DM.js +0 -6
- package/dist/bundle/chunks/awk2-46RTIZKB.js +0 -19
- package/dist/bundle/chunks/bash-ZILV3VHA.js +0 -6
- package/dist/bundle/chunks/chmod-FBHLEIY6.js +0 -8
- package/dist/bundle/chunks/chunk-4JO5BKO4.js +0 -5
- package/dist/bundle/chunks/chunk-BOJ3OAZB.js +0 -16
- package/dist/bundle/chunks/chunk-CG2HXOFG.js +0 -5
- package/dist/bundle/chunks/chunk-NWEGHOXL.js +0 -2
- package/dist/bundle/chunks/chunk-W2EKKAIL.js +0 -15
- package/dist/bundle/chunks/env-EG5SQSAQ.js +0 -8
- package/dist/bundle/chunks/od-ECWXNUB4.js +0 -6
- package/dist/bundle/chunks/printf-VG2POOXB.js +0 -13
- package/dist/bundle/chunks/pwd-AC4P3JKI.js +0 -2
- package/dist/bundle/chunks/sed-ZKODWZ6F.js +0 -79
- package/dist/bundle/chunks/touch-MVQSKQKT.js +0 -3
- package/dist/bundle/chunks/wc-DFQKWSIZ.js +0 -5
- package/dist/interpreter/builtins/variable-helpers.d.ts +0 -30
- /package/dist/bin/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
- /package/dist/bin/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
- /package/dist/bin/shell/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
- /package/dist/bin/shell/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
- /package/dist/bundle/chunks/{curl-TVZH24MD.js → curl-XLP4VABU.js} +0 -0
- /package/dist/bundle/chunks/{file-XPA6O6H2.js → file-NQP3CKRV.js} +0 -0
- /package/dist/commands/curl/{utils.d.ts → response-formatting.d.ts} +0 -0
- /package/dist/commands/xan/{xan-utils.d.ts → column-selection.d.ts} +0 -0
- /package/dist/fs/{utils.d.ts → encoding.d.ts} +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as r,b as d}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var u={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},o="BASH_ALIAS_",m={name:"alias",async execute(e,a){if(d(e))return r(u);if(e.length===0){let t="";for(let[i,s]of Object.entries(a.env))if(i.startsWith(o)){let n=i.slice(o.length);t+=`alias ${n}='${s}'
|
|
2
|
+
`}return{stdout:t,stderr:"",exitCode:0}}let l=e[0]==="--"?e.slice(1):e;for(let t of l){let i=t.indexOf("=");if(i===-1){let s=o+t;return a.env[s]?{stdout:`alias ${t}='${a.env[s]}'
|
|
3
|
+
`,stderr:"",exitCode:0}:{stdout:"",stderr:`alias: ${t}: not found
|
|
4
|
+
`,exitCode:1}}else{let s=t.slice(0,i),n=t.slice(i+1);(n.startsWith("'")&&n.endsWith("'")||n.startsWith('"')&&n.endsWith('"'))&&(n=n.slice(1,-1)),a.env[o+s]=n}}return{stdout:"",stderr:"",exitCode:0}}},c={name:"unalias",async execute(e,a){if(d(e))return r({name:"unalias",summary:"remove alias definitions",usage:"unalias name [name ...]",options:["-a remove all aliases"," --help display this help and exit"]});if(e.length===0)return{stdout:"",stderr:`unalias: usage: unalias [-a] name [name ...]
|
|
5
|
+
`,exitCode:1};if(e[0]==="-a"){for(let s of Object.keys(a.env))s.startsWith(o)&&delete a.env[s];return{stdout:"",stderr:"",exitCode:0}}let l=e[0]==="--"?e.slice(1):e,t=!1,i="";for(let s of l){let n=o+s;a.env[n]?delete a.env[n]:(i+=`unalias: ${s}: not found
|
|
6
|
+
`,t=!0)}return{stdout:"",stderr:i,exitCode:t?1:0}}};export{m as aliasCommand,c as unaliasCommand};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import{k as C}from"./chunk-PSW6BMXW.js";import{a as te,b as ne,c as X}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";function K(e={}){let{fieldSep:t=/\s+/,maxIterations:n=1e4,maxRecursionDepth:i=100,fs:a,cwd:s,exec:o}=e;return{FS:" ",OFS:" ",ORS:`
|
|
2
|
+
`,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:{},arrays:{},arrayAliases:new Map,ARGC:0,ARGV:{},ENVIRON:{},functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:s,exec:o}}function re(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function k(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function m(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function G(e,t){if(e.type==="regex")return e.pattern;let n=m(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function se(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(k(await t.evalExpr(e.index)))}`:"$0":"$0"}function ae(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return m(t.vars[e]??"")}function oe(e,t,n){if(e==="$0")n.line=t,n.fields=n.FS===" "?t.trim().split(/\s+/).filter(Boolean):t.split(n.fieldSep),n.NF=n.fields.length;else if(e.startsWith("$")){let i=parseInt(e.slice(1),10)-1;for(;n.fields.length<=i;)n.fields.push("");n.fields[i]=t,n.NF=n.fields.length,n.line=n.fields.join(n.OFS)}else n.vars[e]=t}async function ge(e,t,n){return e.length===0?t.line.length:m(await n.evalExpr(e[0])).length}async function ke(e,t,n){if(e.length<2)return"";let i=m(await n.evalExpr(e[0])),a=Math.floor(k(await n.evalExpr(e[1])))-1;if(e.length>=3){let s=Math.floor(k(await n.evalExpr(e[2])));return i.substr(Math.max(0,a),s)}return i.substr(Math.max(0,a))}async function Ce(e,t,n){if(e.length<2)return 0;let i=m(await n.evalExpr(e[0])),a=m(await n.evalExpr(e[1])),s=i.indexOf(a);return s===-1?0:s+1}async function Le(e,t,n){if(e.length<2)return 0;let i=m(await n.evalExpr(e[0])),a=e[1];if(a.type!=="variable")return 0;let s=a.name,o=t.FS;if(e.length>=3){let h=e[2];if(h.type==="regex")o=new RegExp(h.pattern);else{let N=m(await n.evalExpr(h));o=N===" "?/\s+/:N}}else t.FS===" "&&(o=/\s+/);let l=i.split(o);t.arrays[s]={};for(let h=0;h<l.length;h++)t.arrays[s][String(h+1)]=l[h];return l.length}async function be(e,t,n){if(e.length<2)return 0;let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=await se(e[2],n),o=ae(s,t);try{let l=new RegExp(i),h=o.replace(l,ce(a)),N=h!==o?1:0;return oe(s,h,t),N}catch{return 0}}async function Oe(e,t,n){if(e.length<2)return 0;let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=await se(e[2],n),o=ae(s,t);try{let l=new RegExp(i,"g"),h=o.match(l),N=h?h.length:0,v=o.replace(l,ce(a));return oe(s,v,t),N}catch{return 0}}function ce(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let a=e[i+1];a==="&"?(n+="&",i+=2):a==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function Pe(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=m(await n.evalExpr(e[0])),a=await G(e[1],n);try{let o=new RegExp(a).exec(i);if(o)return t.RSTART=o.index+1,t.RLENGTH=o[0].length,t.RSTART}catch{}return t.RSTART=0,t.RLENGTH=-1,0}async function Me(e,t,n){if(e.length<3)return"";let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=m(await n.evalExpr(e[2])),o=e.length>=4?m(await n.evalExpr(e[3])):t.line;try{let l=s.toLowerCase()==="g",h=l?0:parseInt(s,10)||1;if(l){let N=new RegExp(i,"g");return o.replace(N,(v,...R)=>ie(a,v,R.slice(0,-2)))}else{let N=0,v=new RegExp(i,"g");return o.replace(v,(R,...I)=>(N++,N===h?ie(a,R,I.slice(0,-2)):R))}}catch{return o}}function ie(e,t,n){let i="",a=0;for(;a<e.length;)if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];if(s==="&")i+="&",a+=2;else if(s==="0")i+=t,a+=2;else if(s>="1"&&s<="9"){let o=parseInt(s,10)-1;i+=n[o]||"",a+=2}else s==="n"?(i+=`
|
|
3
|
+
`,a+=2):s==="t"?(i+=" ",a+=2):(i+=s,a+=2)}else e[a]==="&"?(i+=t,a++):(i+=e[a],a++);return i}async function Te(e,t,n){return e.length===0?"":m(await n.evalExpr(e[0])).toLowerCase()}async function Fe(e,t,n){return e.length===0?"":m(await n.evalExpr(e[0])).toUpperCase()}async function _e(e,t,n){if(e.length===0)return"";let i=m(await n.evalExpr(e[0])),a=[];for(let s=1;s<e.length;s++)a.push(await n.evalExpr(e[s]));return D(i,a)}async function Ge(e,t,n){return e.length===0?0:Math.floor(k(await n.evalExpr(e[0])))}async function De(e,t,n){return e.length===0?0:Math.sqrt(k(await n.evalExpr(e[0])))}async function xe(e,t,n){return e.length===0?0:Math.sin(k(await n.evalExpr(e[0])))}async function Ue(e,t,n){return e.length===0?0:Math.cos(k(await n.evalExpr(e[0])))}async function Be(e,t,n){let i=e.length>0?k(await n.evalExpr(e[0])):0,a=e.length>1?k(await n.evalExpr(e[1])):0;return Math.atan2(i,a)}async function He(e,t,n){return e.length===0?0:Math.log(k(await n.evalExpr(e[0])))}async function $e(e,t,n){return e.length===0?1:Math.exp(k(await n.evalExpr(e[0])))}function We(e,t,n){return t.random?t.random():Math.random()}async function Ve(e,t,n){let i=e.length>0?k(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function Xe(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function Q(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}function D(e,t){let n=0,i="",a=0;for(;a<e.length;)if(e[a]==="%"&&a+1<e.length){let s=a+1,o="",l="",h="",N,v=s;for(;s<e.length&&/\d/.test(e[s]);)s++;s>v&&e[s]==="$"?(N=parseInt(e.substring(v,s),10)-1,s++):s=v;let R=()=>{if(s<e.length){if(s+1<e.length&&(e[s]==="h"&&e[s+1]==="h"||e[s]==="l"&&e[s+1]==="l")){s+=2;return}/[lzjh]/.test(e[s])&&s++}};for(;s<e.length&&/[-+ #0]/.test(e[s]);)o+=e[s++];if(e[s]==="*"){let c=t[n++],p=c!==void 0?Math.floor(Number(c)):0;p<0?(o+="-",l=String(-p)):l=String(p),s++}else for(;s<e.length&&/\d/.test(e[s]);)l+=e[s++];if(e[s]===".")if(s++,e[s]==="*"){let c=t[n++];h=String(c!==void 0?Math.floor(Number(c)):0),s++}else for(;s<e.length&&/\d/.test(e[s]);)h+=e[s++];R();let I=e[s],w=t[N!==void 0?N:n];switch(I){case"s":{let c=w!==void 0?String(w):"";if(h&&(c=c.substring(0,parseInt(h,10))),l){let p=parseInt(l,10);o.includes("-")?c=c.padEnd(p):c=c.padStart(p)}i+=c,N===void 0&&n++;break}case"d":case"i":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=c<0,E=Math.abs(c).toString();if(h){let L=parseInt(h,10);E=E.padStart(L,"0")}let d="";p?d="-":o.includes("+")?d="+":o.includes(" ")&&(d=" ");let y=d+E;if(l){let L=parseInt(l,10);o.includes("-")?y=y.padEnd(L):o.includes("0")&&!h?y=d+E.padStart(L-d.length,"0"):y=y.padStart(L)}i+=y,N===void 0&&n++;break}case"f":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toFixed(p);if(l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"e":case"E":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toExponential(p);if(I==="E"&&(E=E.toUpperCase()),l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"g":case"G":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c!==0?Math.floor(Math.log10(Math.abs(c))):0,d;if(c===0?d="0":E<-4||E>=p?(d=c.toExponential(p-1),I==="G"&&(d=d.toUpperCase())):d=c.toPrecision(p),d.includes(".")&&(d=d.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),d.includes("e")&&(d=d.replace(/\.?0+e/,"e")),l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"x":case"X":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(16);if(I==="X"&&(p=p.toUpperCase()),h){let y=parseInt(h,10);p=p.padStart(y,"0")}let E=c<0?"-":"",d=E+p;if(l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):o.includes("0")&&!h?d=E+p.padStart(y-E.length,"0"):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"o":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(8);if(h){let y=parseInt(h,10);p=p.padStart(y,"0")}let E=c<0?"-":"",d=E+p;if(l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):o.includes("0")&&!h?d=E+p.padStart(y-E.length,"0"):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"c":{typeof w=="number"?i+=String.fromCharCode(w):i+=String(w??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(a,s+1)}a=s+1}else if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];switch(s){case"n":i+=`
|
|
4
|
+
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=s}a+=2}else i+=e[a++];return i}var le={length:ge,substr:ke,index:Ce,split:Le,sub:be,gsub:Oe,match:Pe,gensub:Me,tolower:Te,toupper:Fe,sprintf:_e,int:Ge,sqrt:De,sin:xe,cos:Ue,atan2:Be,log:He,exp:$e,rand:We,srand:Ve,system:Xe("system","shell execution not allowed in sandboxed environment"),close:()=>0,fflush:()=>0,systime:Q("systime"),mktime:Q("mktime"),strftime:Q("strftime")};function g(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function A(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function S(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function j(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function T(e,t){try{return new RegExp(e).test(t)}catch{return!1}}function ue(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):t.split(e.fieldSep)}function x(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function q(e,t,n){if(t===0)e.line=S(n),e.fields=ue(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=S(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function O(e,t){e.line=t,e.fields=ue(e,t),e.NF=e.fields.length}function he(e,t){if(e.FS=t,t===" ")e.fieldSep=/\s+/;else try{e.fieldSep=new RegExp(t)}catch{e.fieldSep=new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function U(e,t){switch(t){case"FS":return e.FS;case"OFS":return e.OFS;case"ORS":return e.ORS;case"OFMT":return e.OFMT;case"NR":return e.NR;case"NF":return e.NF;case"FNR":return e.FNR;case"FILENAME":return e.FILENAME;case"RSTART":return e.RSTART;case"RLENGTH":return e.RLENGTH;case"SUBSEP":return e.SUBSEP;case"ARGC":return e.ARGC}return e.vars[t]??""}function P(e,t,n){switch(t){case"FS":he(e,S(n));return;case"OFS":e.OFS=S(n);return;case"ORS":e.ORS=S(n);return;case"OFMT":e.OFMT=S(n);return;case"NR":e.NR=Math.floor(A(n));return;case"NF":{let i=Math.floor(A(n));if(i<e.NF)e.fields=e.fields.slice(0,i),e.line=e.fields.join(e.OFS);else if(i>e.NF){for(;e.fields.length<i;)e.fields.push("");e.line=e.fields.join(e.OFS)}e.NF=i;return}case"FNR":e.FNR=Math.floor(A(n));return;case"FILENAME":e.FILENAME=S(n);return;case"RSTART":e.RSTART=Math.floor(A(n));return;case"RLENGTH":e.RLENGTH=Math.floor(A(n));return;case"SUBSEP":e.SUBSEP=S(n);return}e.vars[t]=n}function F(e,t){let n=t,i=new Set,a=e.arrayAliases.get(n);for(;a!==void 0&&!i.has(n);)i.add(n),n=a,a=e.arrayAliases.get(n);return n}function B(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=F(e,t);return e.arrays[i]?.[n]??""}function z(e,t,n,i){let a=F(e,t);e.arrays[a]||(e.arrays[a]={}),e.arrays[a][n]=i}function pe(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=F(e,t);return e.arrays[i]?.[n]!==void 0}function fe(e,t,n){let i=F(e,t);e.arrays[i]&&delete e.arrays[i][n]}function de(e,t){let n=F(e,t);delete e.arrays[n]}var J=null;function Ee(e){J=e}async function f(e,t){switch(t.type){case"number":return t.value;case"string":return t.value;case"regex":return T(t.pattern,e.line)?1:0;case"field":return Ke(e,t);case"variable":return U(e,t.name);case"array_access":return Qe(e,t);case"binary":return je(e,t);case"unary":return Je(e,t);case"ternary":return g(await f(e,t.condition))?await f(e,t.consequent):await f(e,t.alternate);case"call":return Ze(e,t.name,t.args);case"assignment":return et(e,t);case"pre_increment":return tt(e,t.operand);case"pre_decrement":return nt(e,t.operand);case"post_increment":return rt(e,t.operand);case"post_decrement":return it(e,t.operand);case"in":return st(e,t.key,t.array);case"getline":return at(e,t.variable,t.file,t.command);case"tuple":return lt(e,t.elements);default:return""}}async function Ke(e,t){let n=Math.floor(A(await f(e,t.index)));return x(e,n)}async function Qe(e,t){let n=S(await f(e,t.key));return B(e,t.array,n)}async function je(e,t){let n=t.operator;if(n==="||")return g(await f(e,t.left))||g(await f(e,t.right))?1:0;if(n==="&&")return g(await f(e,t.left))&&g(await f(e,t.right))?1:0;if(n==="~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return new RegExp(h).test(S(l))?1:0}catch{return 0}}if(n==="!~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return new RegExp(h).test(S(l))?0:1}catch{return 1}}let i=await f(e,t.left),a=await f(e,t.right);if(n===" ")return S(i)+S(a);if(qe(n))return ze(i,a,n);let s=A(i),o=A(a);return re(s,o,n)}function qe(e){return["<","<=",">",">=","==","!="].includes(e)}function ze(e,t,n){let i=j(e),a=j(t);if(i&&a){let l=A(e),h=A(t);switch(n){case"<":return l<h?1:0;case"<=":return l<=h?1:0;case">":return l>h?1:0;case">=":return l>=h?1:0;case"==":return l===h?1:0;case"!=":return l!==h?1:0}}let s=S(e),o=S(t);switch(n){case"<":return s<o?1:0;case"<=":return s<=o?1:0;case">":return s>o?1:0;case">=":return s>=o?1:0;case"==":return s===o?1:0;case"!=":return s!==o?1:0}return 0}async function Je(e,t){let n=await f(e,t.operand);switch(t.operator){case"!":return g(n)?0:1;case"-":return-A(n);case"+":return+A(n);default:return n}}async function Ze(e,t,n){let i=le[t];if(i)return i(n,e,{evalExpr:s=>f(e,s)});let a=e.functions.get(t);return a?Ye(e,a,n):""}async function Ye(e,t,n){if(e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new C(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i={};for(let o of t.params)i[o]=e.vars[o];let a=[];for(let o=0;o<t.params.length;o++){let l=t.params[o];if(o<n.length){let h=n[o];h.type==="variable"&&(e.arrayAliases.set(l,h.name),a.push(l));let N=await f(e,h);e.vars[l]=N}else e.vars[l]=""}e.hasReturn=!1,e.returnValue=void 0,J&&await J(e,t.body.statements);let s=e.returnValue??"";for(let o of t.params)i[o]!==void 0?e.vars[o]=i[o]:delete e.vars[o];for(let o of a)e.arrayAliases.delete(o);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,s}async function et(e,t){let n=await f(e,t.value),i=t.target,a=t.operator,s;if(a==="=")s=n;else{let o;if(i.type==="field"){let N=Math.floor(A(await f(e,i.index)));o=x(e,N)}else if(i.type==="variable")o=U(e,i.name);else{let N=S(await f(e,i.key));o=B(e,i.array,N)}let l=A(o),h=A(n);switch(a){case"+=":s=l+h;break;case"-=":s=l-h;break;case"*=":s=l*h;break;case"/=":s=h!==0?l/h:0;break;case"%=":s=h!==0?l%h:0;break;case"^=":s=l**h;break;default:s=n}}if(i.type==="field"){let o=Math.floor(A(await f(e,i.index)));q(e,o,s)}else if(i.type==="variable")P(e,i.name,s);else{let o=S(await f(e,i.key));z(e,i.array,o,s)}return s}async function H(e,t,n,i){let a;if(t.type==="field"){let s=Math.floor(A(await f(e,t.index)));a=A(x(e,s)),q(e,s,a+n)}else if(t.type==="variable")a=A(U(e,t.name)),P(e,t.name,a+n);else{let s=S(await f(e,t.key));a=A(B(e,t.array,s)),z(e,t.array,s,a+n)}return i?a+n:a}async function tt(e,t){return H(e,t,1,!0)}async function nt(e,t){return H(e,t,-1,!0)}async function rt(e,t){return H(e,t,1,!1)}async function it(e,t){return H(e,t,-1,!1)}async function st(e,t,n){let i;if(t.type==="tuple"){let a=[];for(let s of t.elements)a.push(S(await f(e,s)));i=a.join(e.SUBSEP)}else i=S(await f(e,t));return pe(e,n,i)?1:0}async function at(e,t,n,i){if(i)return ot(e,t,i);if(n)return ct(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let a=e.lineIndex+1;if(a>=e.lines.length)return 0;let s=e.lines[a];return t?P(e,t,s):O(e,s),e.NR++,e.lineIndex=a,1}async function ot(e,t,n){if(!e.exec)return-1;let i=S(await f(e,n)),a=`__cmd_${i}`,s=`__cmdi_${i}`,o,l;if(e.vars[a]===void 0)try{o=(await e.exec(i)).stdout.split(`
|
|
5
|
+
`),o.length>0&&o[o.length-1]===""&&o.pop(),e.vars[a]=JSON.stringify(o),e.vars[s]=-1,l=-1}catch{return-1}else o=JSON.parse(e.vars[a]),l=e.vars[s];let h=l+1;if(h>=o.length)return 0;let N=o[h];return e.vars[s]=h,t?P(e,t,N):O(e,N),1}async function ct(e,t,n){if(!e.fs||!e.cwd)return-1;let i=S(await f(e,n));if(i==="/dev/null")return 0;let a=e.fs.resolvePath(e.cwd,i),s=`__fc_${a}`,o=`__fi_${a}`,l,h;if(e.vars[s]===void 0)try{l=(await e.fs.readFile(a)).split(`
|
|
6
|
+
`),l.length>0&&l[l.length-1]===""&&l.pop(),e.vars[s]=JSON.stringify(l),e.vars[o]=-1,h=-1}catch{return-1}else l=JSON.parse(e.vars[s]),h=e.vars[o];let N=h+1;if(N>=l.length)return 0;let v=l[N];return e.vars[o]=N,t?P(e,t,v):O(e,v),1}async function lt(e,t){if(t.length===0)return"";for(let n=0;n<t.length-1;n++)await f(e,t[n]);return f(e,t[t.length-1])}Ee(M);async function M(e,t){for(let n of t)if(await b(e,n),ut(e))break}function ut(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function b(e,t){switch(t.type){case"block":await M(e,t.statements);break;case"expr_stmt":await f(e,t.expression);break;case"print":await ht(e,t.args,t.output);break;case"printf":await pt(e,t.format,t.args,t.output);break;case"if":await ft(e,t);break;case"while":await dt(e,t);break;case"do_while":await Et(e,t);break;case"for":await Nt(e,t);break;case"for_in":await St(e,t);break;case"break":e.loopBreak=!0;break;case"continue":e.loopContinue=!0;break;case"next":e.shouldNext=!0;break;case"nextfile":e.shouldNextFile=!0;break;case"exit":e.shouldExit=!0,e.exitCode=t.code?Math.floor(A(await f(e,t.code))):0;break;case"return":e.hasReturn=!0,e.returnValue=t.value?await f(e,t.value):"";break;case"delete":await yt(e,t.target);break}}async function ht(e,t,n){let i=[];for(let s of t){let o=await f(e,s);typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(D(e.OFMT,[o])):i.push(S(o))}let a=i.join(e.OFS)+e.ORS;n?await Ne(e,n.redirect,n.file,a):e.output+=a}async function pt(e,t,n,i){let a=S(await f(e,t)),s=[];for(let l of n)s.push(await f(e,l));let o=D(a,s);i?await Ne(e,i.redirect,i.file,o):e.output+=o}async function Ne(e,t,n,i){if(!e.fs||!e.cwd){e.output+=i;return}let a=S(await f(e,n)),s=e.fs.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(s)?await e.fs.appendFile(s,i):(await e.fs.writeFile(s,i),e.openedFiles.add(s)):(e.openedFiles.has(s)||e.openedFiles.add(s),await e.fs.appendFile(s,i))}async function ft(e,t){g(await f(e,t.condition))?await b(e,t.consequent):t.alternate&&await b(e,t.alternate)}async function dt(e,t){let n=0;for(;g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new C(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Et(e,t){let n=0;do{if(n++,n>e.maxIterations)throw new C(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(g(await f(e,t.condition)))}async function Nt(e,t){t.init&&await f(e,t.init);let n=0;for(;!t.condition||g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new C(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;t.update&&await f(e,t.update)}}async function St(e,t){let n=e.arrays[t.array];if(n)for(let i of Object.keys(n)){if(e.vars[t.variable]=i,e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function yt(e,t){if(t.type==="array_access"){let n=S(await f(e,t.key));fe(e,t.array,n)}else t.type==="variable"&&de(e,t.name)}var _=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}execute(t){this.program=t,this.ctx.output="";for(let n of t.functions)this.ctx.functions.set(n.name,n);this.rangeStates=t.rules.map(()=>!1)}async executeBegin(){if(this.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await M(this.ctx,t.action.statements),this.ctx.shouldExit))break}}async executeLine(t){if(!(!this.program||this.ctx.shouldExit)){O(this.ctx,t),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let i=this.program.rules[n];i.pattern?.type==="begin"||i.pattern?.type==="end"||await this.matchesRule(i,n)&&await M(this.ctx,i.action.statements)}}}async executeEnd(){if(this.program&&!this.ctx.inEndBlock){this.ctx.inEndBlock=!0,this.ctx.shouldExit=!1;for(let t of this.program.rules)if(t.pattern?.type==="end"&&(await M(this.ctx,t.action.statements),this.ctx.shouldExit))break;this.ctx.inEndBlock=!1}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(t,n){let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return T(i.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,i.expression));case"range":{let a=await this.matchPattern(i.start),s=await this.matchPattern(i.end);return this.rangeStates[n]?(s&&(this.rangeStates[n]=!1),!0):a?(this.rangeStates[n]=!0,s&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(t.type){case"regex_pattern":return T(t.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,t.expression));default:return!1}}};var r;(function(e){e.NUMBER="NUMBER",e.STRING="STRING",e.REGEX="REGEX",e.IDENT="IDENT",e.BEGIN="BEGIN",e.END="END",e.IF="IF",e.ELSE="ELSE",e.WHILE="WHILE",e.DO="DO",e.FOR="FOR",e.IN="IN",e.BREAK="BREAK",e.CONTINUE="CONTINUE",e.NEXT="NEXT",e.NEXTFILE="NEXTFILE",e.EXIT="EXIT",e.RETURN="RETURN",e.DELETE="DELETE",e.FUNCTION="FUNCTION",e.PRINT="PRINT",e.PRINTF="PRINTF",e.GETLINE="GETLINE",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.CARET="CARET",e.EQ="EQ",e.NE="NE",e.LT="LT",e.GT="GT",e.LE="LE",e.GE="GE",e.MATCH="MATCH",e.NOT_MATCH="NOT_MATCH",e.AND="AND",e.OR="OR",e.NOT="NOT",e.ASSIGN="ASSIGN",e.PLUS_ASSIGN="PLUS_ASSIGN",e.MINUS_ASSIGN="MINUS_ASSIGN",e.STAR_ASSIGN="STAR_ASSIGN",e.SLASH_ASSIGN="SLASH_ASSIGN",e.PERCENT_ASSIGN="PERCENT_ASSIGN",e.CARET_ASSIGN="CARET_ASSIGN",e.INCREMENT="INCREMENT",e.DECREMENT="DECREMENT",e.QUESTION="QUESTION",e.COLON="COLON",e.COMMA="COMMA",e.SEMICOLON="SEMICOLON",e.NEWLINE="NEWLINE",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.DOLLAR="DOLLAR",e.APPEND="APPEND",e.PIPE="PIPE",e.EOF="EOF"})(r||(r={}));var Rt={BEGIN:r.BEGIN,END:r.END,if:r.IF,else:r.ELSE,while:r.WHILE,do:r.DO,for:r.FOR,in:r.IN,break:r.BREAK,continue:r.CONTINUE,next:r.NEXT,nextfile:r.NEXTFILE,exit:r.EXIT,return:r.RETURN,delete:r.DELETE,function:r.FUNCTION,print:r.PRINT,printf:r.PRINTF,getline:r.GETLINE};function At(e){return e.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var $=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(t){this.input=t}tokenize(){let t=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&(t.push(n),this.lastTokenType=n.type)}return t.push(this.makeToken(r.EOF,"")),t}makeToken(t,n){return{type:t,value:n,line:this.line,column:this.column}}peek(t=0){return this.input[this.pos+t]||""}advance(){let t=this.input[this.pos++]||"";return t===`
|
|
7
|
+
`?(this.line++,this.column=1):this.column++,t}skipWhitespace(){for(;this.pos<this.input.length;){let t=this.peek();if(t===" "||t===" "||t==="\r")this.advance();else if(t==="\\")if(this.peek(1)===`
|
|
8
|
+
`)this.advance(),this.advance();else break;else if(t==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
9
|
+
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let t=this.line,n=this.column,i=this.peek();return i===`
|
|
10
|
+
`?(this.advance(),{type:r.NEWLINE,value:`
|
|
11
|
+
`,line:t,column:n}):i==='"'?this.readString():i==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(i)||i==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(i)||i==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,r.NEWLINE,r.SEMICOLON,r.LBRACE,r.RBRACE,r.LPAREN,r.LBRACKET,r.COMMA,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.AND,r.OR,r.NOT,r.MATCH,r.NOT_MATCH,r.QUESTION,r.COLON,r.LT,r.GT,r.LE,r.GE,r.EQ,r.NE,r.PLUS,r.MINUS,r.STAR,r.PERCENT,r.CARET,r.PRINT,r.PRINTF,r.IF,r.WHILE,r.DO,r.FOR,r.RETURN]).has(this.lastTokenType)}readString(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let a=this.advance();switch(a){case"n":i+=`
|
|
12
|
+
`;break;case"t":i+=" ";break;case"r":i+="\r";break;case"f":i+="\f";break;case"b":i+="\b";break;case"v":i+="\v";break;case"a":i+="\x07";break;case"\\":i+="\\";break;case'"':i+='"';break;case"/":i+="/";break;case"x":{let s="";for(;s.length<2&&/[0-9a-fA-F]/.test(this.peek());)s+=this.advance();s.length>0?i+=String.fromCharCode(parseInt(s,16)):i+="x";break}default:if(/[0-7]/.test(a)){let s=a;for(;s.length<3&&/[0-7]/.test(this.peek());)s+=this.advance();i+=String.fromCharCode(parseInt(s,8))}else i+=a}}else i+=this.advance();return this.peek()==='"'&&this.advance(),{type:r.STRING,value:i,line:t,column:n}}readRegex(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&(i+=this.advance());else{if(this.peek()===`
|
|
13
|
+
`)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=At(i),{type:r.REGEX,value:i,line:t,column:n}}readNumber(){let t=this.line,n=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(i+=this.advance();this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(i+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(i+=this.advance());this.isDigit(this.peek());)i+=this.advance();return{type:r.NUMBER,value:parseFloat(i),line:t,column:n}}readIdentifier(){let t=this.line,n=this.column,i="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)i+=this.advance();let a=Rt[i];return a?{type:a,value:i,line:t,column:n}:{type:r.IDENT,value:i,line:t,column:n}}readOperator(){let t=this.line,n=this.column,i=this.advance(),a=this.peek();switch(i){case"+":return a==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):a==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return a==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):a==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return a==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):a==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return a==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return a==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return a==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return a==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return a==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):a==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return a==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return a==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):a===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return a==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return a==="|"?(this.advance(),{type:r.OR,value:"||",line:t,column:n}):{type:r.PIPE,value:"|",line:t,column:n};case"~":return{type:r.MATCH,value:"~",line:t,column:n};case"?":return{type:r.QUESTION,value:"?",line:t,column:n};case":":return{type:r.COLON,value:":",line:t,column:n};case",":return{type:r.COMMA,value:",",line:t,column:n};case";":return{type:r.SEMICOLON,value:";",line:t,column:n};case"(":return{type:r.LPAREN,value:"(",line:t,column:n};case")":return{type:r.RPAREN,value:")",line:t,column:n};case"{":return{type:r.LBRACE,value:"{",line:t,column:n};case"}":return{type:r.RBRACE,value:"}",line:t,column:n};case"[":return{type:r.LBRACKET,value:"[",line:t,column:n};case"]":return{type:r.RBRACKET,value:"]",line:t,column:n};case"$":return{type:r.DOLLAR,value:"$",line:t,column:n};default:return{type:r.IDENT,value:i,line:t,column:n}}}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isAlphaNumeric(t){return this.isDigit(t)||this.isAlpha(t)}};var u={LPAREN:"LPAREN",RPAREN:"RPAREN",QUESTION:"QUESTION",NEWLINE:"NEWLINE",SEMICOLON:"SEMICOLON",RBRACE:"RBRACE",COMMA:"COMMA",PIPE:"PIPE",GT:"GT",APPEND:"APPEND",AND:"AND",OR:"OR",ASSIGN:"ASSIGN",PLUS_ASSIGN:"PLUS_ASSIGN",MINUS_ASSIGN:"MINUS_ASSIGN",STAR_ASSIGN:"STAR_ASSIGN",SLASH_ASSIGN:"SLASH_ASSIGN",PERCENT_ASSIGN:"PERCENT_ASSIGN",CARET_ASSIGN:"CARET_ASSIGN",RBRACKET:"RBRACKET",COLON:"COLON",IN:"IN",PRINT:"PRINT",PRINTF:"PRINTF",IDENT:"IDENT",LT:"LT",LE:"LE",GE:"GE",EQ:"EQ",NE:"NE",MATCH:"MATCH",NOT_MATCH:"NOT_MATCH",NUMBER:"NUMBER",STRING:"STRING",DOLLAR:"DOLLAR",NOT:"NOT",MINUS:"MINUS",PLUS:"PLUS",INCREMENT:"INCREMENT",DECREMENT:"DECREMENT"};function Ie(e){e.expect(u.PRINT);let t=[];if(e.check(u.NEWLINE)||e.check(u.SEMICOLON)||e.check(u.RBRACE)||e.check(u.PIPE)||e.check(u.GT)||e.check(u.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(W(e));e.check(u.COMMA);)e.advance(),t.push(W(e));let n;return e.check(u.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function W(e){return It(e)?Z(e,!0):Z(e,!1)}function Z(e,t){let n=t?e.parseTernary():wt(e);if(e.match(u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN)){let i=e.advance(),a=Z(e,t);if(n.type!=="variable"&&n.type!=="field"&&n.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[i.value],target:n,value:a}}return n}function It(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===u.LPAREN&&t++,i.type===u.RPAREN&&t--,i.type===u.QUESTION&&t===0)return!0;if(i.type===u.NEWLINE||i.type===u.SEMICOLON||i.type===u.RBRACE||i.type===u.COMMA||i.type===u.PIPE)return!1;n++}return!1}function wt(e){let t=Se(e);for(;e.check(u.OR);){e.advance();let n=Se(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function Se(e){let t=ye(e);for(;e.check(u.AND);){e.advance();let n=ye(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function ye(e){let t=mt(e);if(e.check(u.IN)){e.advance();let n=String(e.expect(u.IDENT).value);return{type:"in",key:t,array:n}}return t}function mt(e){let t=Re(e);for(;vt(e)&&!gt(e);){let n=Re(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Re(e){let t=Ae(e);for(;e.match(u.MATCH,u.NOT_MATCH);){let n=e.advance().type===u.MATCH?"~":"!~",i=Ae(e);t={type:"binary",operator:n,left:t,right:i}}return t}function Ae(e){let t=e.parseAddSub();for(;e.match(u.LT,u.LE,u.GE,u.EQ,u.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}function vt(e){return e.match(u.NUMBER,u.STRING,u.IDENT,u.DOLLAR,u.LPAREN,u.NOT,u.MINUS,u.PLUS,u.INCREMENT,u.DECREMENT)}function gt(e){return e.match(u.AND,u.OR,u.QUESTION,u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN,u.COMMA,u.SEMICOLON,u.NEWLINE,u.RBRACE,u.RPAREN,u.RBRACKET,u.COLON,u.PIPE,u.APPEND,u.GT,u.IN)}function we(e){e.expect(u.PRINTF);let t=e.check(u.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():W(e),i=[];for(;e.check(u.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():W(e));t&&(e.skipNewlines(),e.expect(u.RPAREN));let a;return e.check(u.GT)?(e.advance(),a={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),a={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:a}}var V=class{tokens=[];pos=0;parse(t){let n=new $(t);return this.tokens=n.tokenize(),this.pos=0,this.parseProgram()}setPos(t){this.pos=t}current(){return this.tokens[this.pos]||{type:r.EOF,value:"",line:0,column:0}}advance(){let t=this.current();return this.pos<this.tokens.length&&this.pos++,t}match(...t){return t.includes(this.current().type)}check(t){return this.current().type===t}expect(t,n){if(!this.check(t)){let i=this.current();throw new Error(n||`Expected ${t}, got ${i.type} at line ${i.line}:${i.column}`)}return this.advance()}skipNewlines(){for(;this.check(r.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(r.NEWLINE)||this.check(r.SEMICOLON);)this.advance()}parseProgram(){let t=[],n=[];for(this.skipNewlines();!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)this.check(r.FUNCTION)?t.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:t,rules:n}}parseFunction(){this.expect(r.FUNCTION);let t=this.expect(r.IDENT).value;this.expect(r.LPAREN);let n=[];if(!this.check(r.RPAREN))for(n.push(this.expect(r.IDENT).value);this.check(r.COMMA);)this.advance(),n.push(this.expect(r.IDENT).value);this.expect(r.RPAREN),this.skipNewlines();let i=this.parseBlock();return{name:t,params:n,body:i}}parseRule(){let t;if(this.check(r.BEGIN))this.advance(),t={type:"begin"};else if(this.check(r.END))this.advance(),t={type:"end"};else if(this.check(r.LBRACE))t=void 0;else if(this.check(r.REGEX)){let i=this.advance();if(this.check(r.AND)||this.check(r.OR)){let a={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(a)}}else{let a={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}}else{let a={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}this.skipNewlines();let n;return this.check(r.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:t,action:n}}parseBlock(){this.expect(r.LBRACE),this.skipNewlines();let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);)t.push(this.parseStatement()),this.skipTerminators();return this.expect(r.RBRACE),{type:"block",statements:t}}parseStatement(){if(this.check(r.SEMICOLON)||this.check(r.NEWLINE))return this.advance(),{type:"block",statements:[]};if(this.check(r.LBRACE))return this.parseBlock();if(this.check(r.IF))return this.parseIf();if(this.check(r.WHILE))return this.parseWhile();if(this.check(r.DO))return this.parseDoWhile();if(this.check(r.FOR))return this.parseFor();if(this.check(r.BREAK))return this.advance(),{type:"break"};if(this.check(r.CONTINUE))return this.advance(),{type:"continue"};if(this.check(r.NEXT))return this.advance(),{type:"next"};if(this.check(r.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(r.EXIT)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(r.RETURN)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(r.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}return this.check(r.PRINT)?Ie(this):this.check(r.PRINTF)?we(this):{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(r.IF),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();this.skipTerminators();let i;return this.check(r.ELSE)&&(this.advance(),this.skipNewlines(),i=this.parseStatement()),{type:"if",condition:t,consequent:n,alternate:i}}parseWhile(){this.expect(r.WHILE),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:t,body:n}}parseDoWhile(){this.expect(r.DO),this.skipNewlines();let t=this.parseStatement();this.skipNewlines(),this.expect(r.WHILE),this.expect(r.LPAREN);let n=this.parseExpression();return this.expect(r.RPAREN),{type:"do_while",body:t,condition:n}}parseFor(){if(this.expect(r.FOR),this.expect(r.LPAREN),this.check(r.IDENT)){let s=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let l=this.parseStatement();return{type:"for_in",variable:s.value,array:o,body:l}}this.pos--}let t;this.check(r.SEMICOLON)||(t=this.parseExpression()),this.expect(r.SEMICOLON);let n;this.check(r.SEMICOLON)||(n=this.parseExpression()),this.expect(r.SEMICOLON);let i;this.check(r.RPAREN)||(i=this.parseExpression()),this.expect(r.RPAREN),this.skipNewlines();let a=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:a}}parseExpression(){return this.parseAssignment()}parseAssignment(){let t=this.parseTernary();if(this.match(r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN)){let n=this.advance(),i=this.parseAssignment();if(t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],target:t,value:i}}return t}parseTernary(){let t=this.parsePipeGetline();if(this.check(r.QUESTION)){this.advance();let n=this.parseExpression();this.expect(r.COLON);let i=this.parseExpression();t={type:"ternary",condition:t,consequent:n,alternate:i}}return t}parsePipeGetline(){let t=this.parseOr();if(this.check(r.PIPE)){if(this.advance(),!this.check(r.GETLINE))throw new Error("Expected 'getline' after '|' in expression context");this.advance();let n;return this.check(r.IDENT)&&(n=this.advance().value),{type:"getline",command:t,variable:n}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalOrRest(t){for(t=this.parseLogicalAndRest(t);this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalAndRest(t){for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseAnd(){let t=this.parseIn();for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseIn(){let t=this.parseConcatenation();if(this.check(r.IN)){this.advance();let n=this.expect(r.IDENT).value;return{type:"in",key:t,array:n}}return t}parseConcatenation(){let t=this.parseMatch();for(;this.canStartExpression()&&!this.isConcatTerminator();){let n=this.parseMatch();t={type:"binary",operator:" ",left:t,right:n}}return t}parseMatch(){let t=this.parseComparison();for(;this.match(r.MATCH,r.NOT_MATCH);){let n=this.advance().type===r.MATCH?"~":"!~",i=this.parseComparison();t={type:"binary",operator:n,left:t,right:i}}return t}parseComparison(){let t=this.parseAddSub();for(;this.match(r.LT,r.LE,r.GT,r.GE,r.EQ,r.NE);){let n=this.advance(),i=this.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}canStartExpression(){return this.match(r.NUMBER,r.STRING,r.IDENT,r.DOLLAR,r.LPAREN,r.NOT,r.MINUS,r.PLUS,r.INCREMENT,r.DECREMENT)}isConcatTerminator(){return this.match(r.AND,r.OR,r.QUESTION,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.COMMA,r.SEMICOLON,r.NEWLINE,r.RBRACE,r.RPAREN,r.RBRACKET,r.COLON,r.PIPE,r.APPEND,r.IN)}parseAddSub(){let t=this.parseMulDiv();for(;this.match(r.PLUS,r.MINUS);){let n=this.advance().value,i=this.parseMulDiv();t={type:"binary",operator:n,left:t,right:i}}return t}parseMulDiv(){let t=this.parseUnary();for(;this.match(r.STAR,r.SLASH,r.PERCENT);){let n=this.advance(),i=this.parseUnary();t={type:"binary",operator:{"*":"*","/":"/","%":"%"}[n.value],left:t,right:i}}return t}parseUnary(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseUnary();return{type:"unary",operator:t,operand:n}}return this.parsePower()}parsePower(){let t=this.parsePostfix();if(this.check(r.CARET)){this.advance();let n=this.parsePower();t={type:"binary",operator:"^",left:t,right:n}}return t}parsePostfix(){let t=this.parsePrimary();if(this.check(r.INCREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:t}}if(this.check(r.DECREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:t}}return t}parseFieldIndex(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseFieldIndex();return{type:"unary",operator:t,operand:n}}return this.parseFieldIndexPower()}parseFieldIndexPower(){let t=this.parseFieldIndexPrimary();if(this.check(r.CARET)){this.advance();let n=this.parseFieldIndexPower();t={type:"binary",operator:"^",left:t,right:n}}return t}parseFieldIndexPrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();return this.expect(r.RPAREN),t}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=this.parseExpression();if(this.check(r.COMMA)){let i=[n];for(;this.check(r.COMMA);)this.advance(),i.push(this.parseExpression());this.expect(r.RBRACKET);let a=i.reduce((s,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:s,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:a}}return this.expect(r.RBRACKET),{type:"array_access",array:t,key:n}}return{type:"variable",name:t}}throw new Error(`Unexpected token in field index: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}parsePrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();if(this.check(r.COMMA)){let n=[t];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"tuple",elements:n}}return this.expect(r.RPAREN),t}if(this.check(r.GETLINE)){this.advance();let t,n;return this.check(r.IDENT)&&(t=this.advance().value),this.check(r.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:t,file:n}}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(this.skipNewlines(),!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseExpression());return this.skipNewlines(),this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(r.RBRACKET);let i;if(n.length===1)i=n[0];else{i=n[0];for(let a=1;a<n.length;a++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[a]}}return{type:"array_access",array:t,key:i}}return{type:"variable",name:t}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}};var kt={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},fn={name:"awk",async execute(e,t){if(ne(e))return te(kt);let n=/\s+/,i=" ",a={},s=0;for(let c=0;c<e.length;c++){let p=e[c];if(p==="-F"&&c+1<e.length)i=Y(e[++c]),n=me(i),s=c+1;else if(p.startsWith("-F"))i=Y(p.slice(2)),n=me(i),s=c+1;else if(p==="-v"&&c+1<e.length){let E=e[++c],d=E.indexOf("=");if(d>0){let y=E.slice(0,d),L=Y(E.slice(d+1));a[y]=L}s=c+1}else{if(p.startsWith("--"))return X("awk",p);if(p.startsWith("-")&&p.length>1){let E=p[1];if(E!=="F"&&E!=="v")return X("awk",`-${E}`);s=c+1}else if(!p.startsWith("-")){s=c;break}}}if(s>=e.length)return{stdout:"",stderr:`awk: missing program
|
|
14
|
+
`,exitCode:1};let o=e[s],l=e.slice(s+1),h=new V,N;try{N=h.parse(o)}catch(c){return{stdout:"",stderr:`awk: ${c instanceof Error?c.message:String(c)}
|
|
15
|
+
`,exitCode:1}}let v={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(c,p)=>{try{let E=await t.fs.readFile(c);await t.fs.writeFile(c,E+p)}catch{await t.fs.writeFile(c,p)}},resolvePath:t.fs.resolvePath.bind(t.fs)},R=K({fieldSep:n,maxIterations:t.limits?.maxAwkIterations,fs:v,cwd:t.cwd,exec:t.exec?c=>t.exec(c,{cwd:t.cwd}):void 0});R.FS=i,R.vars={...a},R.ARGC=l.length+1,R.ARGV={0:"awk"};for(let c=0;c<l.length;c++)R.ARGV[String(c+1)]=l[c];R.ENVIRON={...t.env};let I=new _(R);I.execute(N);let ee=N.rules.some(c=>c.pattern?.type!=="begin"&&c.pattern?.type!=="end"),w=N.rules.some(c=>c.pattern?.type==="end");try{if(await I.executeBegin(),R.shouldExit)return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};if(!ee&&!w)return{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};let c=[];if(l.length>0)for(let p of l)try{let E=t.fs.resolvePath(t.cwd,p),y=(await t.fs.readFile(E)).split(`
|
|
16
|
+
`);y.length>0&&y[y.length-1]===""&&y.pop(),c.push({filename:p,lines:y})}catch{return{stdout:"",stderr:`awk: ${p}: No such file or directory
|
|
17
|
+
`,exitCode:1}}else{let p=t.stdin.split(`
|
|
18
|
+
`);p.length>0&&p[p.length-1]===""&&p.pop(),c.push({filename:"",lines:p})}for(let p of c){for(R.FILENAME=p.filename,R.FNR=0,R.lines=p.lines,R.lineIndex=-1,R.shouldNextFile=!1;R.lineIndex<p.lines.length-1&&(R.lineIndex++,await I.executeLine(p.lines[R.lineIndex]),!(R.shouldExit||R.shouldNextFile)););if(R.shouldExit)break}return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()}}catch(c){let p=c instanceof Error?c.message:String(c),E=c instanceof C?C.EXIT_CODE:2;return{stdout:I.getOutput(),stderr:`awk: ${p}
|
|
19
|
+
`,exitCode:E}}}};function Y(e){return e.replace(/\\t/g," ").replace(/\\n/g,`
|
|
20
|
+
`).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function me(e){if(e===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(e))try{return new RegExp(e)}catch{return new RegExp(ve(e))}return new RegExp(ve(e))}function ve(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}export{fn as awkCommand2};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as h,b as d}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var l={name:"bash",summary:"execute shell commands or scripts",usage:"bash [OPTIONS] [SCRIPT_FILE] [ARGUMENTS...]",options:["-c COMMAND execute COMMAND string"," --help display this help and exit"],notes:["Without -c, reads and executes commands from SCRIPT_FILE.","Arguments are passed as $1, $2, etc. to the script.",'$0 is set to the script name (or "bash" with -c).']},f={name:"bash",async execute(e,t){if(d(e))return h(l);if(e[0]==="-c"&&e.length>=2){let r=e[1],s=e[2]||"bash",c=e.slice(3);return i(r,s,c,t)}if(e.length===0)return t.stdin?.trim()?i(t.stdin,"bash",[],t):{stdout:"",stderr:"",exitCode:0};let n=e[0],o=e.slice(1);try{let r=t.fs.resolvePath(t.cwd,n),s=await t.fs.readFile(r);return i(s,n,o,t)}catch{return{stdout:"",stderr:`bash: ${n}: No such file or directory
|
|
2
|
+
`,exitCode:127}}}},p={name:"sh",async execute(e,t){if(d(e))return h({...l,name:"sh",summary:"execute shell commands or scripts (POSIX shell)"});if(e[0]==="-c"&&e.length>=2){let r=e[1],s=e[2]||"sh",c=e.slice(3);return i(r,s,c,t)}if(e.length===0)return t.stdin?.trim()?i(t.stdin,"sh",[],t):{stdout:"",stderr:"",exitCode:0};let n=e[0],o=e.slice(1);try{let r=t.fs.resolvePath(t.cwd,n),s=await t.fs.readFile(r);return i(s,n,o,t)}catch{return{stdout:"",stderr:`sh: ${n}: No such file or directory
|
|
3
|
+
`,exitCode:127}}}};async function i(e,t,n,o){if(!o.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
|
|
4
|
+
`,exitCode:1};let r={...o.exportedEnv||{},0:t,"#":String(n.length),"@":n.join(" "),"*":n.join(" ")};n.forEach((a,u)=>{r[String(u+1)]=a});let s=e;if(s.startsWith("#!")){let a=s.indexOf(`
|
|
5
|
+
`);a!==-1&&(s=s.slice(a+1))}return await o.exec(s,{env:r,cwd:o.cwd})}export{f as bashCommand,p as shCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{a as g,b as $}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var C={name:"chmod",summary:"change file mode bits",usage:"chmod [OPTIONS] MODE FILE...",options:["-R change files recursively","-v output a diagnostic for every file processed"," --help display this help and exit"]},R={name:"chmod",async execute(s,a){if($(s))return g(C);if(s.length<2)return{stdout:"",stderr:`chmod: missing operand
|
|
2
|
+
`,exitCode:1};let e=!1,c=!1,o=0;for(;o<s.length&&s[o].startsWith("-");){let t=s[o];if(t==="-R"||t==="--recursive")e=!0,o++;else if(t==="-v"||t==="--verbose")c=!0,o++;else if(t==="--"){o++;break}else{if(/^[+-]?[rwxugo]+/.test(t)||/^\d+$/.test(t))break;if(/^-[Rv]+$/.test(t)){t.includes("R")&&(e=!0),t.includes("v")&&(c=!0),o++;continue}return{stdout:"",stderr:`chmod: invalid option -- '${t.slice(1)}'
|
|
3
|
+
`,exitCode:1}}}if(s.length-o<2)return{stdout:"",stderr:`chmod: missing operand
|
|
4
|
+
`,exitCode:1};let n=s[o],d=s.slice(o+1),r=/^[0-7]+$/.test(n),i;if(r)i=parseInt(n,8);else try{p(n,420)}catch{return{stdout:"",stderr:`chmod: invalid mode: '${n}'
|
|
5
|
+
`,exitCode:1}}let f="",l="",u=!1;for(let t of d){let h=a.fs.resolvePath(a.cwd,t);try{let m;if(r&&i!==void 0)m=i;else{let w=await a.fs.stat(h);m=p(n,w.mode)}if(await a.fs.chmod(h,m),c&&(f+=`mode of '${t}' changed to ${m.toString(8).padStart(4,"0")}
|
|
6
|
+
`),e&&(await a.fs.stat(h)).isDirectory){let y=await v(a,h,r?i:void 0,r?void 0:n,c);f+=y}}catch{l+=`chmod: cannot access '${t}': No such file or directory
|
|
7
|
+
`,u=!0}}return{stdout:f,stderr:l,exitCode:u?1:0}}};async function v(s,a,e,c,o){let n="",d=await s.fs.readdir(a);for(let r of d){let i=a==="/"?`/${r}`:`${a}/${r}`,f;if(e!==void 0)f=e;else if(c!==void 0){let u=await s.fs.stat(i);f=p(c,u.mode)}else f=420;await s.fs.chmod(i,f),o&&(n+=`mode of '${i}' changed to ${f.toString(8).padStart(4,"0")}
|
|
8
|
+
`),(await s.fs.stat(i)).isDirectory&&(n+=await v(s,i,e,c,o))}return n}function p(s,a=420){if(/^[0-7]+$/.test(s))return parseInt(s,8);let e=a&4095,c=s.split(",");for(let o of c){let n=o.match(/^([ugoa]*)([+\-=])([rwxXst]*)$/);if(!n)throw new Error(`Invalid mode: ${s}`);let d=n[1]||"a",r=n[2],i=n[3];(d==="a"||d==="")&&(d="ugo");let f=0;i.includes("r")&&(f|=4),i.includes("w")&&(f|=2),(i.includes("x")||i.includes("X"))&&(f|=1);let l=0;i.includes("s")&&(d.includes("u")&&(l|=2048),d.includes("g")&&(l|=1024)),i.includes("t")&&(l|=512);for(let u of d){let t=0;u==="u"?t=6:u==="g"?t=3:u==="o"&&(t=0);let h=f<<t;r==="+"?e|=h:r==="-"?e&=~h:r==="="&&(e&=~(7<<t),e|=h)}r==="+"?e|=l:r==="-"?e&=~l:r==="="&&(i.includes("s")&&(d.includes("u")&&(e&=-2049,e|=l&2048),d.includes("g")&&(e&=-1025,e|=l&1024)),i.includes("t")&&(e&=-513,e|=l&512))}return e}export{R as chmodCommand};
|