Updates
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user