Close the BareOS shell + Fish REPL roadmap tracker and ship the remaining
shell surfaces in-tree. Roadmap / CI - docs/data/shell-roadmap-features.json: all shell-001…shell-100 rows and P1–P8 phases marked implemented; note documents closure date and pointers. - scripts/verify-shell-roadmap.mjs: validate JSON (schema 1, 8 phases, 100 implemented items) plus existing source needles; wire npm run verify:shell-roadmap into root pretest (package.json). - scripts/README.md: document verifier behavior. Lexer & expansion (packages/bare-os-booter/lib) - shell-lex.js: central lexShellLine; ANSI-C $'…' via decodeBareOsDollarQuote; keep diagnostics/tokenizer aligned with execution tokenizer. - shell.js: stray reserved words at statement start → syntax error exit 2; optional [[ … ]] when BARE_OS_SHELL_DOUBLE_BRACKET=1 (==, !=); alias expansion before function dispatch (ordering tests); expandWordWithCmdSubst: balanced $(…) vs skipped $((…)); backtick command substitution when BARE_OS_SHELL_CMDSUBST; default ctx.execLine for nested cmdsubst when unset; index passthrough for DOUBLE_BRACKET env. - shell-glob.js: ~login → HOME when USER matches, else /home/login (bounded login pattern); tests for pathname + execShellLine. - shell-tokenizer.js: align with shell-lex detailed spans/modes where needed. Completion / REPL - completion-engine.js: completion depth / collectors per shell program work. - packages/bare-os-booter/index.js: small wiring for shell env passthrough. /bin/sh front-end - packages/bare-os-coreutils/src/sh.js; kernel/bin/sh; seeder copies: stay in sync with shell behavior and env flags. Tests - packages/bare-os-booter/test.js: coverage for misplaced reserved words, gated [[ ]], alias vs function, ~user/~~ paths, $'…', cmdsubst $(…) and backticks, and related regressions. Documentation - docs/reference/shell-grammar.md: $'…', $(…) / backticks vs $((…)). - handbook/09-posix-utilities-shell-and-vfs.md, environment appendix, shell-troubleshooting / shell-unsupported-behavior, release checklist, docs/reference/README.md: shell behavior and operator surfaces. - developer-guide/19-how-to-fish-keybinding-completer.md: Fish keybinding / completer how-to (new). Generated / synced artifacts - kernel/lib/bare/manifest.json, kernel/share/man/man.json, kernel/lib/bare/shell-completion.json, posix_utilities.json, docs/audit/bundle-health.json: regenerated or synced with tooling. - scripts/bench-shell-phases.mjs: bench script touch.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
async function run(ctx, argv) {
|
||||
const mode = argv[1]
|
||||
if (mode == null) {
|
||||
ctx.console.error('usage: sh -c COMMAND [NAME [ARG ...]] | sh SCRIPT')
|
||||
if (argv.length < 2) {
|
||||
ctx.console.error('usage: sh [-eu] [-s | -c COMMAND | SCRIPT]')
|
||||
ctx.exitCode = 2
|
||||
return
|
||||
}
|
||||
@@ -10,8 +9,39 @@ async function run(ctx, argv) {
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
const vfsEnv =
|
||||
ctx.vfs?.env && typeof ctx.vfs.env === 'object' ? ctx.vfs.env : null
|
||||
let i = 1
|
||||
let sawFlags = false
|
||||
while (i < argv.length) {
|
||||
const a = argv[i]
|
||||
if (a === '--') {
|
||||
i++
|
||||
break
|
||||
}
|
||||
if (a === '-' || !a.startsWith('-')) break
|
||||
if (a === '-c' || a === '-s') break
|
||||
sawFlags = true
|
||||
for (const ch of a.slice(1)) {
|
||||
if (ch === 'e' && vfsEnv) vfsEnv.BARE_OS_SHELL_ERREXIT = '1'
|
||||
else if (ch === 'u' && vfsEnv) vfsEnv.BARE_OS_SHELL_NOUNSET = '1'
|
||||
else if (ch === 'v' && vfsEnv) vfsEnv.BARE_OS_SHELL_XTRACE = '1'
|
||||
else if (ch === 'x' && vfsEnv) vfsEnv.BARE_OS_SHELL_XTRACE = '1'
|
||||
else if (ch === 'C' && vfsEnv) vfsEnv.BARE_OS_SHELL_NOCLOBBER = '1'
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
const mode = argv[i]
|
||||
if (mode == null && !sawFlags) {
|
||||
ctx.console.error('usage: sh [-eu] [-s | -c COMMAND | SCRIPT]')
|
||||
ctx.exitCode = 2
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === '-c') {
|
||||
const command = argv[2]
|
||||
const command = argv[i + 1]
|
||||
if (command == null) {
|
||||
ctx.console.error('sh: option requires an argument -- c')
|
||||
ctx.console.error('usage: sh -c COMMAND [NAME [ARG ...]] | sh SCRIPT')
|
||||
@@ -25,9 +55,9 @@ async function run(ctx, argv) {
|
||||
for (const k of ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '#']) {
|
||||
saved[k] = env[k]
|
||||
}
|
||||
env['0'] = argv[3] ?? 'sh'
|
||||
const args = argv.slice(4)
|
||||
for (let i = 1; i <= 9; i++) env[String(i)] = args[i - 1] ?? ''
|
||||
env['0'] = argv[i + 3] ?? 'sh'
|
||||
const args = argv.slice(i + 4)
|
||||
for (let j = 1; j <= 9; j++) env[String(j)] = args[j - 1] ?? ''
|
||||
env['#'] = String(args.length)
|
||||
}
|
||||
try {
|
||||
@@ -42,6 +72,20 @@ async function run(ctx, argv) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === '-s') {
|
||||
const stdinText =
|
||||
typeof ctx.shellStdin === 'string'
|
||||
? ctx.shellStdin
|
||||
: typeof ctx.shellStdin === 'object' &&
|
||||
ctx.shellStdin &&
|
||||
'data' in ctx.shellStdin
|
||||
? String(/** @type {{ data?: string }} */ (ctx.shellStdin).data ?? '')
|
||||
: ''
|
||||
await runShScriptText(ctx, stdinText, { label: 'stdin' })
|
||||
return
|
||||
}
|
||||
|
||||
const script = mode
|
||||
let buf
|
||||
try {
|
||||
@@ -63,6 +107,16 @@ async function run(ctx, argv) {
|
||||
const nl = text.indexOf('\n')
|
||||
text = nl === -1 ? '' : text.slice(nl + 1)
|
||||
}
|
||||
await runShScriptText(ctx, text, { label: script })
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown>} ctx
|
||||
* @param {string} text
|
||||
* @param {{ label: string }} meta
|
||||
*/
|
||||
async function runShScriptText(ctx, text, meta) {
|
||||
text = String(text || '').replace(/\\\r?\n/g, '')
|
||||
const lines = text.split(/\r?\n/)
|
||||
const blocks = []
|
||||
let cur = ''
|
||||
@@ -87,8 +141,15 @@ async function run(ctx, argv) {
|
||||
}
|
||||
}
|
||||
if (cur.trim()) blocks.push(cur)
|
||||
let lineNo = 1
|
||||
for (const block of blocks) {
|
||||
const env = ctx.vfs?.env
|
||||
if (env && typeof env === 'object') {
|
||||
env.BARE_OS_SH_SCRIPT_LABEL = meta.label
|
||||
env.BARE_OS_SH_SCRIPT_LINE = String(lineNo)
|
||||
}
|
||||
await ctx.execLine(block)
|
||||
lineNo += block.split(/\r?\n/).length
|
||||
if ((Number(ctx.exitCode) || 0) !== 0) return
|
||||
}
|
||||
ctx.exitCode = 0
|
||||
|
||||
Reference in New Issue
Block a user