just-bash 1.0.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/LICENSE +201 -0
- package/README.md +326 -0
- package/dist/Bash.d.ts +90 -0
- package/dist/ai/index.d.ts +56 -0
- package/dist/ast/types.d.ts +518 -0
- package/dist/bin/chunks/alias-74DFXE2E.js +7 -0
- package/dist/bin/chunks/awk-S63F6IYK.js +15 -0
- package/dist/bin/chunks/base64-NC7HTKLZ.js +5 -0
- package/dist/bin/chunks/basename-Y7JDBYHN.js +6 -0
- package/dist/bin/chunks/bash-TQGTNXAE.js +7 -0
- package/dist/bin/chunks/cat-YZXBF5YF.js +6 -0
- package/dist/bin/chunks/chmod-3G4LK462.js +9 -0
- package/dist/bin/chunks/chunk-26Q3PZQ6.js +2 -0
- package/dist/bin/chunks/chunk-4VDEBYW7.js +2 -0
- package/dist/bin/chunks/chunk-5KNEBKYN.js +2 -0
- package/dist/bin/chunks/chunk-GTNBSMZR.js +23 -0
- package/dist/bin/chunks/chunk-J7BCMQDI.js +16 -0
- package/dist/bin/chunks/chunk-J7MJV6WO.js +3 -0
- package/dist/bin/chunks/chunk-LV662IGP.js +6 -0
- package/dist/bin/chunks/chunk-TA7RUHGQ.js +4 -0
- package/dist/bin/chunks/clear-GTCFHSB2.js +2 -0
- package/dist/bin/chunks/cp-77UY7PGN.js +8 -0
- package/dist/bin/chunks/curl-NE7XEWMN.js +26 -0
- package/dist/bin/chunks/cut-UYV3FM7R.js +6 -0
- package/dist/bin/chunks/date-7NBRXV2Z.js +5 -0
- package/dist/bin/chunks/diff-TG2NXCX2.js +19 -0
- package/dist/bin/chunks/dirname-VLHP44TU.js +5 -0
- package/dist/bin/chunks/du-4FZ7WF2P.js +8 -0
- package/dist/bin/chunks/echo-DEUIS5JO.js +4 -0
- package/dist/bin/chunks/env-FVITWNHG.js +9 -0
- package/dist/bin/chunks/expr-HA2ZNL6S.js +5 -0
- package/dist/bin/chunks/find-4B67H4RP.js +11 -0
- package/dist/bin/chunks/grep-OVWU4WCZ.js +15 -0
- package/dist/bin/chunks/head-VGXR3WWL.js +2 -0
- package/dist/bin/chunks/help-5V3MPCYQ.js +16 -0
- package/dist/bin/chunks/history-PRQ4B6N2.js +3 -0
- package/dist/bin/chunks/html-to-markdown-L4UWMK4S.js +84 -0
- package/dist/bin/chunks/jq-EYSXBSCP.js +14 -0
- package/dist/bin/chunks/ln-DB7J2W5X.js +10 -0
- package/dist/bin/chunks/ls-C4MPAF3H.js +26 -0
- package/dist/bin/chunks/mkdir-LWULWDHP.js +7 -0
- package/dist/bin/chunks/mv-TDYCNSIQ.js +7 -0
- package/dist/bin/chunks/paste-R36J3G4K.js +8 -0
- package/dist/bin/chunks/printf-BOFQVMMK.js +15 -0
- package/dist/bin/chunks/pwd-X4MWD4JP.js +3 -0
- package/dist/bin/chunks/readlink-DPNOQY67.js +7 -0
- package/dist/bin/chunks/rm-W6CCBEMG.js +8 -0
- package/dist/bin/chunks/sed-7IS44XON.js +48 -0
- package/dist/bin/chunks/seq-DGJILX2Q.js +7 -0
- package/dist/bin/chunks/sleep-E4DIYGTT.js +10 -0
- package/dist/bin/chunks/sort-UJP353TM.js +15 -0
- package/dist/bin/chunks/stat-3PHITCPO.js +9 -0
- package/dist/bin/chunks/tail-YSVKBQ77.js +2 -0
- package/dist/bin/chunks/tee-UU2VS3OM.js +3 -0
- package/dist/bin/chunks/timeout-OZVAGW2H.js +12 -0
- package/dist/bin/chunks/touch-XCIAYF5I.js +4 -0
- package/dist/bin/chunks/tr-2EEKHHO6.js +20 -0
- package/dist/bin/chunks/tree-4247W67O.js +12 -0
- package/dist/bin/chunks/true-JCX733LK.js +2 -0
- package/dist/bin/chunks/uniq-W4HF6YSB.js +5 -0
- package/dist/bin/chunks/wc-CNJ3QDRA.js +6 -0
- package/dist/bin/chunks/which-HX2NMOP3.js +3 -0
- package/dist/bin/chunks/xargs-YNLVLPOF.js +4 -0
- package/dist/bin/just-bash.js +188 -0
- package/dist/bin/shell/chunks/alias-74DFXE2E.js +7 -0
- package/dist/bin/shell/chunks/awk-S63F6IYK.js +15 -0
- package/dist/bin/shell/chunks/base64-NC7HTKLZ.js +5 -0
- package/dist/bin/shell/chunks/basename-Y7JDBYHN.js +6 -0
- package/dist/bin/shell/chunks/bash-TQGTNXAE.js +7 -0
- package/dist/bin/shell/chunks/cat-YZXBF5YF.js +6 -0
- package/dist/bin/shell/chunks/chmod-3G4LK462.js +9 -0
- package/dist/bin/shell/chunks/chunk-26Q3PZQ6.js +2 -0
- package/dist/bin/shell/chunks/chunk-4VDEBYW7.js +2 -0
- package/dist/bin/shell/chunks/chunk-5KNEBKYN.js +2 -0
- package/dist/bin/shell/chunks/chunk-GTNBSMZR.js +23 -0
- package/dist/bin/shell/chunks/chunk-J7BCMQDI.js +16 -0
- package/dist/bin/shell/chunks/chunk-J7MJV6WO.js +3 -0
- package/dist/bin/shell/chunks/chunk-LV662IGP.js +6 -0
- package/dist/bin/shell/chunks/chunk-TA7RUHGQ.js +4 -0
- package/dist/bin/shell/chunks/clear-GTCFHSB2.js +2 -0
- package/dist/bin/shell/chunks/cp-77UY7PGN.js +8 -0
- package/dist/bin/shell/chunks/curl-NE7XEWMN.js +26 -0
- package/dist/bin/shell/chunks/cut-UYV3FM7R.js +6 -0
- package/dist/bin/shell/chunks/date-7NBRXV2Z.js +5 -0
- package/dist/bin/shell/chunks/diff-TG2NXCX2.js +19 -0
- package/dist/bin/shell/chunks/dirname-VLHP44TU.js +5 -0
- package/dist/bin/shell/chunks/du-4FZ7WF2P.js +8 -0
- package/dist/bin/shell/chunks/echo-DEUIS5JO.js +4 -0
- package/dist/bin/shell/chunks/env-FVITWNHG.js +9 -0
- package/dist/bin/shell/chunks/expr-HA2ZNL6S.js +5 -0
- package/dist/bin/shell/chunks/find-4B67H4RP.js +11 -0
- package/dist/bin/shell/chunks/grep-OVWU4WCZ.js +15 -0
- package/dist/bin/shell/chunks/head-VGXR3WWL.js +2 -0
- package/dist/bin/shell/chunks/help-5V3MPCYQ.js +16 -0
- package/dist/bin/shell/chunks/history-PRQ4B6N2.js +3 -0
- package/dist/bin/shell/chunks/html-to-markdown-L4UWMK4S.js +84 -0
- package/dist/bin/shell/chunks/jq-EYSXBSCP.js +14 -0
- package/dist/bin/shell/chunks/ln-DB7J2W5X.js +10 -0
- package/dist/bin/shell/chunks/ls-C4MPAF3H.js +26 -0
- package/dist/bin/shell/chunks/mkdir-LWULWDHP.js +7 -0
- package/dist/bin/shell/chunks/mv-TDYCNSIQ.js +7 -0
- package/dist/bin/shell/chunks/paste-R36J3G4K.js +8 -0
- package/dist/bin/shell/chunks/printf-BOFQVMMK.js +15 -0
- package/dist/bin/shell/chunks/pwd-X4MWD4JP.js +3 -0
- package/dist/bin/shell/chunks/readlink-DPNOQY67.js +7 -0
- package/dist/bin/shell/chunks/rm-W6CCBEMG.js +8 -0
- package/dist/bin/shell/chunks/sed-7IS44XON.js +48 -0
- package/dist/bin/shell/chunks/seq-DGJILX2Q.js +7 -0
- package/dist/bin/shell/chunks/sleep-E4DIYGTT.js +10 -0
- package/dist/bin/shell/chunks/sort-UJP353TM.js +15 -0
- package/dist/bin/shell/chunks/stat-3PHITCPO.js +9 -0
- package/dist/bin/shell/chunks/tail-YSVKBQ77.js +2 -0
- package/dist/bin/shell/chunks/tee-UU2VS3OM.js +3 -0
- package/dist/bin/shell/chunks/timeout-OZVAGW2H.js +12 -0
- package/dist/bin/shell/chunks/touch-XCIAYF5I.js +4 -0
- package/dist/bin/shell/chunks/tr-2EEKHHO6.js +20 -0
- package/dist/bin/shell/chunks/tree-4247W67O.js +12 -0
- package/dist/bin/shell/chunks/true-JCX733LK.js +2 -0
- package/dist/bin/shell/chunks/uniq-W4HF6YSB.js +5 -0
- package/dist/bin/shell/chunks/wc-CNJ3QDRA.js +6 -0
- package/dist/bin/shell/chunks/which-HX2NMOP3.js +3 -0
- package/dist/bin/shell/chunks/xargs-YNLVLPOF.js +4 -0
- package/dist/bin/shell/shell.js +172 -0
- package/dist/bundle/ai/index.js +541 -0
- package/dist/bundle/chunks/alias-7ZSTROM7.js +6 -0
- package/dist/bundle/chunks/awk-V4C3GTJI.js +14 -0
- package/dist/bundle/chunks/base64-WATI5PWI.js +4 -0
- package/dist/bundle/chunks/basename-SB5JXIY3.js +5 -0
- package/dist/bundle/chunks/bash-T4PXVRYX.js +6 -0
- package/dist/bundle/chunks/cat-5KESXK2M.js +5 -0
- package/dist/bundle/chunks/chmod-VLKWIL3N.js +8 -0
- package/dist/bundle/chunks/chunk-3YNHMZ5M.js +2 -0
- package/dist/bundle/chunks/chunk-44UOCSGV.js +1 -0
- package/dist/bundle/chunks/chunk-74CEPOFO.js +22 -0
- package/dist/bundle/chunks/chunk-JYYFSUWP.js +5 -0
- package/dist/bundle/chunks/chunk-UJMN5NLH.js +1 -0
- package/dist/bundle/chunks/chunk-W2EKKAIL.js +15 -0
- package/dist/bundle/chunks/chunk-ZVV5VXYZ.js +3 -0
- package/dist/bundle/chunks/clear-ZBD2DMXN.js +1 -0
- package/dist/bundle/chunks/cp-BLHAPLQZ.js +7 -0
- package/dist/bundle/chunks/curl-PA2MWGKN.js +25 -0
- package/dist/bundle/chunks/cut-7RHEYJ7Y.js +5 -0
- package/dist/bundle/chunks/date-YOOSNZVA.js +4 -0
- package/dist/bundle/chunks/diff-IVJFQANX.js +6 -0
- package/dist/bundle/chunks/dirname-Q5HDZLH2.js +4 -0
- package/dist/bundle/chunks/du-I5HYAKTQ.js +7 -0
- package/dist/bundle/chunks/echo-W2TA2N7Y.js +3 -0
- package/dist/bundle/chunks/env-OORA5GFS.js +8 -0
- package/dist/bundle/chunks/expr-A4LJAGVP.js +4 -0
- package/dist/bundle/chunks/find-K3NO35MZ.js +10 -0
- package/dist/bundle/chunks/grep-3D2INI4S.js +14 -0
- package/dist/bundle/chunks/head-7H5R4WKO.js +1 -0
- package/dist/bundle/chunks/help-SDCRRU2F.js +15 -0
- package/dist/bundle/chunks/history-7Z2STZ6Y.js +2 -0
- package/dist/bundle/chunks/html-to-markdown-XMBYO6FD.js +4 -0
- package/dist/bundle/chunks/jq-7R2XGLLH.js +13 -0
- package/dist/bundle/chunks/ln-UTUVIAFP.js +9 -0
- package/dist/bundle/chunks/ls-B7C35UDO.js +23 -0
- package/dist/bundle/chunks/mkdir-WYI2LJ6H.js +6 -0
- package/dist/bundle/chunks/mv-GN23UIZU.js +6 -0
- package/dist/bundle/chunks/paste-L4TYPVSP.js +7 -0
- package/dist/bundle/chunks/printf-3ZT5XOIZ.js +14 -0
- package/dist/bundle/chunks/pwd-ZVX5RTL4.js +2 -0
- package/dist/bundle/chunks/readlink-HHC33N5C.js +6 -0
- package/dist/bundle/chunks/rm-5X2XSQQ6.js +7 -0
- package/dist/bundle/chunks/sed-UZJSXYQZ.js +47 -0
- package/dist/bundle/chunks/seq-TFPZQZPJ.js +6 -0
- package/dist/bundle/chunks/sleep-QJBQD6VS.js +9 -0
- package/dist/bundle/chunks/sort-LHMQWYH2.js +14 -0
- package/dist/bundle/chunks/stat-TM5F5YO4.js +8 -0
- package/dist/bundle/chunks/tail-BLGGG2VX.js +1 -0
- package/dist/bundle/chunks/tee-VCNOG5VI.js +2 -0
- package/dist/bundle/chunks/timeout-THAT7IOO.js +11 -0
- package/dist/bundle/chunks/touch-Z5XRYFYY.js +3 -0
- package/dist/bundle/chunks/tr-UV4V27RJ.js +19 -0
- package/dist/bundle/chunks/tree-75UXQ4XJ.js +11 -0
- package/dist/bundle/chunks/true-OD7ZXH3O.js +1 -0
- package/dist/bundle/chunks/uniq-IIOQKNTS.js +4 -0
- package/dist/bundle/chunks/wc-OXLYBRUE.js +5 -0
- package/dist/bundle/chunks/which-ONWH3TNF.js +2 -0
- package/dist/bundle/chunks/xargs-E5JPQL24.js +3 -0
- package/dist/bundle/index.js +141 -0
- package/dist/commands/alias/alias.d.ts +3 -0
- package/dist/commands/awk/awk.d.ts +2 -0
- package/dist/commands/awk/executor.d.ts +3 -0
- package/dist/commands/awk/expressions.d.ts +3 -0
- package/dist/commands/awk/functions.d.ts +12 -0
- package/dist/commands/awk/parser.d.ts +3 -0
- package/dist/commands/awk/types.d.ts +44 -0
- package/dist/commands/base64/base64.d.ts +5 -0
- package/dist/commands/basename/basename.d.ts +2 -0
- package/dist/commands/bash/bash.d.ts +3 -0
- package/dist/commands/cat/cat.d.ts +2 -0
- package/dist/commands/chmod/chmod.d.ts +2 -0
- package/dist/commands/clear/clear.d.ts +2 -0
- package/dist/commands/cp/cp.d.ts +2 -0
- package/dist/commands/curl/curl.d.ts +8 -0
- package/dist/commands/curl/form.d.ts +21 -0
- package/dist/commands/curl/help.d.ts +9 -0
- package/dist/commands/curl/parse.d.ts +9 -0
- package/dist/commands/curl/types.d.ts +31 -0
- package/dist/commands/curl/utils.d.ts +20 -0
- package/dist/commands/cut/cut.d.ts +2 -0
- package/dist/commands/date/date.d.ts +5 -0
- package/dist/commands/diff/diff.d.ts +5 -0
- package/dist/commands/dirname/dirname.d.ts +2 -0
- package/dist/commands/du/du.d.ts +2 -0
- package/dist/commands/echo/echo.d.ts +2 -0
- package/dist/commands/env/env.d.ts +3 -0
- package/dist/commands/expr/expr.d.ts +7 -0
- package/dist/commands/find/find.d.ts +2 -0
- package/dist/commands/find/matcher.d.ts +3 -0
- package/dist/commands/find/parser.d.ts +2 -0
- package/dist/commands/find/types.d.ts +70 -0
- package/dist/commands/grep/grep.d.ts +4 -0
- package/dist/commands/head/head-tail-shared.d.ts +38 -0
- package/dist/commands/head/head.d.ts +2 -0
- package/dist/commands/help/help.d.ts +2 -0
- package/dist/commands/help.d.ts +16 -0
- package/dist/commands/history/history.d.ts +2 -0
- package/dist/commands/html-to-markdown/html-to-markdown.d.ts +7 -0
- package/dist/commands/jq/jq.d.ts +14 -0
- package/dist/commands/ln/ln.d.ts +2 -0
- package/dist/commands/ls/ls.d.ts +2 -0
- package/dist/commands/mkdir/mkdir.d.ts +2 -0
- package/dist/commands/mv/mv.d.ts +2 -0
- package/dist/commands/paste/paste.d.ts +2 -0
- package/dist/commands/printf/printf.d.ts +2 -0
- package/dist/commands/pwd/pwd.d.ts +2 -0
- package/dist/commands/readlink/readlink.d.ts +2 -0
- package/dist/commands/registry.d.ts +33 -0
- package/dist/commands/rm/rm.d.ts +2 -0
- package/dist/commands/sed/executor.d.ts +7 -0
- package/dist/commands/sed/parser.d.ts +5 -0
- package/dist/commands/sed/sed.d.ts +2 -0
- package/dist/commands/sed/types.d.ts +141 -0
- package/dist/commands/seq/seq.d.ts +14 -0
- package/dist/commands/sleep/sleep.d.ts +2 -0
- package/dist/commands/sort/comparator.d.ts +9 -0
- package/dist/commands/sort/parser.d.ts +11 -0
- package/dist/commands/sort/sort.d.ts +2 -0
- package/dist/commands/sort/types.d.ts +18 -0
- package/dist/commands/stat/stat.d.ts +2 -0
- package/dist/commands/tail/tail.d.ts +2 -0
- package/dist/commands/tee/tee.d.ts +2 -0
- package/dist/commands/timeout/timeout.d.ts +2 -0
- package/dist/commands/touch/touch.d.ts +2 -0
- package/dist/commands/tr/tr.d.ts +2 -0
- package/dist/commands/tree/tree.d.ts +2 -0
- package/dist/commands/true/true.d.ts +3 -0
- package/dist/commands/uniq/uniq.d.ts +2 -0
- package/dist/commands/wc/wc.d.ts +2 -0
- package/dist/commands/which/which.d.ts +2 -0
- package/dist/commands/xargs/xargs.d.ts +2 -0
- package/dist/fs-interface.d.ts +186 -0
- package/dist/fs.d.ts +39 -0
- package/dist/index.d.ts +12 -0
- package/dist/interpreter/arithmetic.d.ts +29 -0
- package/dist/interpreter/builtins/break.d.ts +6 -0
- package/dist/interpreter/builtins/cd.d.ts +6 -0
- package/dist/interpreter/builtins/continue.d.ts +6 -0
- package/dist/interpreter/builtins/declare.d.ts +29 -0
- package/dist/interpreter/builtins/eval.d.ts +9 -0
- package/dist/interpreter/builtins/exit.d.ts +5 -0
- package/dist/interpreter/builtins/export.d.ts +13 -0
- package/dist/interpreter/builtins/index.d.ts +36 -0
- package/dist/interpreter/builtins/let.d.ts +18 -0
- package/dist/interpreter/builtins/local.d.ts +6 -0
- package/dist/interpreter/builtins/read.d.ts +6 -0
- package/dist/interpreter/builtins/return.d.ts +6 -0
- package/dist/interpreter/builtins/set.d.ts +6 -0
- package/dist/interpreter/builtins/shift.d.ts +12 -0
- package/dist/interpreter/builtins/source.d.ts +6 -0
- package/dist/interpreter/builtins/unset.d.ts +12 -0
- package/dist/interpreter/builtins/variable-helpers.d.ts +30 -0
- package/dist/interpreter/conditionals.d.ts +17 -0
- package/dist/interpreter/control-flow.d.ts +21 -0
- package/dist/interpreter/errors.d.ts +107 -0
- package/dist/interpreter/expansion/analysis.d.ts +39 -0
- package/dist/interpreter/expansion/brace-range.d.ts +20 -0
- package/dist/interpreter/expansion/pattern.d.ts +22 -0
- package/dist/interpreter/expansion/variable.d.ts +27 -0
- package/dist/interpreter/expansion/word-split.d.ts +24 -0
- package/dist/interpreter/expansion.d.ts +27 -0
- package/dist/interpreter/functions.d.ts +12 -0
- package/dist/interpreter/helpers/array.d.ts +23 -0
- package/dist/interpreter/helpers/condition.d.ts +22 -0
- package/dist/interpreter/helpers/errors.d.ts +8 -0
- package/dist/interpreter/helpers/file-tests.d.ts +33 -0
- package/dist/interpreter/helpers/ifs.d.ts +43 -0
- package/dist/interpreter/helpers/loop.d.ts +24 -0
- package/dist/interpreter/helpers/numeric-compare.d.ts +13 -0
- package/dist/interpreter/helpers/readonly.d.ts +21 -0
- package/dist/interpreter/helpers/regex.d.ts +8 -0
- package/dist/interpreter/helpers/result.d.ts +54 -0
- package/dist/interpreter/helpers/statements.d.ts +20 -0
- package/dist/interpreter/helpers/string-compare.d.ts +22 -0
- package/dist/interpreter/helpers/string-tests.d.ts +13 -0
- package/dist/interpreter/helpers/variable-tests.d.ts +9 -0
- package/dist/interpreter/helpers/word-parts.d.ts +22 -0
- package/dist/interpreter/index.d.ts +3 -0
- package/dist/interpreter/interpreter.d.ts +61 -0
- package/dist/interpreter/redirections.d.ts +14 -0
- package/dist/interpreter/types.d.ts +68 -0
- package/dist/limits.d.ts +26 -0
- package/dist/network/allow-list/shared.d.ts +45 -0
- package/dist/network/allow-list.d.ts +51 -0
- package/dist/network/fetch.d.ts +25 -0
- package/dist/network/index.d.ts +7 -0
- package/dist/network/types.d.ts +85 -0
- package/dist/overlay-fs/OverlayFs.d.ts +87 -0
- package/dist/overlay-fs/index.d.ts +1 -0
- package/dist/parser/arithmetic-parser.d.ts +25 -0
- package/dist/parser/command-parser.d.ts +10 -0
- package/dist/parser/compound-parser.d.ts +14 -0
- package/dist/parser/conditional-parser.d.ts +8 -0
- package/dist/parser/expansion-parser.d.ts +10 -0
- package/dist/parser/lexer.d.ts +135 -0
- package/dist/parser/parser.d.ts +92 -0
- package/dist/parser/types.d.ts +23 -0
- package/dist/parser/word-parser.d.ts +33 -0
- package/dist/sandbox/Command.d.ts +28 -0
- package/dist/sandbox/Sandbox.d.ts +60 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/types.d.ts +80 -0
- package/dist/utils/args.d.ts +55 -0
- package/dist/utils/file-reader.d.ts +64 -0
- package/dist/utils/glob.d.ts +25 -0
- package/package.json +103 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as b,b as $,c as d}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var O={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input"," --help display this help and exit"]};function g(r,f,t,e=0){if(r===null||r===void 0)return"null";if(typeof r=="boolean"||typeof r=="number")return String(r);if(typeof r=="string")return t?r:JSON.stringify(r);if(Array.isArray(r))return r.length===0?"[]":f?`[${r.map(l=>g(l,!0,!1)).join(",")}]`:`[
|
|
3
|
+
${r.map(l=>" ".repeat(e+1)+g(l,!1,!1,e+1)).join(`,
|
|
4
|
+
`)}
|
|
5
|
+
${" ".repeat(e)}]`;if(typeof r=="object"){let s=Object.keys(r);return s.length===0?"{}":f?`{${s.map(i=>`${JSON.stringify(i)}:${g(r[i],!0,!1)}`).join(",")}}`:`{
|
|
6
|
+
${s.map(i=>{let n=g(r[i],!1,!1,e+1);return`${" ".repeat(e+1)}${JSON.stringify(i)}: ${n}`}).join(`,
|
|
7
|
+
`)}
|
|
8
|
+
${" ".repeat(e)}}`}return String(r)}function m(r,f){if(f===""||f===".")return[r];let t=f.startsWith(".")?f.slice(1):f;if(t==="")return[r];if(t.startsWith("[]")){let i=t.slice(2);return Array.isArray(r)?r.flatMap(n=>m(n,`.${i}`)):r&&typeof r=="object"?Object.values(r).flatMap(n=>m(n,`.${i}`)):[]}let e=t.match(/^\[(-?\d+)\](.*)/);if(e){let i=Number.parseInt(e[1],10),n=e[2];if(Array.isArray(r)){let h=i<0?r.length+i:i;if(h>=0&&h<r.length)return m(r[h],`.${n}`)}return[null]}let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(s){let i=s[1],n=s[2];if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r[i];if(n.startsWith("[]"))return n=n.slice(2),Array.isArray(o)?o.flatMap(c=>m(c,`.${n}`)):o&&typeof o=="object"?Object.values(o).flatMap(c=>m(c,`.${n}`)):[];if(n.startsWith(".")||n.startsWith("[")||n==="")return m(o,n||".")}return[null]}let l=t.match(/^\["([^"]+)"\](.*)/);if(l){let i=l[1],n=l[2];return r&&typeof r=="object"&&!Array.isArray(r)?m(r[i],`.${n}`):[null]}return[null]}function j(r,f){let t=f.trim();if(t.includes("|")){let e=t.split("|").map(l=>l.trim()),s=[r];for(let l of e)s=s.flatMap(i=>j(i,l));return s}return t==="keys"?Array.isArray(r)?[r.map((e,s)=>s)]:r&&typeof r=="object"?[Object.keys(r)]:[null]:t==="values"?Array.isArray(r)?[r]:r&&typeof r=="object"?[Object.values(r)]:[null]:t==="length"?typeof r=="string"?[r.length]:Array.isArray(r)?[r.length]:r&&typeof r=="object"?[Object.keys(r).length]:r===null?[0]:[null]:t==="type"?r===null?["null"]:Array.isArray(r)?["array"]:[typeof r]:t==="first"?Array.isArray(r)&&r.length>0?[r[0]]:[null]:t==="last"?Array.isArray(r)&&r.length>0?[r[r.length-1]]:[null]:t==="reverse"?Array.isArray(r)?[[...r].reverse()]:typeof r=="string"?[r.split("").reverse().join("")]:[null]:t==="sort"?Array.isArray(r)?[[...r].sort()]:[null]:t==="unique"?Array.isArray(r)?[[...new Set(r.map(e=>JSON.stringify(e)))].map(e=>JSON.parse(e))]:[null]:t==="flatten"?Array.isArray(r)?[r.flat()]:[null]:t==="add"?Array.isArray(r)?r.length===0?[null]:r.every(e=>typeof e=="number")?[r.reduce((e,s)=>e+s,0)]:r.every(e=>typeof e=="string")?[r.join("")]:r.every(e=>Array.isArray(e))?[r.flat()]:[null]:[null]:t==="min"?Array.isArray(r)&&r.length>0?[Math.min(...r)]:[null]:t==="max"?Array.isArray(r)&&r.length>0?[Math.max(...r)]:[null]:t==="empty"?[]:t==="not"?[!r]:m(r,t)}var x={name:"jq",async execute(r,f){if($(r))return b(O);let t=!1,e=!1,s=!1,l=!1,i=!1,n=".",h=!1,o=[];for(let a=0;a<r.length;a++){let u=r[a];if(u==="-r"||u==="--raw-output")t=!0;else if(u==="-c"||u==="--compact-output")e=!0;else if(u==="-e"||u==="--exit-status")s=!0;else if(u==="-s"||u==="--slurp")l=!0;else if(u==="-n"||u==="--null-input")i=!0;else if(u==="-")o.push("-");else{if(u.startsWith("--"))return d("jq",u);if(u.startsWith("-"))for(let p of u.slice(1))if(p==="r")t=!0;else if(p==="c")e=!0;else if(p==="e")s=!0;else if(p==="s")l=!0;else if(p==="n")i=!0;else return d("jq",`-${p}`);else h?o.push(u):(n=u,h=!0)}}let c;if(i)c="";else if(o.length===0||o.length===1&&o[0]==="-")c=f.stdin;else try{let a=f.fs.resolvePath(f.cwd,o[0]);c=await f.fs.readFile(a)}catch{return{stdout:"",stderr:`jq: ${o[0]}: No such file or directory
|
|
9
|
+
`,exitCode:2}}try{let a;if(i)a=j(null,n);else if(l){let y=[];for(let A of c.trim().split(`
|
|
10
|
+
`))A.trim()&&y.push(JSON.parse(A));a=j(y,n)}else{let y=c.trim();if(y.startsWith("{")||y.startsWith("["))a=j(JSON.parse(y),n);else{a=[];for(let A of y.split(`
|
|
11
|
+
`))A.trim()&&a.push(...j(JSON.parse(A),n))}}let u=a.map(y=>g(y,e,t)).join(`
|
|
12
|
+
`),p=s&&(a.length===0||a.every(y=>y==null||y===!1))?1:0;return{stdout:u?`${u}
|
|
13
|
+
`:"",stderr:"",exitCode:p}}catch(a){return{stdout:"",stderr:`jq: parse error: ${a.message}
|
|
14
|
+
`,exitCode:5}}}};export{x as jqCommand};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as m,b as h}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var y={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},p={name:"ln",async execute(i,s){if(h(i))return m(y);let r=!1,a=!1,d=!1,t=0;for(;t<i.length&&i[t].startsWith("-");){let e=i[t];if(e==="-s"||e==="--symbolic")r=!0,t++;else if(e==="-f"||e==="--force")a=!0,t++;else if(e==="-v"||e==="--verbose")d=!0,t++;else if(e==="-n"||e==="--no-dereference")t++;else if(/^-[sfvn]+$/.test(e))e.includes("s")&&(r=!0),e.includes("f")&&(a=!0),e.includes("v")&&(d=!0),t++;else if(e==="--"){t++;break}else return{stdout:"",stderr:`ln: invalid option -- '${e.slice(1)}'
|
|
3
|
+
`,exitCode:1}}let f=i.slice(t);if(f.length<2)return{stdout:"",stderr:`ln: missing file operand
|
|
4
|
+
`,exitCode:1};let n=f[0],l=f[1],o=s.fs.resolvePath(s.cwd,l);if(await s.fs.exists(o))if(a)try{await s.fs.rm(o,{force:!0})}catch{return{stdout:"",stderr:`ln: cannot remove '${l}': Permission denied
|
|
5
|
+
`,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${r?"symbolic ":""}link '${l}': File exists
|
|
6
|
+
`,exitCode:1};try{if(r)await s.fs.symlink(n,o);else{let e=s.fs.resolvePath(s.cwd,n);if(!await s.fs.exists(e))return{stdout:"",stderr:`ln: failed to access '${n}': No such file or directory
|
|
7
|
+
`,exitCode:1};await s.fs.link(e,o)}}catch(e){let u=e;return u.message.includes("EPERM")?{stdout:"",stderr:`ln: '${n}': hard link not allowed for directory
|
|
8
|
+
`,exitCode:1}:{stdout:"",stderr:`ln: ${u.message}
|
|
9
|
+
`,exitCode:1}}let c="";return d&&(c=`'${l}' -> '${n}'
|
|
10
|
+
`),{stdout:c,stderr:"",exitCode:0}}};export{p as lnCommand};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as I}from"./chunk-TA7RUHGQ.js";import{a as F,b as H}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var L=(n,t,e)=>{let s=n instanceof RegExp?_(n,e):n,r=t instanceof RegExp?_(t,e):t,i=s!==null&&r!=null&&ut(s,r,e);return i&&{start:i[0],end:i[1],pre:e.slice(0,i[0]),body:e.slice(i[0]+s.length,i[1]),post:e.slice(i[1]+r.length)}},_=(n,t)=>{let e=t.match(n);return e?e[0]:null},ut=(n,t,e)=>{let s,r,i,o,l,h=e.indexOf(n),f=e.indexOf(t,h+1),u=h;if(h>=0&&f>0){if(n===t)return[h,f];for(s=[],i=e.length;u>=0&&!l;){if(u===h)s.push(u),h=e.indexOf(n,u+1);else if(s.length===1){let d=s.pop();d!==void 0&&(l=[d,f])}else r=s.pop(),r!==void 0&&r<i&&(i=r,o=f),f=e.indexOf(t,u+1);u=h<f&&h>=0?h:f}s.length&&o!==void 0&&(l=[i,o])}return l};var J="\0SLASH"+Math.random()+"\0",U="\0OPEN"+Math.random()+"\0",G="\0CLOSE"+Math.random()+"\0",Z="\0COMMA"+Math.random()+"\0",K="\0PERIOD"+Math.random()+"\0",ft=new RegExp(J,"g"),pt=new RegExp(U,"g"),dt=new RegExp(G,"g"),gt=new RegExp(Z,"g"),mt=new RegExp(K,"g"),yt=/\\\\/g,wt=/\\{/g,St=/\\}/g,xt=/\\,/g,$t=/\\./g;function k(n){return isNaN(n)?n.charCodeAt(0):parseInt(n,10)}function bt(n){return n.replace(yt,J).replace(wt,U).replace(St,G).replace(xt,Z).replace($t,K)}function Et(n){return n.replace(ft,"\\").replace(pt,"{").replace(dt,"}").replace(gt,",").replace(mt,".")}function V(n){if(!n)return[""];let t=[],e=L("{","}",n);if(!e)return n.split(",");let{pre:s,body:r,post:i}=e,o=s.split(",");o[o.length-1]+="{"+r+"}";let l=V(i);return i.length&&(o[o.length-1]+=l.shift(),o.push.apply(o,l)),t.push.apply(t,o),t}function X(n){return n?(n.slice(0,2)==="{}"&&(n="\\{\\}"+n.slice(2)),P(bt(n),!0).map(Et)):[]}function At(n){return"{"+n+"}"}function vt(n){return/^-?0\d/.test(n)}function Mt(n,t){return n<=t}function Nt(n,t){return n>=t}function P(n,t){let e=[],s=L("{","}",n);if(!s)return[n];let r=s.pre,i=s.post.length?P(s.post,!1):[""];if(/\$$/.test(s.pre))for(let o=0;o<i.length;o++){let l=r+"{"+s.body+"}"+i[o];e.push(l)}else{let o=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),l=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),h=o||l,f=s.body.indexOf(",")>=0;if(!h&&!f)return s.post.match(/,(?!,).*\}/)?(n=s.pre+"{"+s.body+G+s.post,P(n)):[n];let u;if(h)u=s.body.split(/\.\./);else if(u=V(s.body),u.length===1&&u[0]!==void 0&&(u=P(u[0],!1).map(At),u.length===1))return i.map(a=>s.pre+u[0]+a);let d;if(h&&u[0]!==void 0&&u[1]!==void 0){let a=k(u[0]),c=k(u[1]),g=Math.max(u[0].length,u[1].length),p=u.length===3&&u[2]!==void 0?Math.abs(k(u[2])):1,m=Mt;c<a&&(p*=-1,m=Nt);let w=u.some(vt);d=[];for(let S=a;m(S,c);S+=p){let x;if(l)x=String.fromCharCode(S),x==="\\"&&(x="");else if(x=String(S),w){let b=g-x.length;if(b>0){let v=new Array(b+1).join("0");S<0?x="-"+v+x.slice(1):x=v+x}}d.push(x)}}else{d=[];for(let a=0;a<u.length;a++)d.push.apply(d,P(u[a],!1))}for(let a=0;a<d.length;a++)for(let c=0;c<i.length;c++){let g=r+d[a]+i[c];(!t||h||g)&&e.push(g)}}return e}var O=n=>{if(typeof n!="string")throw new TypeError("invalid pattern");if(n.length>65536)throw new TypeError("pattern is too long")};var Tt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},z=n=>n.replace(/[[\]\\-]/g,"\\$&"),Pt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Y=n=>n.join(""),Q=(n,t)=>{let e=t;if(n.charAt(e)!=="[")throw new Error("not in a brace expression");let s=[],r=[],i=e+1,o=!1,l=!1,h=!1,f=!1,u=e,d="";t:for(;i<n.length;){let p=n.charAt(i);if((p==="!"||p==="^")&&i===e+1){f=!0,i++;continue}if(p==="]"&&o&&!h){u=i+1;break}if(o=!0,p==="\\"&&!h){h=!0,i++;continue}if(p==="["&&!h){for(let[m,[y,w,S]]of Object.entries(Tt))if(n.startsWith(m,i)){if(d)return["$.",!1,n.length-e,!0];i+=m.length,S?r.push(y):s.push(y),l=l||w;continue t}}if(h=!1,d){p>d?s.push(z(d)+"-"+z(p)):p===d&&s.push(z(p)),d="",i++;continue}if(n.startsWith("-]",i+1)){s.push(z(p+"-")),i+=2;continue}if(n.startsWith("-",i+1)){d=p,i+=2;continue}s.push(z(p)),i++}if(u<i)return["",!1,0,!1];if(!s.length&&!r.length)return["$.",!1,n.length-e,!0];if(r.length===0&&s.length===1&&/^\\?.$/.test(s[0])&&!f){let p=s[0].length===2?s[0].slice(-1):s[0];return[Pt(p),!1,u-e,!1]}let a="["+(f?"^":"")+Y(s)+"]",c="["+(f?"":"^")+Y(r)+"]";return[s.length&&r.length?"("+a+"|"+c+")":s.length?a:c,l,u-e,!0]};var M=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!0}={})=>e?t?n.replace(/\[([^\/\\])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):t?n.replace(/\[([^\/\\{}])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1");var Ot=new Set(["!","?","+","*","@"]),tt=n=>Ot.has(n),zt="(?!(?:^|/)\\.\\.?(?:$|/))",C="(?!\\.)",Ct=new Set(["[","."]),Rt=new Set(["..","."]),Dt=new Set("().*{}+?[]^$\\!"),Wt=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),B="[^/]",et=B+"*?",st=B+"+?",N=class n{type;#s;#n;#r=!1;#t=[];#e;#o;#c;#a=!1;#i;#h;#u=!1;constructor(t,e,s={}){this.type=t,t&&(this.#n=!0),this.#e=e,this.#s=this.#e?this.#e.#s:this,this.#i=this.#s===this?s:this.#s.#i,this.#c=this.#s===this?[]:this.#s.#c,t==="!"&&!this.#s.#a&&this.#c.push(this),this.#o=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(let t of this.#t)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#h!==void 0?this.#h:this.type?this.#h=this.type+"("+this.#t.map(t=>String(t)).join("|")+")":this.#h=this.#t.map(t=>String(t)).join("")}#p(){if(this!==this.#s)throw new Error("should only call on root");if(this.#a)return this;this.toString(),this.#a=!0;let t;for(;t=this.#c.pop();){if(t.type!=="!")continue;let e=t,s=e.#e;for(;s;){for(let r=e.#o+1;!s.type&&r<s.#t.length;r++)for(let i of t.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(s.#t[r])}e=s,s=e.#e}}return this}push(...t){for(let e of t)if(e!==""){if(typeof e!="string"&&!(e instanceof n&&e.#e===this))throw new Error("invalid part: "+e);this.#t.push(e)}}toJSON(){let t=this.type===null?this.#t.slice().map(e=>typeof e=="string"?e:e.toJSON()):[this.type,...this.#t.map(e=>e.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#s||this.#s.#a&&this.#e?.type==="!")&&t.push({}),t}isStart(){if(this.#s===this)return!0;if(!this.#e?.isStart())return!1;if(this.#o===0)return!0;let t=this.#e;for(let e=0;e<this.#o;e++){let s=t.#t[e];if(!(s instanceof n&&s.type==="!"))return!1}return!0}isEnd(){if(this.#s===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();let t=this.#e?this.#e.#t.length:0;return this.#o===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let e=new n(this.type,t);for(let s of this.#t)e.copyIn(s);return e}static#l(t,e,s,r){let i=!1,o=!1,l=-1,h=!1;if(e.type===null){let c=s,g="";for(;c<t.length;){let p=t.charAt(c++);if(i||p==="\\"){i=!i,g+=p;continue}if(o){c===l+1?(p==="^"||p==="!")&&(h=!0):p==="]"&&!(c===l+2&&h)&&(o=!1),g+=p;continue}else if(p==="["){o=!0,l=c,h=!1,g+=p;continue}if(!r.noext&&tt(p)&&t.charAt(c)==="("){e.push(g),g="";let m=new n(p,e);c=n.#l(t,m,c,r),e.push(m);continue}g+=p}return e.push(g),c}let f=s+1,u=new n(null,e),d=[],a="";for(;f<t.length;){let c=t.charAt(f++);if(i||c==="\\"){i=!i,a+=c;continue}if(o){f===l+1?(c==="^"||c==="!")&&(h=!0):c==="]"&&!(f===l+2&&h)&&(o=!1),a+=c;continue}else if(c==="["){o=!0,l=f,h=!1,a+=c;continue}if(tt(c)&&t.charAt(f)==="("){u.push(a),a="";let g=new n(c,u);u.push(g),f=n.#l(t,g,f,r);continue}if(c==="|"){u.push(a),a="",d.push(u),u=new n(null,e);continue}if(c===")")return a===""&&e.#t.length===0&&(e.#u=!0),u.push(a),a="",e.push(...d,u),f;a+=c}return e.type=null,e.#n=void 0,e.#t=[t.substring(s-1)],f}static fromGlob(t,e={}){let s=new n(null,void 0,e);return n.#l(t,s,0,e),s}toMMPattern(){if(this!==this.#s)return this.#s.toMMPattern();let t=this.toString(),[e,s,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#i.nocase&&!this.#i.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return s;let l=(this.#i.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${e}$`,l),{_src:e,_glob:t})}get options(){return this.#i}toRegExpSource(t){let e=t??!!this.#i.dot;if(this.#s===this&&this.#p(),!this.type){let h=this.isStart()&&this.isEnd()&&!this.#t.some(c=>typeof c!="string"),f=this.#t.map(c=>{let[g,p,m,y]=typeof c=="string"?n.#d(c,this.#n,h):c.toRegExpSource(t);return this.#n=this.#n||m,this.#r=this.#r||y,g}).join(""),u="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&Rt.has(this.#t[0]))){let g=Ct,p=e&&g.has(f.charAt(0))||f.startsWith("\\.")&&g.has(f.charAt(2))||f.startsWith("\\.\\.")&&g.has(f.charAt(4)),m=!e&&!t&&g.has(f.charAt(0));u=p?zt:m?C:""}let d="";return this.isEnd()&&this.#s.#a&&this.#e?.type==="!"&&(d="(?:$|\\/)"),[u+f+d,M(f),this.#n=!!this.#n,this.#r]}let s=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:",i=this.#f(e);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){let h=this.toString();return this.#t=[h],this.type=null,this.#n=void 0,[h,M(this.toString()),!1,!1]}let o=!s||t||e||!C?"":this.#f(!0);o===i&&(o=""),o&&(i=`(?:${i})(?:${o})*?`);let l="";if(this.type==="!"&&this.#u)l=(this.isStart()&&!e?C:"")+st;else{let h=this.type==="!"?"))"+(this.isStart()&&!e&&!t?C:"")+et+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;l=r+i+h}return[l,M(i),this.#n=!!this.#n,this.#r]}#f(t){return this.#t.map(e=>{if(typeof e=="string")throw new Error("string type in extglob ast??");let[s,r,i,o]=e.toRegExpSource(t);return this.#r=this.#r||o,s}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join("|")}static#d(t,e,s=!1){let r=!1,i="",o=!1;for(let l=0;l<t.length;l++){let h=t.charAt(l);if(r){r=!1,i+=(Dt.has(h)?"\\":"")+h;continue}if(h==="\\"){l===t.length-1?i+="\\\\":r=!0;continue}if(h==="["){let[f,u,d,a]=Q(t,l);if(d){i+=f,o=o||u,l+=d-1,e=e||a;continue}}if(h==="*"){i+=s&&t==="*"?st:et,e=!0;continue}if(h==="?"){i+=B,e=!0;continue}i+=Wt(h)}return[i,M(t),!!e,o]}};var q=(n,{windowsPathsNoEscape:t=!1,magicalBraces:e=!1}={})=>e?t?n.replace(/[?*()[\]{}]/g,"[$&]"):n.replace(/[?*()[\]\\{}]/g,"\\$&"):t?n.replace(/[?*()[\]]/g,"[$&]"):n.replace(/[?*()[\]\\]/g,"\\$&");var $=(n,t,e={})=>(O(t),!e.nocomment&&t.charAt(0)==="#"?!1:new T(t,e).match(n)),jt=/^\*+([^+@!?\*\[\(]*)$/,Lt=n=>t=>!t.startsWith(".")&&t.endsWith(n),kt=n=>t=>t.endsWith(n),Gt=n=>(n=n.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(n)),Bt=n=>(n=n.toLowerCase(),t=>t.toLowerCase().endsWith(n)),qt=/^\*+\.\*+$/,Ft=n=>!n.startsWith(".")&&n.includes("."),Ht=n=>n!=="."&&n!==".."&&n.includes("."),It=/^\.\*+$/,_t=n=>n!=="."&&n!==".."&&n.startsWith("."),Jt=/^\*+$/,Ut=n=>n.length!==0&&!n.startsWith("."),Zt=n=>n.length!==0&&n!=="."&&n!=="..",Kt=/^\?+([^+@!?\*\[\(]*)?$/,Vt=([n,t=""])=>{let e=rt([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},Xt=([n,t=""])=>{let e=ot([n]);return t?(t=t.toLowerCase(),s=>e(s)&&s.toLowerCase().endsWith(t)):e},Yt=([n,t=""])=>{let e=ot([n]);return t?s=>e(s)&&s.endsWith(t):e},Qt=([n,t=""])=>{let e=rt([n]);return t?s=>e(s)&&s.endsWith(t):e},rt=([n])=>{let t=n.length;return e=>e.length===t&&!e.startsWith(".")},ot=([n])=>{let t=n.length;return e=>e.length===t&&e!=="."&&e!==".."},at=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",nt={win32:{sep:"\\"},posix:{sep:"/"}},te=at==="win32"?nt.win32.sep:nt.posix.sep;$.sep=te;var A=Symbol("globstar **");$.GLOBSTAR=A;var ee="[^/]",se=ee+"*?",ne="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",ie="(?:(?!(?:\\/|^)\\.).)*?",re=(n,t={})=>e=>$(e,n,t);$.filter=re;var E=(n,t={})=>Object.assign({},n,t),oe=n=>{if(!n||typeof n!="object"||!Object.keys(n).length)return $;let t=$;return Object.assign((s,r,i={})=>t(s,r,E(n,i)),{Minimatch:class extends t.Minimatch{constructor(r,i={}){super(r,E(n,i))}static defaults(r){return t.defaults(E(n,r)).Minimatch}},AST:class extends t.AST{constructor(r,i,o={}){super(r,i,E(n,o))}static fromGlob(r,i={}){return t.AST.fromGlob(r,E(n,i))}},unescape:(s,r={})=>t.unescape(s,E(n,r)),escape:(s,r={})=>t.escape(s,E(n,r)),filter:(s,r={})=>t.filter(s,E(n,r)),defaults:s=>t.defaults(E(n,s)),makeRe:(s,r={})=>t.makeRe(s,E(n,r)),braceExpand:(s,r={})=>t.braceExpand(s,E(n,r)),match:(s,r,i={})=>t.match(s,r,E(n,i)),sep:t.sep,GLOBSTAR:A})};$.defaults=oe;var ct=(n,t={})=>(O(n),t.nobrace||!/\{(?:(?!\{).)*\}/.test(n)?[n]:X(n));$.braceExpand=ct;var ae=(n,t={})=>new T(n,t).makeRe();$.makeRe=ae;var ce=(n,t,e={})=>{let s=new T(t,e);return n=n.filter(r=>s.match(r)),s.options.nonull&&!n.length&&n.push(t),n};$.match=ce;var it=/[?*]|[+@!]\(.*?\)|\[|\]/,he=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),T=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(t,e={}){O(t),e=e||{},this.options=e,this.pattern=t,this.platform=e.platform||at,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!e.windowsPathsNoEscape||e.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!e.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!e.nonegate,this.comment=!1,this.empty=!1,this.partial=!!e.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=e.windowsNoMagicRoot!==void 0?e.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let e of t)if(typeof e!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,e=this.options;if(!e.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],e.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);let s=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(s),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,o,l)=>{if(this.isWindows&&this.windowsNoMagicRoot){let h=i[0]===""&&i[1]===""&&(i[2]==="?"||!it.test(i[2]))&&!it.test(i[3]),f=/^[a-z]:/i.test(i[0]);if(h)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(f)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(h=>this.parse(h))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){let o=this.set[i];o[0]===""&&o[1]===""&&this.globParts[i][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let s=0;s<t.length;s++)for(let r=0;r<t[s].length;r++)t[s][r]==="**"&&(t[s][r]="*");let{optimizationLevel:e=1}=this.options;return e>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):e>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(e=>{let s=-1;for(;(s=e.indexOf("**",s+1))!==-1;){let r=s;for(;e[r+1]==="**";)r++;r!==s&&e.splice(s,r-s)}return e})}levelOneOptimize(t){return t.map(e=>(e=e.reduce((s,r)=>{let i=s[s.length-1];return r==="**"&&i==="**"?s:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(s.pop(),s):(s.push(r),s)},[]),e.length===0?[""]:e))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let e=!1;do{if(e=!1,!this.preserveMultipleSlashes){for(let r=1;r<t.length-1;r++){let i=t[r];r===1&&i===""&&t[0]===""||(i==="."||i==="")&&(e=!0,t.splice(r,1),r--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(e=!0,t.pop())}let s=0;for(;(s=t.indexOf("..",s+1))!==-1;){let r=t[s-1];r&&r!=="."&&r!==".."&&r!=="**"&&(e=!0,t.splice(s-1,2),s-=2)}}while(e);return t.length===0?[""]:t}firstPhasePreProcess(t){let e=!1;do{e=!1;for(let s of t){let r=-1;for(;(r=s.indexOf("**",r+1))!==-1;){let o=r;for(;s[o+1]==="**";)o++;o>r&&s.splice(r+1,o-r);let l=s[r+1],h=s[r+2],f=s[r+3];if(l!==".."||!h||h==="."||h===".."||!f||f==="."||f==="..")continue;e=!0,s.splice(r,1);let u=s.slice(0);u[r]="**",t.push(u),r--}if(!this.preserveMultipleSlashes){for(let o=1;o<s.length-1;o++){let l=s[o];o===1&&l===""&&s[0]===""||(l==="."||l==="")&&(e=!0,s.splice(o,1),o--)}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(e=!0,s.pop())}let i=0;for(;(i=s.indexOf("..",i+1))!==-1;){let o=s[i-1];if(o&&o!=="."&&o!==".."&&o!=="**"){e=!0;let h=i===1&&s[i+1]==="**"?["."]:[];s.splice(i-1,2,...h),s.length===0&&s.push(""),i-=2}}}}while(e);return t}secondPhasePreProcess(t){for(let e=0;e<t.length-1;e++)for(let s=e+1;s<t.length;s++){let r=this.partsMatch(t[e],t[s],!this.preserveMultipleSlashes);if(r){t[e]=[],t[s]=r;break}}return t.filter(e=>e.length)}partsMatch(t,e,s=!1){let r=0,i=0,o=[],l="";for(;r<t.length&&i<e.length;)if(t[r]===e[i])o.push(l==="b"?e[i]:t[r]),r++,i++;else if(s&&t[r]==="**"&&e[i]===t[r+1])o.push(t[r]),r++;else if(s&&e[i]==="**"&&t[r]===e[i+1])o.push(e[i]),i++;else if(t[r]==="*"&&e[i]&&(this.options.dot||!e[i].startsWith("."))&&e[i]!=="**"){if(l==="b")return!1;l="a",o.push(t[r]),r++,i++}else if(e[i]==="*"&&t[r]&&(this.options.dot||!t[r].startsWith("."))&&t[r]!=="**"){if(l==="a")return!1;l="b",o.push(e[i]),r++,i++}else return!1;return t.length===e.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,e=!1,s=0;for(let r=0;r<t.length&&t.charAt(r)==="!";r++)e=!e,s++;s&&(this.pattern=t.slice(s)),this.negate=e}matchOne(t,e,s=!1){let r=this.options;if(this.isWindows){let p=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),m=!p&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),y=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),w=!y&&e[0]===""&&e[1]===""&&e[2]==="?"&&typeof e[3]=="string"&&/^[a-z]:$/i.test(e[3]),S=m?3:p?0:void 0,x=w?3:y?0:void 0;if(typeof S=="number"&&typeof x=="number"){let[b,v]=[t[S],e[x]];b.toLowerCase()===v.toLowerCase()&&(e[x]=b,x>S?e=e.slice(x):S>x&&(t=t.slice(S)))}}let{optimizationLevel:i=1}=this.options;i>=2&&(t=this.levelTwoFileOptimize(t)),this.debug("matchOne",this,{file:t,pattern:e}),this.debug("matchOne",t.length,e.length);for(var o=0,l=0,h=t.length,f=e.length;o<h&&l<f;o++,l++){this.debug("matchOne loop");var u=e[l],d=t[o];if(this.debug(e,u,d),u===!1)return!1;if(u===A){this.debug("GLOBSTAR",[e,u,d]);var a=o,c=l+1;if(c===f){for(this.debug("** at the end");o<h;o++)if(t[o]==="."||t[o]===".."||!r.dot&&t[o].charAt(0)===".")return!1;return!0}for(;a<h;){var g=t[a];if(this.debug(`
|
|
3
|
+
globstar while`,t,a,e,c,g),this.matchOne(t.slice(a),e.slice(c),s))return this.debug("globstar found match!",a,h,g),!0;if(g==="."||g===".."||!r.dot&&g.charAt(0)==="."){this.debug("dot detected!",t,a,e,c);break}this.debug("globstar swallow a segment, and continue"),a++}return!!(s&&(this.debug(`
|
|
4
|
+
>>> no match, partial?`,t,a,e,c),a===h))}let p;if(typeof u=="string"?(p=d===u,this.debug("string match",u,d,p)):(p=u.test(d),this.debug("pattern match",u,d,p)),!p)return!1}if(o===h&&l===f)return!0;if(o===h)return s;if(l===f)return o===h-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return ct(this.pattern,this.options)}parse(t){O(t);let e=this.options;if(t==="**")return A;if(t==="")return"";let s,r=null;(s=t.match(Jt))?r=e.dot?Zt:Ut:(s=t.match(jt))?r=(e.nocase?e.dot?Bt:Gt:e.dot?kt:Lt)(s[1]):(s=t.match(Kt))?r=(e.nocase?e.dot?Xt:Vt:e.dot?Yt:Qt)(s):(s=t.match(qt))?r=e.dot?Ht:Ft:(s=t.match(It))&&(r=_t);let i=N.fromGlob(t,this.options).toMMPattern();return r&&typeof i=="object"&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let e=this.options,s=e.noglobstar?se:e.dot?ne:ie,r=new Set(e.nocase?["i"]:[]),i=t.map(h=>{let f=h.map(d=>{if(d instanceof RegExp)for(let a of d.flags.split(""))r.add(a);return typeof d=="string"?he(d):d===A?A:d._src});f.forEach((d,a)=>{let c=f[a+1],g=f[a-1];d!==A||g===A||(g===void 0?c!==void 0&&c!==A?f[a+1]="(?:\\/|"+s+"\\/)?"+c:f[a]=s:c===void 0?f[a-1]=g+"(?:\\/|\\/"+s+")?":c!==A&&(f[a-1]=g+"(?:\\/|\\/"+s+"\\/)"+c,f[a+1]=A))});let u=f.filter(d=>d!==A);if(this.partial&&u.length>=1){let d=[];for(let a=1;a<=u.length;a++)d.push(u.slice(0,a).join("/"));return"(?:"+d.join("|")+")"}return u.join("/")}).join("|"),[o,l]=t.length>1?["(?:",")"]:["",""];i="^"+o+i+l+"$",this.partial&&(i="^(?:\\/|"+o+i.slice(1,-1)+l+")$"),this.negate&&(i="^(?!"+i+").+$");try{this.regexp=new RegExp(i,[...r].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,e=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&e)return!0;let s=this.options;this.isWindows&&(t=t.split("\\").join("/"));let r=this.slashSplit(t);this.debug(this.pattern,"split",r);let i=this.set;this.debug(this.pattern,"set",i);let o=r[r.length-1];if(!o)for(let l=r.length-2;!o&&l>=0;l--)o=r[l];for(let l=0;l<i.length;l++){let h=i[l],f=r;if(s.matchBase&&h.length===1&&(f=[o]),this.matchOne(f,h,e))return s.flipNegate?!0:!this.negate}return s.flipNegate?!1:this.negate}static defaults(t){return $.defaults(t).Minimatch}};$.AST=N;$.Minimatch=T;$.escape=q;$.unescape=M;function R(n){if(n<1024)return String(n);if(n<1024*1024){let e=n/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(n<1024*1024*1024){let e=n/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=n/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function D(n){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()],s=String(n.getDate()).padStart(2," "),r=new Date,i=new Date(r.getTime()-4320*60*60*1e3);if(n>i){let l=String(n.getHours()).padStart(2,"0"),h=String(n.getMinutes()).padStart(2,"0");return`${e} ${s} ${l}:${h}`}let o=n.getFullYear();return`${e} ${s} ${o}`}var le={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},ue={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},Le={name:"ls",async execute(n,t){if(H(n))return F(le);let e=I("ls",n,ue);if(!e.ok)return e.error;let s=e.result.flags.showAll,r=e.result.flags.showAlmostAll,i=e.result.flags.longFormat,o=e.result.flags.humanReadable,l=e.result.flags.recursive,h=e.result.flags.reverse,f=e.result.flags.sortBySize,u=e.result.flags.directoryOnly,d=e.result.flags.sortByTime;e.result.flags.onePerLine;let a=e.result.positional;a.length===0&&a.push(".");let c="",g="",p=0;for(let m=0;m<a.length;m++){let y=a[m];if(m>0&&c&&!c.endsWith(`
|
|
5
|
+
|
|
6
|
+
`)&&(c+=`
|
|
7
|
+
`),u){let w=t.fs.resolvePath(t.cwd,y);try{let S=await t.fs.stat(w);if(i){let x=S.isDirectory?"drwxr-xr-x":"-rw-r--r--",b=S.isDirectory?"/":"",v=S.size??0,W=o?R(v).padStart(5):String(v).padStart(5),j=S.mtime??new Date(0),lt=D(j);c+=`${x} 1 user user ${W} ${lt} ${y}${b}
|
|
8
|
+
`}else c+=`${y}
|
|
9
|
+
`}catch{g+=`ls: cannot access '${y}': No such file or directory
|
|
10
|
+
`,p=2}continue}if(y.includes("*")||y.includes("?")||y.includes("[")){let w=await fe(y,t,s,r,i,h,o,f);c+=w.stdout,g+=w.stderr,w.exitCode!==0&&(p=w.exitCode)}else{let w=await ht(y,t,s,r,i,l,a.length>1,h,o,f);c+=w.stdout,g+=w.stderr,w.exitCode!==0&&(p=w.exitCode)}}return{stdout:c,stderr:g,exitCode:p}}};async function fe(n,t,e,s,r,i=!1,o=!1,l=!1){let h=e||s,f=t.fs.getAllPaths(),u=t.fs.resolvePath(t.cwd,"."),d=[];for(let a of f){let c=a.startsWith(u)&&a.slice(u.length+1)||a;if($(c,n)||$(a,n)){let g=c.split("/").pop()||c;if(!h&&g.startsWith("."))continue;d.push(c||a)}}if(d.length===0)return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
11
|
+
`,exitCode:2};if(l){let a=[];for(let c of d){let g=t.fs.resolvePath(t.cwd,c);try{let p=await t.fs.stat(g);a.push({path:c,size:p.size??0})}catch{a.push({path:c,size:0})}}a.sort((c,g)=>g.size-c.size),d.length=0,d.push(...a.map(c=>c.path))}else d.sort();if(i&&d.reverse(),r){let a=[];for(let c of d){let g=t.fs.resolvePath(t.cwd,c);try{let p=await t.fs.stat(g),m=p.isDirectory?"drwxr-xr-x":"-rw-r--r--",y=p.isDirectory?"/":"",w=p.size??0,S=o?R(w).padStart(5):String(w).padStart(5),x=p.mtime??new Date(0),b=D(x);a.push(`${m} 1 user user ${S} ${b} ${c}${y}`)}catch{a.push(`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${c}`)}}return{stdout:`${a.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`,stderr:"",exitCode:0}}return{stdout:`${d.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`,stderr:"",exitCode:0}}async function ht(n,t,e,s,r,i,o,l=!1,h=!1,f=!1,u=!1){let d=e||s,a=t.fs.resolvePath(t.cwd,n);try{let c=await t.fs.stat(a);if(!c.isDirectory){if(r){let m=c.size??0,y=h?R(m).padStart(5):String(m).padStart(5),w=c.mtime??new Date(0),S=D(w);return{stdout:`-rw-r--r-- 1 user user ${y} ${S} ${n}
|
|
16
|
+
`,stderr:"",exitCode:0}}return{stdout:`${n}
|
|
17
|
+
`,stderr:"",exitCode:0}}let g=await t.fs.readdir(a);if(d||(g=g.filter(m=>!m.startsWith("."))),f){let m=[];for(let y of g){let w=a==="/"?`/${y}`:`${a}/${y}`;try{let S=await t.fs.stat(w);m.push({name:y,size:S.size??0})}catch{m.push({name:y,size:0})}}m.sort((y,w)=>w.size-y.size),g=m.map(y=>y.name)}else g.sort();e&&(g=[".","..",...g]),l&&g.reverse();let p="";if((i||o)&&(p+=`${n}:
|
|
18
|
+
`),r){p+=`total ${g.length}
|
|
19
|
+
`;for(let m of g){if(m==="."||m===".."){p+=`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${m}
|
|
20
|
+
`;continue}let y=a==="/"?`/${m}`:`${a}/${m}`;try{let w=await t.fs.stat(y),S=w.isDirectory?"drwxr-xr-x":"-rw-r--r--",x=w.isDirectory?"/":"",b=w.size??0,v=h?R(b).padStart(5):String(b).padStart(5),W=w.mtime??new Date(0),j=D(W);p+=`${S} 1 user user ${v} ${j} ${m}${x}
|
|
21
|
+
`}catch{p+=`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${m}
|
|
22
|
+
`}}}else p+=g.join(`
|
|
23
|
+
`)+(g.length?`
|
|
24
|
+
`:"");if(i)for(let m of g){if(m==="."||m==="..")continue;let y=a==="/"?`/${m}`:`${a}/${m}`;try{if((await t.fs.stat(y)).isDirectory){p+=`
|
|
25
|
+
`;let S=n==="."?`./${m}`:`${n}/${m}`,x=await ht(S,t,e,s,r,i,!1,l,h,f,!0);p+=x.stdout}}catch{}}return{stdout:p,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`ls: ${n}: No such file or directory
|
|
26
|
+
`,exitCode:2}}}export{Le as lsCommand};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a}from"./chunk-TA7RUHGQ.js";import{a as l}from"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var g={recursive:{short:"p",long:"parents",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},y={name:"mkdir",async execute(u,o){let e=a("mkdir",u,g);if(!e.ok)return e.error;let m=e.result.flags.recursive,f=e.result.flags.verbose,n=e.result.positional;if(n.length===0)return{stdout:"",stderr:`mkdir: missing operand
|
|
3
|
+
`,exitCode:1};let c="",t="",d=0;for(let r of n)try{let i=o.fs.resolvePath(o.cwd,r);await o.fs.mkdir(i,{recursive:m}),f&&(c+=`mkdir: created directory '${r}'
|
|
4
|
+
`)}catch(i){let s=l(i);s.includes("ENOENT")||s.includes("no such file")?t+=`mkdir: cannot create directory '${r}': No such file or directory
|
|
5
|
+
`:s.includes("EEXIST")||s.includes("already exists")?t+=`mkdir: cannot create directory '${r}': File exists
|
|
6
|
+
`:t+=`mkdir: cannot create directory '${r}': ${s}
|
|
7
|
+
`,d=1}return{stdout:c,stderr:t,exitCode:d}}};export{y as mkdirCommand};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as y}from"./chunk-TA7RUHGQ.js";import{a as $}from"./chunk-4VDEBYW7.js";import{a as g,b as u}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var C={name:"mv",summary:"move (rename) files",usage:"mv [OPTION]... SOURCE... DEST",options:["-f, --force do not prompt before overwriting","-n, --no-clobber do not overwrite an existing file","-v, --verbose explain what is being done"," --help display this help and exit"]},P={force:{short:"f",long:"force",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},O={name:"mv",async execute(m,t){if(u(m))return g(C);let s=y("mv",m,P);if(!s.ok)return s.error;let p=s.result.flags.force,d=s.result.flags.noClobber,w=s.result.flags.verbose,l=s.result.positional;if(d&&(p=!1),l.length<2)return{stdout:"",stderr:`mv: missing destination file operand
|
|
3
|
+
`,exitCode:1};let r=l.pop()??"",v=l,n=t.fs.resolvePath(t.cwd,r),h="",c="",b=0,a=!1;try{a=(await t.fs.stat(n)).isDirectory}catch{}if(v.length>1&&!a)return{stdout:"",stderr:`mv: target '${r}' is not a directory
|
|
4
|
+
`,exitCode:1};for(let e of v)try{let f=t.fs.resolvePath(t.cwd,e),o=n;if(a){let i=e.split("/").pop()||e;o=n==="/"?`/${i}`:`${n}/${i}`}if(d)try{await t.fs.stat(o);continue}catch{}if(await t.fs.mv(f,o),w){let i=a?`${r}/${e.split("/").pop()||e}`:r;h+=`renamed '${e}' -> '${i}'
|
|
5
|
+
`}}catch(f){let o=$(f);o.includes("ENOENT")||o.includes("no such file")?c+=`mv: cannot stat '${e}': No such file or directory
|
|
6
|
+
`:c+=`mv: cannot move '${e}': ${o}
|
|
7
|
+
`,b=1}return{stdout:h,stderr:c,exitCode:b}}};export{O as mvCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as g}from"./chunk-TA7RUHGQ.js";import{a as c,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var L={name:"paste",summary:"merge lines of files",usage:"paste [OPTION]... [FILE]...",description:["Write lines consisting of the sequentially corresponding lines from","each FILE, separated by TABs, to standard output.","","With no FILE, or when FILE is -, read standard input."],options:["-d, --delimiters=LIST reuse characters from LIST instead of TABs","-s, --serial paste one file at a time instead of in parallel"," --help display this help and exit"],examples:["paste file1 file2 Merge file1 and file2 side by side","paste -d, file1 file2 Use comma as delimiter","paste -s file1 Paste all lines of file1 on one line","paste - - < file Paste pairs of lines from file"]},x={delimiter:{short:"d",long:"delimiters",type:"string",default:" "},serial:{short:"s",long:"serial",type:"boolean"}},P={name:"paste",async execute(s,i){if(m(s))return c(L);let n=g("paste",s,x);if(!n.ok)return n.error;let l=n.result.flags.delimiter,d=n.result.flags.serial,p=n.result.positional;if(p.length===0)return{stdout:"",stderr:`usage: paste [-s] [-d delimiters] file ...
|
|
3
|
+
`,exitCode:1};let a=i.stdin?i.stdin.split(`
|
|
4
|
+
`):[""];a.length>0&&a[a.length-1]===""&&a.pop();let I=p.filter(e=>e==="-").length,f=[],u=0;for(let e of p)if(e==="-"){let t=[];for(let o=u;o<a.length;o+=I)t.push(a[o]);f.push(t),u++}else{let t=i.fs.resolvePath(i.cwd,e);try{let r=(await i.fs.readFile(t)).split(`
|
|
5
|
+
`);r.length>0&&r[r.length-1]===""&&r.pop(),f.push(r)}catch{return{stdout:"",stderr:`paste: ${e}: No such file or directory
|
|
6
|
+
`,exitCode:1}}}let h="";if(d)for(let e of f)e&&(h+=`${y(e,l)}
|
|
7
|
+
`);else{let e=Math.max(...f.map(t=>t?.length??0));for(let t=0;t<e;t++){let o=[];for(let r of f)o.push(r?.[t]??"");h+=`${y(o,l)}
|
|
8
|
+
`}}return{stdout:h,stderr:"",exitCode:0}}};function y(s,i){if(s.length===0)return"";if(s.length===1)return s[0];let n=s[0];for(let l=1;l<s.length;l++){let d=(l-1)%i.length;n+=i[d]+s[l]}return n}export{P as pasteCommand};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as I}from"./chunk-4VDEBYW7.js";import{a as E,b as C}from"./chunk-GTNBSMZR.js";import{a as A,b as _}from"./chunk-5KNEBKYN.js";var $=A(S=>{(function(){"use strict";var e={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function a(o){return s(n(o),arguments)}function t(o,l){return a.apply(null,[o].concat(l||[]))}function s(o,l){var f=1,u=o.length,i,h="",d,p,c,m,k,w,v,b;for(d=0;d<u;d++)if(typeof o[d]=="string")h+=o[d];else if(typeof o[d]=="object"){if(c=o[d],c.keys)for(i=l[f],p=0;p<c.keys.length;p++){if(i==null)throw new Error(a('[sprintf] Cannot access property "%s" of undefined value "%s"',c.keys[p],c.keys[p-1]));i=i[c.keys[p]]}else c.param_no?i=l[c.param_no]:i=l[f++];if(e.not_type.test(c.type)&&e.not_primitive.test(c.type)&&i instanceof Function&&(i=i()),e.numeric_arg.test(c.type)&&typeof i!="number"&&isNaN(i))throw new TypeError(a("[sprintf] expecting number but found %T",i));switch(e.number.test(c.type)&&(v=i>=0),c.type){case"b":i=parseInt(i,10).toString(2);break;case"c":i=String.fromCharCode(parseInt(i,10));break;case"d":case"i":i=parseInt(i,10);break;case"j":i=JSON.stringify(i,null,c.width?parseInt(c.width):0);break;case"e":i=c.precision?parseFloat(i).toExponential(c.precision):parseFloat(i).toExponential();break;case"f":i=c.precision?parseFloat(i).toFixed(c.precision):parseFloat(i);break;case"g":i=c.precision?String(Number(i.toPrecision(c.precision))):parseFloat(i);break;case"o":i=(parseInt(i,10)>>>0).toString(8);break;case"s":i=String(i),i=c.precision?i.substring(0,c.precision):i;break;case"t":i=String(!!i),i=c.precision?i.substring(0,c.precision):i;break;case"T":i=Object.prototype.toString.call(i).slice(8,-1).toLowerCase(),i=c.precision?i.substring(0,c.precision):i;break;case"u":i=parseInt(i,10)>>>0;break;case"v":i=i.valueOf(),i=c.precision?i.substring(0,c.precision):i;break;case"x":i=(parseInt(i,10)>>>0).toString(16);break;case"X":i=(parseInt(i,10)>>>0).toString(16).toUpperCase();break}e.json.test(c.type)?h+=i:(e.number.test(c.type)&&(!v||c.sign)?(b=v?"+":"-",i=i.toString().replace(e.sign,"")):b="",k=c.pad_char?c.pad_char==="0"?"0":c.pad_char.charAt(1):" ",w=c.width-(b+i).length,m=c.width&&w>0?k.repeat(w):"",h+=c.align?b+i+m:k==="0"?b+m+i:m+b+i)}return h}var r=Object.create(null);function n(o){if(r[o])return r[o];for(var l=o,f,u=[],i=0;l;){if((f=e.text.exec(l))!==null)u.push(f[0]);else if((f=e.modulo.exec(l))!==null)u.push("%");else if((f=e.placeholder.exec(l))!==null){if(f[2]){i|=1;var h=[],d=f[2],p=[];if((p=e.key.exec(d))!==null)for(h.push(p[1]);(d=d.substring(p[0].length))!=="";)if((p=e.key_access.exec(d))!==null)h.push(p[1]);else if((p=e.index_access.exec(d))!==null)h.push(p[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");f[2]=h}else i|=2;if(i===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");u.push({placeholder:f[0],param_no:f[1],keys:f[2],sign:f[3],pad_char:f[4],align:f[5],width:f[6],precision:f[7],type:f[8]})}else throw new SyntaxError("[sprintf] unexpected placeholder");l=l.substring(f[0].length)}return r[o]=u}typeof S<"u"&&(S.sprintf=a,S.vsprintf=t),typeof window<"u"&&(window.sprintf=a,window.vsprintf=t,typeof define=="function"&&define.amd&&define(function(){return{sprintf:a,vsprintf:t}}))})()});var x=_($(),1);var M={name:"printf",summary:"format and print data",usage:"printf [-v var] FORMAT [ARGUMENT...]",options:[" -v var assign the output to shell variable VAR rather than display it"," --help display this help and exit"],notes:["FORMAT controls the output like in C printf.","Escape sequences: \\n (newline), \\t (tab), \\\\ (backslash)","Format specifiers: %s (string), %d (integer), %f (float), %x (hex), %o (octal), %% (literal %)","Width and precision: %10s (width 10), %.2f (2 decimal places), %010d (zero-padded)","Flags: %- (left-justify), %+ (show sign), %0 (zero-pad)"]},Q={name:"printf",async execute(e,a){if(C(e))return E(M);if(e.length===0)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
3
|
+
`,exitCode:2};let t=null,s=0;for(;s<e.length;){let o=e[s];if(o==="--"){s++;break}if(o==="-v"){if(s+1>=e.length)return{stdout:"",stderr:`printf: -v: option requires an argument
|
|
4
|
+
`,exitCode:1};if(t=e[s+1],!/^[a-zA-Z_][a-zA-Z0-9_]*(\[[^\]]+\])?$/.test(t))return{stdout:"",stderr:`printf: \`${t}': not a valid identifier
|
|
5
|
+
`,exitCode:2};s+=2}else{if(o.startsWith("-")&&o!=="-")break;break}}if(s>=e.length)return{stdout:"",stderr:`printf: usage: printf format [arguments]
|
|
6
|
+
`,exitCode:1};let r=e[s],n=e.slice(s+1);try{let o=j(r),l="",f=0,u=!1,i="";do{let{result:h,argsConsumed:d,error:p,errMsg:c,stopped:m}=N(o,n,f);if(l+=h,f+=d,p&&(u=!0,c&&(i=c)),m)break}while(f<n.length&&f>0);return f===0&&n.length>0,t?(a.env[t]=l,{stdout:"",stderr:i,exitCode:u?1:0}):{stdout:l,stderr:i,exitCode:u?1:0}}catch(o){return{stdout:"",stderr:`printf: ${I(o)}
|
|
7
|
+
`,exitCode:1}}}};function j(e){let a="",t=0;for(;t<e.length;)if(e[t]==="\\"&&t+1<e.length)switch(e[t+1]){case"n":a+=`
|
|
8
|
+
`,t+=2;break;case"t":a+=" ",t+=2;break;case"r":a+="\r",t+=2;break;case"\\":a+="\\",t+=2;break;case"a":a+="\x07",t+=2;break;case"b":a+="\b",t+=2;break;case"f":a+="\f",t+=2;break;case"v":a+="\v",t+=2;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let r="",n=t+1;for(;n<e.length&&n<t+4&&/[0-7]/.test(e[n]);)r+=e[n],n++;a+=String.fromCharCode(parseInt(r,8)),t=n;break}case"x":t+3<e.length&&/[0-9a-fA-F]{2}/.test(e.slice(t+2,t+4))?(a+=String.fromCharCode(parseInt(e.slice(t+2,t+4),16)),t+=4):(a+=e[t],t++);break;default:a+=e[t],t++}else a+=e[t],t++;return a}function N(e,a,t){let s="",r=0,n=0,o=!1,l="";for(;r<e.length;)if(e[r]==="%"&&r+1<e.length){let f=r;if(r++,e[r]==="%"){s+="%",r++;continue}for(;r<e.length&&"+-0 #'".includes(e[r]);)r++;let u=!1;if(e[r]==="*")u=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;let i=!1;if(e[r]===".")if(r++,e[r]==="*")i=!0,r++;else for(;r<e.length&&/\d/.test(e[r]);)r++;r<e.length&&"hlL".includes(e[r])&&r++;let h=e[r]||"";r++;let p=e.slice(f,r);if(u){let b=parseInt(a[t+n]||"0",10);n++,p=p.replace("*",String(b))}if(i){let b=parseInt(a[t+n]||"0",10);n++,p=p.replace(".*",`.${b}`)}let c=a[t+n]||"";n++;let{value:m,parseError:k,parseErrMsg:w,stopped:v}=W(p,h,c);if(s+=m,k&&(o=!0,w&&(l=w)),v)return{result:s,argsConsumed:n,error:o,errMsg:l,stopped:!0}}else s+=e[r],r++;return{result:s,argsConsumed:n,error:o,errMsg:l,stopped:!1}}function W(e,a,t){let s=!1,r="";switch(a){case"d":case"i":{let n=y(t);return s=g,s&&(r=`printf: ${t}: invalid number
|
|
9
|
+
`),{value:F(e,n),parseError:s,parseErrMsg:r}}case"o":{let n=y(t);return s=g,s&&(r=`printf: ${t}: invalid number
|
|
10
|
+
`),{value:z(e,n),parseError:s,parseErrMsg:r}}case"u":{let n=y(t);s=g,s&&(r=`printf: ${t}: invalid number
|
|
11
|
+
`);let o=n<0?n>>>0:n;return{value:F(e.replace("u","d"),o),parseError:s,parseErrMsg:r}}case"x":case"X":{let n=y(t);return s=g,s&&(r=`printf: ${t}: invalid number
|
|
12
|
+
`),{value:T(e,n),parseError:s,parseErrMsg:r}}case"e":case"E":case"f":case"F":case"g":case"G":{let n=parseFloat(t)||0;return{value:q(e,a,n),parseError:!1,parseErrMsg:""}}case"c":return{value:t.charAt(0)||"",parseError:!1,parseErrMsg:""};case"s":return{value:X(e,t),parseError:!1,parseErrMsg:""};case"q":return{value:U(e,t),parseError:!1,parseErrMsg:""};case"b":{let n=P(t);return{value:n.value,parseError:!1,parseErrMsg:"",stopped:n.stopped}}default:try{return{value:(0,x.sprintf)(e,t),parseError:!1,parseErrMsg:""}}catch{return{value:"",parseError:!0,parseErrMsg:`printf: [sprintf] unexpected placeholder
|
|
13
|
+
`}}}}var g=!1;function y(e){g=!1;let a=e.trimStart(),t=a!==a.trimEnd();if(e=a.trimEnd(),e.startsWith("'")&&e.length>=2||e.startsWith('"')&&e.length>=2)return e.charCodeAt(1);if(e.startsWith("\\'")&&e.length>=3||e.startsWith('\\"')&&e.length>=3)return e.charCodeAt(2);if(e.startsWith("+")&&(e=e.slice(1)),e.startsWith("0x")||e.startsWith("0X")){let s=parseInt(e,16);return Number.isNaN(s)?(g=!0,0):(t&&(g=!0),s)}if(e.startsWith("0")&&e.length>1&&/^-?0[0-7]+$/.test(e))return t&&(g=!0),parseInt(e,8)||0;if(/^\d+#/.test(e)){g=!0;let s=e.match(/^(\d+)#/);return s?parseInt(s[1],10):0}if(e!==""&&!/^-?\d+$/.test(e)){g=!0;let s=parseInt(e,10);return Number.isNaN(s)?0:s}return t&&(g=!0),parseInt(e,10)||0}function F(e,a){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[diu]$/);if(!t)return(0,x.sprintf)(e.replace(/\.\d*/,""),a);let s=t[1]||"",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,o=a<0,l=Math.abs(a),f=String(l);n>=0&&(f=f.padStart(n,"0"));let u="";o?u="-":s.includes("+")?u="+":s.includes(" ")&&(u=" ");let i=u+f;return r>i.length&&(s.includes("-")?i=i.padEnd(r," "):s.includes("0")&&n<0?i=u+f.padStart(r-u.length,"0"):i=i.padStart(r," ")),i}function z(e,a){let t=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?o$/);if(!t)return(0,x.sprintf)(e,a);let s=t[1]||"",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,o=Math.abs(a).toString(8);n>=0&&(o=o.padStart(n,"0")),s.includes("#")&&!o.startsWith("0")&&(o=`0${o}`);let l=o;return r>l.length&&(s.includes("-")?l=l.padEnd(r," "):s.includes("0")&&n<0?l=l.padStart(r,"0"):l=l.padStart(r," ")),l}function T(e,a){let t=e.includes("X"),s=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[xX]$/);if(!s)return(0,x.sprintf)(e,a);let r=s[1]||"",n=s[2]?parseInt(s[2],10):0,o=s[3]!==void 0?s[4]?parseInt(s[4],10):0:-1,l=Math.abs(a).toString(16);t&&(l=l.toUpperCase()),o>=0&&(l=l.padStart(o,"0"));let f="";r.includes("#")&&a!==0&&(f=t?"0X":"0x");let u=f+l;return n>u.length&&(r.includes("-")?u=u.padEnd(n," "):r.includes("0")&&o<0?u=f+l.padStart(n-f.length,"0"):u=u.padStart(n," ")),u}function O(e){if(e==="")return"''";if(/^[a-zA-Z0-9_./-]+$/.test(e))return e;if(/[\x00-\x1f\x7f]/.test(e)){let s="$'";for(let r of e){let n=r.charCodeAt(0);r==="'"?s+="\\'":r==="\\"?s+="\\\\":r===`
|
|
14
|
+
`?s+="\\n":r===" "?s+="\\t":r==="\r"?s+="\\r":r==="\x07"?s+="\\a":r==="\b"?s+="\\b":r==="\f"?s+="\\f":r==="\v"?s+="\\v":r==="\x1B"?s+="\\E":n<32||n>126?s+=`\\x${n.toString(16).padStart(2,"0")}`:r==='"'?s+='\\"':s+=r}return s+="'",s}let t="";for(let s of e)" |&;<>()$`\\\"'*?[#~=%!{}".includes(s)?t+=`\\${s}`:t+=s;return t}function X(e,a){let t=e.match(/^%(-?)(\d*)(\.(\d*))?s$/);if(!t)return(0,x.sprintf)(e.replace(/0+(?=\d)/,""),a);let s=t[1]==="-",r=t[2]?parseInt(t[2],10):0,n=t[3]!==void 0?t[4]?parseInt(t[4],10):0:-1,o=a;return n>=0&&o.length>n&&(o=o.slice(0,n)),r>o.length&&(s?o=o.padEnd(r," "):o=o.padStart(r," ")),o}function U(e,a){let t=O(a),s=e.match(/^%(-?)(\d*)q$/);if(!s)return t;let r=s[1]==="-",n=s[2]?parseInt(s[2],10):0,o=t;return n>o.length&&(r?o=o.padEnd(n," "):o=o.padStart(n," ")),o}function q(e,a,t){let s=e.match(/^%([- +#0']*)(\d*)(\.(\d*))?[eEfFgG]$/);if(!s)return(0,x.sprintf)(e,t);let r=s[1]||"",n=s[2]?parseInt(s[2],10):0,o=s[3]!==void 0?s[4]?parseInt(s[4],10):0:6,l,f=a.toLowerCase();if(f==="e"?(l=t.toExponential(o),l=l.replace(/e([+-])(\d)$/,"e$10$2"),a==="E"&&(l=l.toUpperCase())):f==="f"?(l=t.toFixed(o),r.includes("#")&&o===0&&!l.includes(".")&&(l+=".")):f==="g"?(l=t.toPrecision(o||1),r.includes("#")||(l=l.replace(/\.?0+$/,""),l=l.replace(/\.?0+e/,"e")),l=l.replace(/e([+-])(\d)$/,"e$10$2"),a==="G"&&(l=l.toUpperCase())):l=t.toString(),t>=0&&(r.includes("+")?l=`+${l}`:r.includes(" ")&&(l=` ${l}`)),n>l.length)if(r.includes("-"))l=l.padEnd(n," ");else if(r.includes("0")){let u=l.match(/^[+ -]/)?.[0]||"",i=u?l.slice(1):l;l=u+i.padStart(n-u.length,"0")}else l=l.padStart(n," ");return l}function P(e){let a="",t=0;for(;t<e.length;)if(e[t]==="\\"&&t+1<e.length)switch(e[t+1]){case"n":a+=`
|
|
15
|
+
`,t+=2;break;case"t":a+=" ",t+=2;break;case"r":a+="\r",t+=2;break;case"\\":a+="\\",t+=2;break;case"a":a+="\x07",t+=2;break;case"b":a+="\b",t+=2;break;case"f":a+="\f",t+=2;break;case"v":a+="\v",t+=2;break;case"c":return{value:a,stopped:!0};case"x":{let r="",n=t+2;for(;n<e.length&&n<t+4&&/[0-9a-fA-F]/.test(e[n]);)r+=e[n],n++;r?(a+=String.fromCharCode(parseInt(r,16)),t=n):(a+="\\x",t+=2);break}case"u":{let r="",n=t+2;for(;n<e.length&&n<t+6&&/[0-9a-fA-F]/.test(e[n]);)r+=e[n],n++;r?(a+=String.fromCodePoint(parseInt(r,16)),t=n):(a+="\\u",t+=2);break}case"0":{let r="",n=t+2;for(;n<e.length&&n<t+5&&/[0-7]/.test(e[n]);)r+=e[n],n++;r?a+=String.fromCharCode(parseInt(r,8)):a+="\0",t=n;break}case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let r="",n=t+1;for(;n<e.length&&n<t+4&&/[0-7]/.test(e[n]);)r+=e[n],n++;a+=String.fromCharCode(parseInt(r,8)),t=n;break}default:a+=e[t],t++}else a+=e[t],t++;return{value:a,stopped:!1}}export{Q as printfCommand};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as h,b as u}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var m={name:"readlink",summary:"print resolved symbolic links or canonical file names",usage:"readlink [OPTIONS] FILE...",options:["-f canonicalize by following every symlink in every component of the given name recursively"," --help display this help and exit"]},y={name:"readlink",async execute(i,r){if(u(i))return h(m);let s=!1,t=0;for(;t<i.length&&i[t].startsWith("-");){let n=i[t];if(n==="-f"||n==="--canonicalize")s=!0,t++;else if(n==="--"){t++;break}else return{stdout:"",stderr:`readlink: invalid option -- '${n.slice(1)}'
|
|
3
|
+
`,exitCode:1}}let d=i.slice(t);if(d.length===0)return{stdout:"",stderr:`readlink: missing operand
|
|
4
|
+
`,exitCode:1};let l="",c=!1;for(let n of d){let a=r.fs.resolvePath(r.cwd,n);try{if(s){let e=a,f=new Set;for(;!f.has(e);){f.add(e);try{let o=await r.fs.readlink(e);if(o.startsWith("/"))e=o;else{let k=e.substring(0,e.lastIndexOf("/"))||"/";e=r.fs.resolvePath(k,o)}}catch{break}}l+=`${e}
|
|
5
|
+
`}else{let e=await r.fs.readlink(a);l+=`${e}
|
|
6
|
+
`}}catch{s?l+=`${a}
|
|
7
|
+
`:c=!0}}return{stdout:l,stderr:"",exitCode:c?1:0}}};export{y as readlinkCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as u}from"./chunk-TA7RUHGQ.js";import{a as m}from"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var v={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},y={name:"rm",async execute(d,s){let e=u("rm",d,v);if(!e.ok)return e.error;let a=e.result.flags.recursive||e.result.flags.recursiveUpper,c=e.result.flags.force,p=e.result.flags.verbose,l=e.result.positional;if(l.length===0)return c?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
|
|
3
|
+
`,exitCode:1};let f="",t="",i=0;for(let r of l)try{let n=s.fs.resolvePath(s.cwd,r);if((await s.fs.stat(n)).isDirectory&&!a){t+=`rm: cannot remove '${r}': Is a directory
|
|
4
|
+
`,i=1;continue}await s.fs.rm(n,{recursive:a,force:c}),p&&(f+=`removed '${r}'
|
|
5
|
+
`)}catch(n){if(!c){let o=m(n);o.includes("ENOENT")||o.includes("no such file")?t+=`rm: cannot remove '${r}': No such file or directory
|
|
6
|
+
`:o.includes("ENOTEMPTY")||o.includes("not empty")?t+=`rm: cannot remove '${r}': Directory not empty
|
|
7
|
+
`:t+=`rm: cannot remove '${r}': ${o}
|
|
8
|
+
`,i=1}}return{stdout:f,stderr:t,exitCode:i}}};export{y as rmCommand};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{i as $}from"./chunk-LV662IGP.js";import{a as I,b as N,c as S}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var R=1e4;function W(t){return{patternSpace:"",holdSpace:"",lineNumber:0,totalLines:t,deleted:!1,printed:!1,quit:!1,appendBuffer:[],substitutionMade:!1,lineNumberOutput:[],restartCycle:!1}}function _(t){return typeof t=="object"&&"first"in t&&"step"in t}function M(t,e,i,s){if(t==="$")return e===i;if(typeof t=="number")return e===t;if(_(t)){let{first:n,step:a}=t;return a===0?e===n:(e-n)%a===0&&e>=n}if(typeof t=="object"&&"pattern"in t)try{return new RegExp(t.pattern).test(s)}catch{return!1}return!1}function x(t,e,i,s){if(!t||!t.start&&!t.end)return!0;let n=t.start,a=t.end;if(n!==void 0&&a===void 0)return M(n,e,i,s);if(n!==void 0&&a!==void 0){let r=typeof n=="number"?n:n==="$"?i:1,o=typeof a=="number"?a:i;return typeof n=="object"&&"pattern"in n&&M(n,e,i,s)?!0:e>=r&&e<=o}return!0}function O(t,e,i){let s="",n=0;for(;n<t.length;){if(t[n]==="\\"&&n+1<t.length){let a=t[n+1];if(a==="&"){s+="&",n+=2;continue}if(a==="n"){s+=`
|
|
3
|
+
`,n+=2;continue}if(a==="t"){s+=" ",n+=2;continue}let r=parseInt(a,10);if(r>=1&&r<=9){s+=i[r-1]||"",n+=2;continue}s+=a,n+=2;continue}if(t[n]==="&"){s+=e,n++;continue}s+=t[n],n++}return s}function v(t,e){let{lineNumber:i,totalLines:s,patternSpace:n}=e;if(t.type!=="label"&&x(t.address,i,s,n))switch(t.type){case"substitute":{let a=t,r="";a.global&&(r+="g"),a.ignoreCase&&(r+="i");try{let o=new RegExp(a.pattern,r),u=e.patternSpace;if(a.nthOccurrence&&a.nthOccurrence>0&&!a.global){let l=0,p=a.nthOccurrence;e.patternSpace=e.patternSpace.replace(new RegExp(a.pattern,`g${a.ignoreCase?"i":""}`),(d,...c)=>{if(l++,l===p){let h=c.slice(0,-2);return O(a.replacement,d,h)}return d})}else e.patternSpace=e.patternSpace.replace(o,(l,...p)=>{let d=p.slice(0,-2);return O(a.replacement,l,d)});u!==e.patternSpace&&(e.substitutionMade=!0,a.printOnMatch&&(e.printed=!0))}catch{}break}case"print":e.printed=!0;break;case"printFirstLine":{let a=e.patternSpace.indexOf(`
|
|
4
|
+
`);a!==-1?e.lineNumberOutput.push(e.patternSpace.slice(0,a)):e.lineNumberOutput.push(e.patternSpace);break}case"delete":e.deleted=!0;break;case"deleteFirstLine":{let a=e.patternSpace.indexOf(`
|
|
5
|
+
`);a!==-1?(e.patternSpace=e.patternSpace.slice(a+1),e.restartCycle=!0):e.deleted=!0;break}case"zap":e.patternSpace="";break;case"append":e.appendBuffer.push(t.text);break;case"insert":e.appendBuffer.unshift(`__INSERT__${t.text}`);break;case"change":e.patternSpace=t.text,e.deleted=!0,e.appendBuffer.push(t.text);break;case"hold":e.holdSpace=e.patternSpace;break;case"holdAppend":e.holdSpace?e.holdSpace+=`
|
|
6
|
+
${e.patternSpace}`:e.holdSpace=e.patternSpace;break;case"get":e.patternSpace=e.holdSpace;break;case"getAppend":e.patternSpace+=`
|
|
7
|
+
${e.holdSpace}`;break;case"exchange":{let a=e.patternSpace;e.patternSpace=e.holdSpace,e.holdSpace=a;break}case"next":e.printed=!0;break;case"quit":e.quit=!0;break;case"transliterate":e.patternSpace=P(e.patternSpace,t);break;case"lineNumber":e.lineNumberOutput.push(String(e.lineNumber));break;case"branch":break;case"branchOnSubst":break;case"branchOnNoSubst":break;case"group":break}}function P(t,e){let i="";for(let s of t){let n=e.source.indexOf(s);n!==-1?i+=e.dest[n]:i+=s}return i}function y(t,e,i,s){let n=new Map;for(let f=0;f<t.length;f++){let l=t[f];l.type==="label"&&n.set(l.name,f)}let a=s?.maxIterations??R,r=0,o=0,u=0;for(;u<t.length;){if(r++,r>a)throw new $(`sed: command execution exceeded maximum iterations (${a})`,"iterations");if(e.deleted||e.quit||e.restartCycle)break;let f=t[u];if(f.type==="nextAppend"){if(x(f.address,e.lineNumber,e.totalLines,e.patternSpace))if(i&&i.currentLineIndex+o+1<i.lines.length){o++;let l=i.lines[i.currentLineIndex+o];e.patternSpace+=`
|
|
8
|
+
${l}`,e.lineNumber=i.currentLineIndex+o+1}else{e.quit=!0,e.deleted=!0;break}u++;continue}if(f.type==="branch"){let l=f;if(x(l.address,e.lineNumber,e.totalLines,e.patternSpace)){if(l.label){let p=n.get(l.label);if(p!==void 0){u=p;continue}}break}u++;continue}if(f.type==="branchOnSubst"){let l=f;if(x(l.address,e.lineNumber,e.totalLines,e.patternSpace)&&e.substitutionMade){if(e.substitutionMade=!1,l.label){let p=n.get(l.label);if(p!==void 0){u=p;continue}}break}u++;continue}if(f.type==="branchOnNoSubst"){let l=f;if(x(l.address,e.lineNumber,e.totalLines,e.patternSpace)&&!e.substitutionMade){if(l.label){let p=n.get(l.label);if(p!==void 0){u=p;continue}}break}u++;continue}if(f.type==="group"){let l=f;x(l.address,e.lineNumber,e.totalLines,e.patternSpace)&&y(l.commands,e,i,s),u++;continue}v(f,e),u++}return o}var A={r:"r (read file) - file operations not supported",R:"R (read line from file) - file operations not supported",w:"w (write to file) - file operations not supported",W:"W (write first line to file) - file operations not supported",e:"e (execute shell command) - shell execution not supported",l:"l (list/escape special chars) - not implemented",F:"F (print filename) - not implemented",Q:"Q (quit without printing) - use 'q' instead",v:"v (version check) - not implemented"};function C(t){if(t==="$")return"$";let e=t.match(/^(\d+)~(\d+)$/);if(e)return{first:parseInt(e[1],10),step:parseInt(e[2],10)};let i=parseInt(t,10);if(!Number.isNaN(i))return i;if(t.startsWith("/")&&t.endsWith("/"))return{pattern:t.slice(1,-1)}}function T(t){let e=t,i,s,n=e.match(/^(\d+)~(\d+)/);if(n)return i={first:parseInt(n[1],10),step:parseInt(n[2],10)},e=e.slice(n[0].length),{range:{start:i,end:void 0},rest:e};if(e.startsWith("$")){if(i="$",e=e.slice(1),e.startsWith(",")){e=e.slice(1);let r=e.match(/^(\d+|\$)/);r&&(s=C(r[1]),e=e.slice(r[0].length))}return{range:{start:i,end:s},rest:e}}let a=e.match(/^(\d+)/);if(a){if(i=parseInt(a[1],10),e=e.slice(a[0].length),e.startsWith(",")){e=e.slice(1);let r=e.match(/^(\d+|\$)/);r&&(s=C(r[1]),e=e.slice(r[0].length))}return{range:{start:i,end:s},rest:e}}if(e.startsWith("/")){let r=1;for(;r<e.length&&e[r]!=="/";)e[r]==="\\"&&r+1<e.length?r+=2:r++;if(r<e.length){if(i={pattern:e.slice(1,r)},e=e.slice(r+1),e.startsWith(","))if(e=e.slice(1),e.startsWith("/")){let o=1;for(;o<e.length&&e[o]!=="/";)e[o]==="\\"&&o+1<e.length?o+=2:o++;o<e.length&&(s={pattern:e.slice(1,o)},e=e.slice(o+1))}else{let o=e.match(/^(\d+|\$)/);o&&(s=C(o[1]),e=e.slice(o[0].length))}return{range:{start:i,end:s},rest:e}}}return{rest:e}}function q(t){let e=t.trim();if(!e)return{command:null};let{range:i,rest:s}=T(e),n=s.trim();if(!n&&i)return{command:{type:"print",address:i}};let a=n[0];switch(a){case"p":return{command:{type:"print",address:i}};case"d":return{command:{type:"delete",address:i}};case"h":return{command:{type:"hold",address:i}};case"H":return{command:{type:"holdAppend",address:i}};case"g":if(n.length===1||/^\s/.test(n[1]))return{command:{type:"get",address:i}};break;case"G":return{command:{type:"getAppend",address:i}};case"x":return{command:{type:"exchange",address:i}};case"n":return{command:{type:"next",address:i}};case"N":return{command:{type:"nextAppend",address:i}};case"P":return{command:{type:"printFirstLine",address:i}};case"D":return{command:{type:"deleteFirstLine",address:i}};case"q":return{command:{type:"quit",address:i}};case"z":return{command:{type:"zap",address:i}};case"=":return{command:{type:"lineNumber",address:i}};case"y":return D(n,i);case"b":{let r=n.slice(1).trim();return{command:{type:"branch",address:i,label:r||void 0}}}case"t":{let r=n.slice(1).trim();return{command:{type:"branchOnSubst",address:i,label:r||void 0}}}case"T":{let r=n.slice(1).trim();return{command:{type:"branchOnNoSubst",address:i,label:r||void 0}}}case"{":return B(n,i);case":":{let r=n.slice(1).trim();return r?{command:{type:"label",name:r}}:{command:null,error:"missing label name"}}case"a":if(n[1]==="\\"||n[1]===" "){let r=n.slice(2).replace(/^[\s]*/,"");return{command:{type:"append",address:i,text:r}}}break;case"i":if(n[1]==="\\"||n[1]===" "){let r=n.slice(2).replace(/^[\s]*/,"");return{command:{type:"insert",address:i,text:r}}}break;case"c":if(n[1]==="\\"||n[1]===" "){let r=n.slice(2).replace(/^[\s]*/,"");return{command:{type:"change",address:i,text:r}}}break;case"s":return L(n,i)}return n.startsWith("s")?L(n,i):a&&A[a]?{command:null,error:`unsupported command: ${A[a]}`}:{command:null,error:`invalid command: ${t}`}}function D(t,e){if(!t.startsWith("y")||t.length<4)return{command:null,error:"invalid transliteration"};let i=t[1],s=2,n="",a="";for(;s<t.length&&t[s]!==i;)if(t[s]==="\\"&&s+1<t.length){let r=t[s+1];r==="n"?n+=`
|
|
9
|
+
`:r==="t"?n+=" ":n+=r,s+=2}else n+=t[s],s++;if(s>=t.length)return{command:null,error:"unterminated transliteration source"};for(s++;s<t.length&&t[s]!==i;)if(t[s]==="\\"&&s+1<t.length){let r=t[s+1];r==="n"?a+=`
|
|
10
|
+
`:r==="t"?a+=" ":a+=r,s+=2}else a+=t[s],s++;return n.length!==a.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:e,source:n,dest:a}}}function L(t,e){if(!t.startsWith("s")||t.length<4)return{command:null,error:"invalid substitution"};let i=t[1],s="",n="",a="",r=2;for(;r<t.length&&t[r]!==i;)t[r]==="\\"&&r+1<t.length?(s+=t[r]+t[r+1],r+=2):(s+=t[r],r++);if(r>=t.length)return{command:null,error:"unterminated substitution pattern"};for(r++;r<t.length&&t[r]!==i;)t[r]==="\\"&&r+1<t.length?(n+=t[r]+t[r+1],r+=2):(n+=t[r],r++);r<t.length&&(r++,a=t.slice(r));let o,u=a.match(/(\d+)/);return u&&(o=parseInt(u[1],10)),{command:{type:"substitute",address:e,pattern:s,replacement:n,global:a.includes("g"),ignoreCase:a.includes("i"),printOnMatch:a.includes("p"),nthOccurrence:o}}}function B(t,e){let i=1,s=1,n=!1,a="",r=0;for(;s<t.length&&i>0;){let l=t[s];if(l==="\\"&&s+1<t.length){s+=2;continue}if(!n&&l==="s"&&s+1<t.length&&/[^a-zA-Z0-9]/.test(t[s+1])){n=!0,a=t[s+1],r=0,s++;continue}if(n&&l===a){r++,r>=3&&(n=!1),s++;continue}n||(l==="{"?i++:l==="}"&&i--),s++}if(i!==0)return{command:null,error:"unmatched brace in grouped commands"};let o=t.slice(1,s-1).trim(),u=F(o),f=[];for(let l of u){let p=q(l);if(p.error)return{command:null,error:p.error};p.command&&f.push(p.command)}return{command:{type:"group",address:e,commands:f}}}function E(t,e=!1){let i=[];for(let s of t){let n=F(s);for(let a of n){let r=q(a);if(r.error)return{commands:[],error:r.error};r.command&&(r.command.type==="substitute"&&e&&(r.command.extendedRegex=!0),i.push(r.command))}}return{commands:i}}function F(t){let e=[],i="",s=!1,n="",a=0,r=0,o=0;for(;o<t.length;){let u=t[o];if(u==="\\"&&o+1<t.length){i+=u+t[o+1],o+=2;continue}if(!s){if(u==="{"){r++,i+=u,o++;continue}if(u==="}"){r--,i+=u,o++;continue}}if(!s&&u==="s"&&o+1<t.length&&/[^a-zA-Z0-9]/.test(t[o+1])){n=t[o+1],a=0,s=!0,i+=u,o++;continue}if(s&&u===n){a++,i+=u,a>=3&&(s=!1),o++;continue}if(!s&&r===0&&u===";"){i.trim()&&e.push(i.trim()),i="",o++;continue}i+=u,o++}return i.trim()&&e.push(i.trim()),e}var z={name:"sed",summary:"stream editor for filtering and transforming text",usage:"sed [OPTION]... {script} [input-file]...",options:["-n, --quiet, --silent suppress automatic printing of pattern space","-e script add the script to commands to be executed","-f script-file read script from file","-i, --in-place edit files in place","-E, -r, --regexp-extended use extended regular expressions"," --help display this help and exit"],description:`Commands:
|
|
11
|
+
s/regexp/replacement/[flags] substitute
|
|
12
|
+
d delete pattern space
|
|
13
|
+
p print pattern space
|
|
14
|
+
a\\ text append text after line
|
|
15
|
+
i\\ text insert text before line
|
|
16
|
+
c\\ text change (replace) line with text
|
|
17
|
+
h copy pattern space to hold space
|
|
18
|
+
H append pattern space to hold space
|
|
19
|
+
g copy hold space to pattern space
|
|
20
|
+
G append hold space to pattern space
|
|
21
|
+
x exchange pattern and hold spaces
|
|
22
|
+
n read next line into pattern space
|
|
23
|
+
N append next line to pattern space
|
|
24
|
+
y/source/dest/ transliterate characters
|
|
25
|
+
= print line number
|
|
26
|
+
b [label] branch to label
|
|
27
|
+
t [label] branch on substitution
|
|
28
|
+
:label define label
|
|
29
|
+
q quit
|
|
30
|
+
|
|
31
|
+
Addresses:
|
|
32
|
+
N line number
|
|
33
|
+
$ last line
|
|
34
|
+
/regexp/ lines matching regexp
|
|
35
|
+
N,M range from line N to M`};function w(t,e,i,s){let n=t.split(`
|
|
36
|
+
`);n.length>0&&n[n.length-1]===""&&n.pop();let a=n.length,r="",o="",u=!1,f=s?{maxIterations:s.maxSedIterations}:void 0;for(let l=0;l<n.length;l++){let p={...W(a),patternSpace:n[l],holdSpace:o,lineNumber:l+1,totalLines:a,substitutionMade:!1},d={lines:n,currentLineIndex:l},c=0,h=1e4,b=0;do{if(c++,c>h)break;p.restartCycle=!1;let m=y(e,p,d,f);b+=m,d.currentLineIndex+=m}while(p.restartCycle&&!p.deleted&&!p.quit);l+=b,o=p.holdSpace,u=p.substitutionMade;for(let m of p.lineNumberOutput)r+=`${m}
|
|
37
|
+
`;let g=[],k=[];for(let m of p.appendBuffer)m.startsWith("__INSERT__")?g.push(m.slice(10)):k.push(m);for(let m of g)r+=`${m}
|
|
38
|
+
`;p.deleted||(i?p.printed&&(r+=`${p.patternSpace}
|
|
39
|
+
`):r+=`${p.patternSpace}
|
|
40
|
+
`);for(let m of k)r+=`${m}
|
|
41
|
+
`;if(p.quit)break}return r}var X={name:"sed",async execute(t,e){if(N(t))return I(z);let i=[],s=[],n=!1,a=!1,r=!1,o=[];for(let d=0;d<t.length;d++){let c=t[d];if(c==="-n"||c==="--quiet"||c==="--silent")n=!0;else if(c==="-i"||c==="--in-place")a=!0;else if(c.startsWith("-i"))a=!0;else if(c==="-E"||c==="-r"||c==="--regexp-extended")r=!0;else if(c==="-e")d+1<t.length&&i.push(t[++d]);else if(c==="-f")d+1<t.length&&s.push(t[++d]);else{if(c.startsWith("--"))return S("sed",c);if(c.startsWith("-")&&c.length>1){for(let h of c.slice(1))if(h!=="n"&&h!=="e"&&h!=="f"&&h!=="i"&&h!=="E"&&h!=="r")return S("sed",`-${h}`);c.includes("n")&&(n=!0),c.includes("i")&&(a=!0),(c.includes("E")||c.includes("r"))&&(r=!0),c.includes("e")&&!c.includes("n")&&!c.includes("i")&&d+1<t.length&&i.push(t[++d]),c.includes("f")&&!c.includes("e")&&d+1<t.length&&s.push(t[++d])}else!c.startsWith("-")&&i.length===0&&s.length===0?i.push(c):c.startsWith("-")||o.push(c)}}for(let d of s){let c=e.fs.resolvePath(e.cwd,d);try{let h=await e.fs.readFile(c);for(let b of h.split(`
|
|
42
|
+
`)){let g=b.trim();g&&!g.startsWith("#")&&i.push(g)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${d}: No such file or directory
|
|
43
|
+
`,exitCode:1}}}if(i.length===0)return{stdout:"",stderr:`sed: no script specified
|
|
44
|
+
`,exitCode:1};let{commands:u,error:f}=E(i,r);if(f)return{stdout:"",stderr:`sed: ${f}
|
|
45
|
+
`,exitCode:1};if(u.length===0)return{stdout:"",stderr:`sed: no valid commands
|
|
46
|
+
`,exitCode:1};let l="";if(o.length===0)return l=e.stdin,{stdout:w(l,u,n,e.limits),stderr:"",exitCode:0};if(a){for(let d of o){let c=e.fs.resolvePath(e.cwd,d);try{let h=await e.fs.readFile(c),b=w(h,u,n,e.limits);await e.fs.writeFile(c,b)}catch{return{stdout:"",stderr:`sed: ${d}: No such file or directory
|
|
47
|
+
`,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}for(let d of o){let c=e.fs.resolvePath(e.cwd,d);try{l+=await e.fs.readFile(c)}catch{return{stdout:"",stderr:`sed: ${d}: No such file or directory
|
|
48
|
+
`,exitCode:1}}}return{stdout:w(l,u,n,e.limits),stderr:"",exitCode:0}}};export{X as sedCommand};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-5KNEBKYN.js";var F={name:"seq",async execute(r){let d=`
|
|
3
|
+
`,h=!1,i=[],e=0;for(;e<r.length;){let t=r[e];if(t==="-s"&&e+1<r.length){d=r[e+1],e+=2;continue}if(t==="-w"){h=!0,e++;continue}if(t==="--"){e++;break}if(t.startsWith("-")&&t!=="-"){if(t.startsWith("-s")&&t.length>2){d=t.slice(2),e++;continue}if((t==="-ws"||t==="-sw")&&(h=!0,e+1<r.length)){d=r[e+1],e+=2;continue}}i.push(t),e++}for(;e<r.length;)i.push(r[e]),e++;if(i.length===0)return{stdout:"",stderr:`seq: missing operand
|
|
4
|
+
`,exitCode:1};let l=1,o=1,a;if(i.length===1?a=parseFloat(i[0]):i.length===2?(l=parseFloat(i[0]),a=parseFloat(i[1])):(l=parseFloat(i[0]),o=parseFloat(i[1]),a=parseFloat(i[2])),Number.isNaN(l)||Number.isNaN(o)||Number.isNaN(a))return{stdout:"",stderr:`seq: invalid floating point argument: '${i.find(n=>Number.isNaN(parseFloat(n)))}'
|
|
5
|
+
`,exitCode:1};if(o===0)return{stdout:"",stderr:`seq: invalid Zero increment value: '0'
|
|
6
|
+
`,exitCode:1};let s=[],f=t=>{let n=String(t),u=n.indexOf(".");return u===-1?0:n.length-u-1},c=Math.max(f(l),f(o),f(a)),p=1e5,m=0;if(o>0)for(let t=l;t<=a+1e-10&&!(m++>p);t+=o)s.push(c>0?t.toFixed(c):String(Math.round(t)));else for(let t=l;t>=a-1e-10&&!(m++>p);t+=o)s.push(c>0?t.toFixed(c):String(Math.round(t)));if(h&&s.length>0){let t=Math.max(...s.map(n=>n.replace("-","").length));for(let n=0;n<s.length;n++){let u=s[n].startsWith("-"),x=(u?s[n].slice(1):s[n]).padStart(t,"0");s[n]=u?`-${x}`:x}}let g=s.join(d);return{stdout:g?`${g}
|
|
7
|
+
`:"",stderr:"",exitCode:0}}};export{F as seqCommand};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a,b as o}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var i={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
3
|
+
s - seconds (default)
|
|
4
|
+
m - minutes
|
|
5
|
+
h - hours
|
|
6
|
+
d - days
|
|
7
|
+
|
|
8
|
+
NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};function l(t){let s=t.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!s)return null;let e=parseFloat(s[1]);switch(s[2]||"s"){case"s":return e*1e3;case"m":return e*60*1e3;case"h":return e*60*60*1e3;case"d":return e*24*60*60*1e3;default:return null}}var d={name:"sleep",async execute(t,s){if(o(t))return a(i);if(t.length===0)return{stdout:"",stderr:`sleep: missing operand
|
|
9
|
+
`,exitCode:1};let e=0;for(let n of t){let r=l(n);if(r===null)return{stdout:"",stderr:`sleep: invalid time interval '${n}'
|
|
10
|
+
`,exitCode:1};e+=r}return s.sleep?await s.sleep(e):await new Promise(n=>setTimeout(n,e)),{stdout:"",stderr:"",exitCode:0}}};export{d as sleepCommand};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as F}from"./chunk-J7MJV6WO.js";import{a as v,b as y,c as C}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";function k(u,t,r){let f=r!==null?r:/\s+/,a=u.split(f),s=t.startField-1;if(s>=a.length)return"";if(t.endField===void 0){let i=a[s]||"";return t.startChar!==void 0&&(i=i.slice(t.startChar-1)),t.ignoreLeading&&(i=i.trimStart()),i}let l=Math.min(t.endField-1,a.length-1),c="";for(let i=s;i<=l&&i<a.length;i++){let o=a[i]||"";if(i===s&&t.startChar!==void 0&&(o=o.slice(t.startChar-1)),i===l&&t.endChar!==void 0){let e=i===s&&t.startChar!==void 0?t.endChar-t.startChar+1:t.endChar;o=o.slice(0,e)}i>s&&(c+=r||" "),c+=o}return t.ignoreLeading&&(c=c.trimStart()),c}function S(u,t,r,f){if(r){let l=parseFloat(u)||0,c=parseFloat(t)||0;return l-c}let a=u,s=t;return f&&(a=a.toLowerCase(),s=s.toLowerCase()),a.localeCompare(s)}function b(u){let{keys:t,fieldDelimiter:r,numeric:f,ignoreCase:a,reverse:s}=u;return(l,c)=>{if(t.length===0){let o=l,e=c;a&&(o=o.toLowerCase(),e=e.toLowerCase());let n;if(f){let d=parseFloat(o)||0,h=parseFloat(e)||0;if(n=d-h,n===0){let p=o.localeCompare(e);return s?-p:p}}else n=o.localeCompare(e);return s?-n:n}for(let o of t){let e=k(l,o,r),n=k(c,o,r),d=o.numeric??f,h=o.ignoreCase??a,p=o.reverse??s,g=S(e,n,d,h);if(g!==0)return p?-g:g}let i=l.localeCompare(c);return s?-i:i}}function w(u,t){if(t.keys.length===0){if(t.ignoreCase){let a=new Set;return u.filter(s=>{let l=s.toLowerCase();return a.has(l)?!1:(a.add(l),!0)})}return[...new Set(u)]}let r=t.keys[0],f=new Set;return u.filter(a=>{let s=k(a,r,t.fieldDelimiter);return(r.ignoreCase??t.ignoreCase)&&(s=s.toLowerCase()),f.has(s)?!1:(f.add(s),!0)})}function m(u){let t={startField:1},r="",f=u,a=f.match(/([nrfb]+)$/i);a&&(r=a[1].toLowerCase(),f=f.slice(0,-r.length)),r.includes("n")&&(t.numeric=!0),r.includes("r")&&(t.reverse=!0),r.includes("f")&&(t.ignoreCase=!0),r.includes("b")&&(t.ignoreLeading=!0);let s=f.split(",");if(s.length===0||s[0]==="")return null;let l=s[0].split("."),c=parseInt(l[0],10);if(Number.isNaN(c)||c<1)return null;if(t.startField=c,l.length>1&&l[1]){let i=parseInt(l[1],10);!Number.isNaN(i)&&i>=1&&(t.startChar=i)}if(s.length>1&&s[1]){let i=s[1],o=i.match(/([nrfb]+)$/i);if(o){let n=o[1].toLowerCase();n.includes("n")&&(t.numeric=!0),n.includes("r")&&(t.reverse=!0),n.includes("f")&&(t.ignoreCase=!0),n.includes("b")&&(t.ignoreLeading=!0),i=i.slice(0,-n.length)}let e=i.split(".");if(e[0]){let n=parseInt(e[0],10);if(!Number.isNaN(n)&&n>=1&&(t.endField=n),e.length>1&&e[1]){let d=parseInt(e[1],10);!Number.isNaN(d)&&d>=1&&(t.endChar=d)}}}return t}var N={name:"sort",summary:"sort lines of text files",usage:"sort [OPTION]... [FILE]...",options:["-f, --ignore-case fold lower case to upper case characters","-n, --numeric-sort compare according to string numerical value","-r, --reverse reverse the result of comparisons","-u, --unique output only unique lines","-k, --key=KEYDEF sort via a key; KEYDEF gives location and type","-t, --field-separator=SEP use SEP as field separator"," --help display this help and exit"],description:`KEYDEF is F[.C][OPTS][,F[.C][OPTS]]
|
|
3
|
+
F is a field number (1-indexed)
|
|
4
|
+
C is a character position within the field (1-indexed)
|
|
5
|
+
OPTS can be: n (numeric), r (reverse), f (fold case), b (ignore blanks)
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
-k1 sort by first field
|
|
9
|
+
-k2,2 sort by second field only
|
|
10
|
+
-k1.3 sort by first field starting at 3rd character
|
|
11
|
+
-k1,2n sort by fields 1-2 numerically
|
|
12
|
+
-k2 -k1 sort by field 2, then by field 1`},D={name:"sort",async execute(u,t){if(y(u))return v(N);let r={reverse:!1,numeric:!1,unique:!1,ignoreCase:!1,keys:[],fieldDelimiter:null},f=[];for(let o=0;o<u.length;o++){let e=u[o];if(e==="-r"||e==="--reverse")r.reverse=!0;else if(e==="-n"||e==="--numeric-sort")r.numeric=!0;else if(e==="-u"||e==="--unique")r.unique=!0;else if(e==="-f"||e==="--ignore-case")r.ignoreCase=!0;else if(e==="-t"||e==="--field-separator")r.fieldDelimiter=u[++o]||null;else if(e.startsWith("-t"))r.fieldDelimiter=e.slice(2)||null;else if(e.startsWith("--field-separator="))r.fieldDelimiter=e.slice(18)||null;else if(e==="-k"||e==="--key"){let n=u[++o];if(n){let d=m(n);d&&r.keys.push(d)}}else if(e.startsWith("-k")){let n=m(e.slice(2));n&&r.keys.push(n)}else if(e.startsWith("--key=")){let n=m(e.slice(6));n&&r.keys.push(n)}else{if(e.startsWith("--"))return C("sort",e);if(e.startsWith("-")&&!e.startsWith("--")){let n=!1;for(let d of e.slice(1))if(d==="r")r.reverse=!0;else if(d==="n")r.numeric=!0;else if(d==="u")r.unique=!0;else if(d==="f")r.ignoreCase=!0;else{n=!0;break}if(n)return C("sort",e)}else f.push(e)}}let a=await F(t,f,{cmdName:"sort"});if(!a.ok)return a.error;let l=a.content.split(`
|
|
13
|
+
`);l.length>0&&l[l.length-1]===""&&l.pop();let c=b(r);return l.sort(c),r.unique&&(l=w(l,r)),{stdout:l.length>0?`${l.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`:"",stderr:"",exitCode:0}}};export{D as sortCommand};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as d}from"./chunk-TA7RUHGQ.js";import{a as u,b as g}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var S={name:"stat",summary:"display file or file system status",usage:"stat [OPTION]... FILE...",options:["-c FORMAT use the specified FORMAT instead of the default"," --help display this help and exit"]},$={format:{short:"c",type:"string"}},x={name:"stat",async execute(e,a){if(g(e))return u(S);let s=d("stat",e,$);if(!s.ok)return s.error;let n=s.result.flags.format??null,c=s.result.positional;if(c.length===0)return{stdout:"",stderr:`stat: missing operand
|
|
3
|
+
`,exitCode:1};let o="",p="",f=!1;for(let i of c){let h=a.fs.resolvePath(a.cwd,i);try{let r=await a.fs.stat(h);if(n){let t=n,l=r.mode.toString(8),y=m(r.mode,r.isDirectory);t=t.replace(/%n/g,i),t=t.replace(/%N/g,`'${i}'`),t=t.replace(/%s/g,String(r.size)),t=t.replace(/%F/g,r.isDirectory?"directory":"regular file"),t=t.replace(/%a/g,l),t=t.replace(/%A/g,y),t=t.replace(/%u/g,"1000"),t=t.replace(/%U/g,"user"),t=t.replace(/%g/g,"1000"),t=t.replace(/%G/g,"group"),o+=`${t}
|
|
4
|
+
`}else{let t=r.mode.toString(8).padStart(4,"0"),l=m(r.mode,r.isDirectory);o+=` File: ${i}
|
|
5
|
+
`,o+=` Size: ${r.size} Blocks: ${Math.ceil(r.size/512)}
|
|
6
|
+
`,o+=`Access: (${t}/${l})
|
|
7
|
+
`,o+=`Modify: ${r.mtime.toISOString()}
|
|
8
|
+
`}}catch{p+=`stat: cannot stat '${i}': No such file or directory
|
|
9
|
+
`,f=!0}}return{stdout:o,stderr:p,exitCode:f?1:0}}};function m(e,a){let s=a?"d":"-",n=[e&256?"r":"-",e&128?"w":"-",e&64?"x":"-",e&32?"r":"-",e&16?"w":"-",e&8?"x":"-",e&4?"r":"-",e&2?"w":"-",e&1?"x":"-"];return s+n.join("")}export{x as statCommand};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a,b as n,d as l}from"./chunk-J7BCMQDI.js";import{a as i,b as s}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var h={name:"tail",summary:"output the last part of files",usage:"tail [OPTION]... [FILE]...",options:["-c, --bytes=NUM print the last NUM bytes","-n, --lines=NUM print the last NUM lines (default 10)","-n +NUM print starting from line NUM","-q, --quiet never print headers giving file names","-v, --verbose always print headers giving file names"," --help display this help and exit"]},c={name:"tail",async execute(t,r){if(s(t))return i(h);let e=a(t,"tail");if(!e.ok)return e.error;let{lines:o,bytes:p,fromLine:m}=e.options;return n(r,e.options,"tail",f=>l(f,o,p,m??!1))}};export{c as tailCommand};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as d}from"./chunk-TA7RUHGQ.js";import{a as p,b as l}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var h={name:"tee",summary:"read from stdin and write to stdout and files",usage:"tee [OPTION]... [FILE]...",options:["-a, --append append to the given FILEs, do not overwrite"," --help display this help and exit"]},m={append:{short:"a",long:"append",type:"boolean"}},g={name:"tee",async execute(r,e){if(l(r))return p(h);let t=d("tee",r,m);if(!t.ok)return t.error;let{append:f}=t.result.flags,c=t.result.positional,o=e.stdin,n="",a=0;for(let i of c)try{let s=e.fs.resolvePath(e.cwd,i);f?await e.fs.appendFile(s,o):await e.fs.writeFile(s,o)}catch{n+=`tee: ${i}: No such file or directory
|
|
3
|
+
`,a=1}return{stdout:o,stderr:n,exitCode:a}}};export{g as teeCommand};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as f,b as c,c as u}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var x={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
|
|
3
|
+
|
|
4
|
+
DURATION is a number with optional suffix:
|
|
5
|
+
s - seconds (default)
|
|
6
|
+
m - minutes
|
|
7
|
+
h - hours
|
|
8
|
+
d - days`,options:["-k, --kill-after=DURATION send KILL signal after DURATION if still running","-s, --signal=SIGNAL specify signal to send (default: TERM)"," --preserve-status exit with same status as COMMAND, even on timeout"," --foreground run command in foreground"," --help display this help and exit"]};function O(n){let r=n.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!r)return null;let i=parseFloat(r[1]);switch(r[2]||"s"){case"s":return i*1e3;case"m":return i*60*1e3;case"h":return i*60*60*1e3;case"d":return i*24*60*60*1e3;default:return null}}var N={name:"timeout",async execute(n,r){if(c(n))return f(x);let i=!1,s=0;for(let t=0;t<n.length;t++){let e=n[t];if(e==="--preserve-status")i=!0,s=t+1;else if(e==="--foreground")s=t+1;else if(e==="-k"||e==="--kill-after")t++,s=t+1;else if(e.startsWith("--kill-after="))s=t+1;else if(e==="-s"||e==="--signal")t++,s=t+1;else if(e.startsWith("--signal="))s=t+1;else{if(e.startsWith("--")&&e!=="--")return u("timeout",e);if(e.startsWith("-")&&e.length>1&&e!=="--")if(e.startsWith("-k"))s=t+1;else if(e.startsWith("-s"))s=t+1;else return u("timeout",e);else{s=t;break}}}let o=n.slice(s);if(o.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
9
|
+
`,exitCode:1};let a=o[0],l=O(a);if(l===null)return{stdout:"",stderr:`timeout: invalid time interval '${a}'
|
|
10
|
+
`,exitCode:1};let m=o.slice(1);if(m.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
11
|
+
`,exitCode:1};if(!r.exec)return{stdout:"",stderr:`timeout: exec not available
|
|
12
|
+
`,exitCode:1};let h=m.map(t=>t.includes(" ")||t.includes(" ")?`'${t.replace(/'/g,"'\\''")}'`:t).join(" "),p=new Promise(t=>{setTimeout(()=>t({timedOut:!0}),l)}),g=r.exec(h).then(t=>({timedOut:!1,result:t})),d=await Promise.race([p,g]);return d.timedOut?{stdout:"",stderr:"",exitCode:124}:d.result}};export{N as timeoutCommand};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as f}from"./chunk-4VDEBYW7.js";import{c as r}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var l={name:"touch",async execute(u,e){let s=[];for(let t of u){if(t.startsWith("--"))return r("touch",t);if(t.startsWith("-")&&t.length>1)return r("touch",t);s.push(t)}if(s.length===0)return{stdout:"",stderr:`touch: missing file operand
|
|
3
|
+
`,exitCode:1};let n="",i=0;for(let t of s)try{let o=e.fs.resolvePath(e.cwd,t);await e.fs.exists(o)||await e.fs.writeFile(o,"")}catch(o){n+=`touch: cannot touch '${t}': ${f(o)}
|
|
4
|
+
`,i=1}return{stdout:"",stderr:n,exitCode:i}}};export{l as touchCommand};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as C}from"./chunk-TA7RUHGQ.js";import{a as g,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var x={name:"tr",summary:"translate or delete characters",usage:"tr [OPTION]... SET1 [SET2]",options:["-c, -C, --complement use the complement of SET1","-d, --delete delete characters in SET1","-s, --squeeze-repeats squeeze repeated characters"," --help display this help and exit"],description:`SET syntax:
|
|
3
|
+
a-z character range
|
|
4
|
+
[:alnum:] all letters and digits
|
|
5
|
+
[:alpha:] all letters
|
|
6
|
+
[:digit:] all digits
|
|
7
|
+
[:lower:] all lowercase letters
|
|
8
|
+
[:upper:] all uppercase letters
|
|
9
|
+
[:space:] all whitespace
|
|
10
|
+
[:blank:] horizontal whitespace
|
|
11
|
+
[:punct:] all punctuation
|
|
12
|
+
[:print:] all printable characters
|
|
13
|
+
[:graph:] all printable characters except space
|
|
14
|
+
[:cntrl:] all control characters
|
|
15
|
+
[:xdigit:] all hexadecimal digits
|
|
16
|
+
\\n, \\t, \\r escape sequences`},b={"[:alnum:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","[:alpha:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz","[:blank:]":" ","[:cntrl:]":Array.from({length:32},(r,n)=>String.fromCharCode(n)).join("").concat("\x7F"),"[:digit:]":"0123456789","[:graph:]":Array.from({length:94},(r,n)=>String.fromCharCode(33+n)).join(""),"[:lower:]":"abcdefghijklmnopqrstuvwxyz","[:print:]":Array.from({length:95},(r,n)=>String.fromCharCode(32+n)).join(""),"[:punct:]":"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~","[:space:]":`
|
|
17
|
+
\r\f\v`,"[:upper:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","[:xdigit:]":"0123456789ABCDEFabcdef"};function S(r){let n="",e=0;for(;e<r.length;){if(r[e]==="["&&r[e+1]===":"){let l=!1;for(let[i,a]of Object.entries(b))if(r.slice(e).startsWith(i)){n+=a,e+=i.length,l=!0;break}if(l)continue}if(r[e]==="\\"&&e+1<r.length){let l=r[e+1];l==="n"?n+=`
|
|
18
|
+
`:l==="t"?n+=" ":l==="r"?n+="\r":n+=l,e+=2;continue}if(e+2<r.length&&r[e+1]==="-"){let l=r.charCodeAt(e),i=r.charCodeAt(e+2);for(let a=l;a<=i;a++)n+=String.fromCharCode(a);e+=3;continue}n+=r[e],e++}return n}var y={complement:{short:"c",long:"complement",type:"boolean"},complementUpper:{short:"C",type:"boolean"},delete:{short:"d",long:"delete",type:"boolean"},squeeze:{short:"s",long:"squeeze-repeats",type:"boolean"}},q={name:"tr",async execute(r,n){if(m(r))return g(x);let e=C("tr",r,y);if(!e.ok)return e.error;let l=e.result.flags.complement||e.result.flags.complementUpper,i=e.result.flags.delete,a=e.result.flags.squeeze,p=e.result.positional;if(p.length<1)return{stdout:"",stderr:`tr: missing operand
|
|
19
|
+
`,exitCode:1};if(!i&&!a&&p.length<2)return{stdout:"",stderr:`tr: missing operand after SET1
|
|
20
|
+
`,exitCode:1};let f=S(p[0]),s=p.length>1?S(p[1]):"",d=n.stdin,u=o=>{let t=f.includes(o);return l?!t:t},c="";if(i)for(let o of d)u(o)||(c+=o);else if(a&&p.length===1){let o="";for(let t of d)u(t)&&t===o||(c+=t,o=t)}else{if(l){let o=s.length>0?s[s.length-1]:"";for(let t of d)f.includes(t)?c+=t:c+=o}else{let o=new Map;for(let t=0;t<f.length;t++){let h=t<s.length?s[t]:s[s.length-1];o.set(f[t],h)}for(let t of d)c+=o.get(t)??t}if(a){let o="",t="";for(let h of c)s.includes(h)&&h===t||(o+=h,t=h);c=o}}return{stdout:c,stderr:"",exitCode:0}}};export{q as trCommand};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as P}from"./chunk-TA7RUHGQ.js";import{a as $,b as w}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var g={name:"tree",summary:"list contents of directories in a tree-like format",usage:"tree [OPTION]... [DIRECTORY]...",options:["-a include hidden files","-d list directories only","-L LEVEL limit depth of directory tree","-f print full path prefix for each file"," --help display this help and exit"]},O={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},N={name:"tree",async execute(s,o){if(w(s))return $(g);let e=P("tree",s,O);if(!e.ok)return e.error;let u={showHidden:e.result.flags.showHidden,directoriesOnly:e.result.flags.directoriesOnly,maxDepth:e.result.flags.maxDepth??null,fullPath:e.result.flags.fullPath},a=e.result.positional;a.length===0&&a.push(".");let t="",c="",l=0,r=0;for(let i of a){let n=await b(o,i,u,"",0);t+=n.output,c+=n.stderr,l+=n.dirCount,r+=n.fileCount}return t+=`
|
|
3
|
+
${l} director${l===1?"y":"ies"}`,u.directoriesOnly||(t+=`, ${r} file${r===1?"":"s"}`),t+=`
|
|
4
|
+
`,{stdout:t,stderr:c,exitCode:c?1:0}}};async function b(s,o,e,u,a){let t={output:"",stderr:"",dirCount:0,fileCount:0},c=s.fs.resolvePath(s.cwd,o);try{if(!(await s.fs.stat(c)).isDirectory)return t.output=`${o}
|
|
5
|
+
`,t.fileCount=1,t}catch{return t.stderr=`tree: ${o}: No such file or directory
|
|
6
|
+
`,t}if(t.output=`${o}
|
|
7
|
+
`,e.maxDepth!==null&&a>=e.maxDepth)return t;try{let r=(await s.fs.readdir(c)).filter(i=>!(!e.showHidden&&i.startsWith(".")));r.sort();for(let i=0;i<r.length;i++){let n=r[i],f=c==="/"?`/${n}`:`${c}/${n}`,h=i===r.length-1,y=h?"`-- ":"|-- ",p=u+(h?" ":"| ");try{if((await s.fs.stat(f)).isDirectory){t.dirCount++;let d=e.fullPath?f:n;if(t.output+=`${u+y+d}
|
|
8
|
+
`,e.maxDepth===null||a+1<e.maxDepth){let C=await D(s,f,e,p,a+1);t.output+=C.output,t.dirCount+=C.dirCount,t.fileCount+=C.fileCount}}else if(!e.directoriesOnly){t.fileCount++;let d=e.fullPath?f:n;t.output+=`${u+y+d}
|
|
9
|
+
`}}catch{}}}catch{t.stderr=`tree: ${o}: Permission denied
|
|
10
|
+
`}return t}async function D(s,o,e,u,a){let t={output:"",stderr:"",dirCount:0,fileCount:0};if(e.maxDepth!==null&&a>=e.maxDepth)return t;try{let l=(await s.fs.readdir(o)).filter(r=>!(!e.showHidden&&r.startsWith(".")));l.sort();for(let r=0;r<l.length;r++){let i=l[r],n=o==="/"?`/${i}`:`${o}/${i}`,f=r===l.length-1,h=f?"`-- ":"|-- ",y=u+(f?" ":"| ");try{if((await s.fs.stat(n)).isDirectory){t.dirCount++;let m=e.fullPath?n:i;t.output+=`${u+h+m}
|
|
11
|
+
`;let d=await D(s,n,e,y,a+1);t.output+=d.output,t.dirCount+=d.dirCount,t.fileCount+=d.fileCount}else if(!e.directoriesOnly){t.fileCount++;let m=e.fullPath?n:i;t.output+=`${u+h+m}
|
|
12
|
+
`}}catch{}}}catch{}return t}export{N as treeCommand};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as g}from"./chunk-J7MJV6WO.js";import{a as f}from"./chunk-TA7RUHGQ.js";import{a as p,b as d}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var b={name:"uniq",summary:"report or omit repeated lines",usage:"uniq [OPTION]... [INPUT [OUTPUT]]",options:["-c, --count prefix lines by the number of occurrences","-d, --repeated only print duplicate lines","-i, --ignore-case ignore case when comparing","-u, --unique only print unique lines"," --help display this help and exit"]},w={count:{short:"c",long:"count",type:"boolean"},duplicatesOnly:{short:"d",long:"repeated",type:"boolean"},uniqueOnly:{short:"u",long:"unique",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},P={name:"uniq",async execute(a,m){if(d(a))return p(b);let o=f("uniq",a,w);if(!o.ok)return o.error;let{count:h,duplicatesOnly:y,uniqueOnly:q,ignoreCase:C}=o.result.flags,O=o.result.positional,u=await g(m,O,{cmdName:"uniq"});if(!u.ok)return u.error;let n=u.content.split(`
|
|
3
|
+
`);if(n.length>0&&n[n.length-1]===""&&n.pop(),n.length===0)return{stdout:"",stderr:"",exitCode:0};let t=[],r=n[0],i=1,x=(e,s)=>C?e.toLowerCase()===s.toLowerCase():e===s;for(let e=1;e<n.length;e++)x(n[e],r)?i++:(t.push({line:r,count:i}),r=n[e],i=1);t.push({line:r,count:i});let l=t;y?l=t.filter(e=>e.count>1):q&&(l=t.filter(e=>e.count===1));let c="";for(let{line:e,count:s}of l)h?c+=`${String(s).padStart(4)} ${e}
|
|
4
|
+
`:c+=`${e}
|
|
5
|
+
`;return{stdout:c,stderr:"",exitCode:0}}};export{P as uniqCommand};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as y}from"./chunk-J7MJV6WO.js";import{a as g}from"./chunk-TA7RUHGQ.js";import{a as w,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var C={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes print the byte counts","-m, --chars print the character counts","-l, --lines print the newline counts","-w, --words print the word counts"," --help display this help and exit"]},S={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},L={name:"wc",async execute(n,l){if(m(n))return w(C);let r=g("wc",n,S);if(!r.ok)return r.error;let{lines:s,words:t}=r.result.flags,e=r.result.flags.bytes||r.result.flags.chars,o=r.result.positional;!s&&!t&&!e&&(s=t=e=!0);let i=await y(l,o,{cmdName:"wc",stopOnError:!1});if(o.length===0){let f=b(i.files[0].content);return{stdout:`${h(f,s,t,e,"")}
|
|
3
|
+
`,stderr:"",exitCode:0}}let c="",u=0,d=0,p=0;for(let{filename:f,content:x}of i.files){let a=b(x);u+=a.lines,d+=a.words,p+=a.chars,c+=`${h(a,s,t,e,f)}
|
|
4
|
+
`}return o.length>1&&(c+=`${h({lines:u,words:d,chars:p},s,t,e,"total")}
|
|
5
|
+
`),{stdout:c,stderr:i.stderr,exitCode:i.exitCode}}};function b(n){let l=n.length,r=0,s=0,t=!1;for(let e=0;e<l;e++){let o=n[e];o===`
|
|
6
|
+
`?(r++,t&&(s++,t=!1)):o===" "||o===" "||o==="\r"?t&&(s++,t=!1):t=!0}return t&&s++,{lines:r,words:s,chars:l}}function h(n,l,r,s,t){let e=[];l&&e.push(String(n.lines)),r&&e.push(String(n.words)),s&&e.push(String(n.chars));let o=e.join(" ");return t&&(o+=` ${t}`),o}export{L as wcCommand};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as u}from"./chunk-TA7RUHGQ.js";import{a as f,b as h}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var w={name:"which",summary:"locate a command",usage:"which [-as] program ...",options:["-a List all instances of executables found","-s No output, just return 0 if found, 1 if not","--help display this help and exit"]},g={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},A={name:"which",async execute(s,e){if(h(s))return f(w);let t=u("which",s,g);if(!t.ok)return t.error;let c=t.result.flags.showAll,p=t.result.flags.silent,o=t.result.positional;if(o.length===0)return{stdout:"",stderr:"",exitCode:1};let d=(e.env.PATH||"/bin:/usr/bin").split(":"),n="",r=!0;for(let m of o){let a=!1;for(let i of d){if(!i)continue;let l=`${i}/${m}`;if(await e.fs.exists(l)&&(a=!0,p||(n+=`${l}
|
|
3
|
+
`),!c))break}a||(r=!1)}return{stdout:n,stderr:"",exitCode:r?0:1}}};export{A as whichCommand};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as w,b as A,c as I}from"./chunk-GTNBSMZR.js";import"./chunk-5KNEBKYN.js";var N={name:"xargs",summary:"build and execute command lines from standard input",usage:"xargs [OPTION]... [COMMAND [INITIAL-ARGS]]",options:["-I REPLACE replace occurrences of REPLACE with input","-n NUM use at most NUM arguments per command line","-P NUM run at most NUM processes at a time","-0, --null items are separated by null, not whitespace","-t, --verbose print commands before executing","-r, --no-run-if-empty do not run command if input is empty"," --help display this help and exit"]},E={name:"xargs",async execute(n,p){if(A(n))return w(N);let h=null,u=null,l=null,x=!1,g=!1,C=!1,r=0;for(let t=0;t<n.length;t++){let e=n[t];if(e==="-I"&&t+1<n.length)h=n[++t],r=t+1;else if(e==="-n"&&t+1<n.length)u=parseInt(n[++t],10),r=t+1;else if(e==="-P"&&t+1<n.length)l=parseInt(n[++t],10),r=t+1;else if(e==="-0"||e==="--null")x=!0,r=t+1;else if(e==="-t"||e==="--verbose")g=!0,r=t+1;else if(e==="-r"||e==="--no-run-if-empty")C=!0,r=t+1;else{if(e.startsWith("--"))return I("xargs",e);if(e.startsWith("-")&&e.length>1){for(let m of e.slice(1))if(!"0trnIP".includes(m))return I("xargs",`-${m}`);e.includes("0")&&(x=!0),e.includes("t")&&(g=!0),e.includes("r")&&(C=!0),r=t+1}else if(!e.startsWith("-")){r=t;break}}}let o=n.slice(r);o.length===0&&o.push("echo");let P=x?"\0":/\s+/,i=p.stdin.split(P).map(t=>t.trim()).filter(t=>t.length>0);if(i.length===0)return C?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let c="",a="",d=0,y=async t=>{let e=t.join(" ");return g&&(a+=`${e}
|
|
3
|
+
`),p.exec?p.exec(e):{stdout:`${e}
|
|
4
|
+
`,stderr:"",exitCode:0}},b=async t=>{if(l!==null&&l>1)for(let e=0;e<t.length;e+=l){let s=t.slice(e,e+l),m=await Promise.all(s.map(y));for(let f of m)c+=f.stdout,a+=f.stderr,f.exitCode!==0&&(d=f.exitCode)}else for(let e of t){let s=await y(e);c+=s.stdout,a+=s.stderr,s.exitCode!==0&&(d=s.exitCode)}};if(h!==null){let t=i.map(e=>o.map(s=>s.replaceAll(h,e)));await b(t)}else if(u!==null){let t=[];for(let e=0;e<i.length;e+=u){let s=i.slice(e,e+u);t.push([...o,...s])}await b(t)}else{let t=[...o,...i],e=await y(t);c+=e.stdout,a+=e.stderr,d=e.exitCode}return{stdout:c,stderr:a,exitCode:d}}};export{E as xargsCommand};
|