This commit is contained in:
Raven Scott
2026-04-03 04:01:24 -04:00
parent 8505077f8d
commit 98259a7b4a
23 changed files with 2371 additions and 66 deletions
+13 -8
View File
@@ -136,7 +136,8 @@ async function run(ctx, argv) {
patterns.push(s)
}
} catch (e) {
if (!suppressErrors) ctx.console.error('grep: ' + pf + ': ' + (e.message || e))
if (!suppressErrors)
ctx.console.error('grep: ' + pf + ': ' + (e.message || e))
ctx.exitCode = 2
return
}
@@ -181,13 +182,15 @@ async function run(ctx, argv) {
try {
const buf = await vfs.readFile(path)
if (!buf) {
if (!suppressErrors) ctx.console.error('grep: ' + path + ': No such file')
if (!suppressErrors)
ctx.console.error('grep: ' + path + ': No such file')
fatal = true
continue
}
text = ctx.b4a.toString(buf)
} catch (e) {
if (!suppressErrors) ctx.console.error('grep: ' + path + ': ' + (e.message || e))
if (!suppressErrors)
ctx.console.error('grep: ' + path + ': ' + (e.message || e))
fatal = true
continue
}
@@ -249,9 +252,12 @@ async function run(ctx, argv) {
function buildMatchers(patterns, o) {
if (patterns.length === 0) throw new Error('no pattern')
if (o.fixed) {
const pats = o.icase ? patterns.map((p) => p.toLowerCase()) : patterns.slice()
return pats.map((p) => (line) =>
o.icase ? line.toLowerCase().includes(p) : line.includes(p)
const pats = o.icase
? patterns.map((p) => p.toLowerCase())
: patterns.slice()
return pats.map(
(p) => (line) =>
o.icase ? line.toLowerCase().includes(p) : line.includes(p)
)
}
const flags = o.icase ? 'i' : ''
@@ -283,8 +289,7 @@ function stripCr(line) {
* @param {boolean} multiFile
*/
function namePrefixForCount(showName, label, useStdin, multiFile) {
const need =
multiFile || (showName && (label != null || useStdin))
const need = multiFile || (showName && (label != null || useStdin))
if (!need) return ''
if (label != null) return label + ':'
return '(standard input):'
+1 -1
View File
@@ -5,7 +5,7 @@ function bareStdin(ctx) {
async function run(ctx, argv) {
ctx.console.log(
'Bare OS — default user: guest | builtins: cd, export, exit, login, logout | /bin: basename cat clear crontab date dirname echo env exit false grep head hdms help hostname id login logout ls nl pathchk printenv pwd rm savevault seq sleep sort tail test touch true tty uname wc which whoami'
'Bare OS — default user: guest | builtins: alias, cd, export, exit, login, logout, unalias | /bin: basename cat clear crontab date dirname echo env exit false git grep head hdms help hostname id login logout ls nl pathchk printenv pwd rm savevault seq sleep sort tail test touch true tty uname wc which whoami'
)
ctx.console.log(
'Identity: login [--new] <passphrase> | logout [--save] | savevault (encrypt copy of personal drive under /.bare/vault/)'
+32 -2
View File
@@ -3,7 +3,14 @@ function bareStdin(ctx) {
return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : ''
}
/**
* rm — remove files or directories.
* Flags: -r -R --recursive, -f --force, -- ; bundled e.g. -rf
*/
async function run(ctx, argv) {
const vfs = ctx.vfs
let recursive = false
let force = false
const files = []
let dash = false
for (let i = 1; i < argv.length; i++) {
@@ -16,7 +23,22 @@ async function run(ctx, argv) {
dash = true
continue
}
if (a.startsWith('-')) continue
if (a === '--recursive' || a === '-r' || a === '-R') {
recursive = true
continue
}
if (a === '--force' || a === '-f') {
force = true
continue
}
if (a.startsWith('-') && a.length > 1) {
for (let j = 1; j < a.length; j++) {
const c = a[j]
if (c === 'r' || c === 'R') recursive = true
else if (c === 'f') force = true
}
continue
}
files.push(a)
}
if (!files.length) {
@@ -24,10 +46,18 @@ async function run(ctx, argv) {
ctx.exitCode = 1
return
}
const doRm =
vfs && typeof vfs.rm === 'function'
? (p) => vfs.rm(p, { recursive, force })
: async (p) => {
if (recursive) throw new Error('recursive rm not supported')
return vfs.unlink(p)
}
for (const f of files) {
try {
await ctx.vfs.unlink(f)
await doRm(f)
} catch (e) {
if (force) continue
ctx.console.error('rm: ' + f + ': ' + (e.message || e))
ctx.exitCode = 1
}