This commit is contained in:
Raven Scott
2026-04-26 15:49:55 -04:00
parent 4cdd1569af
commit 2dc388ffd0
26 changed files with 473 additions and 38 deletions
+23 -2
View File
@@ -64,10 +64,31 @@ async function run(ctx, argv) {
text = nl === -1 ? '' : text.slice(nl + 1)
}
const lines = text.split(/\r?\n/)
const blocks = []
let cur = ''
let depth = 0
for (let i = 0; i < lines.length; i++) {
const trimmed = lines[i].trim()
const raw = lines[i]
const trimmed = raw.trim()
if (!trimmed || trimmed.startsWith('#')) continue
await ctx.execLine(trimmed)
cur += (cur ? '\n' : '') + raw
const words = trimmed
.replace(/[;(){}]/g, ' ')
.split(/\s+/)
.filter(Boolean)
for (const w of words) {
if (w === 'if' || w === 'for' || w === 'while' || w === 'until' || w === 'case')
depth++
else if (w === 'fi' || w === 'done' || w === 'esac') depth = Math.max(0, depth - 1)
}
if (depth === 0) {
blocks.push(cur)
cur = ''
}
}
if (cur.trim()) blocks.push(cur)
for (const block of blocks) {
await ctx.execLine(block)
if ((Number(ctx.exitCode) || 0) !== 0) return
}
ctx.exitCode = 0