23 lines
657 B
Plaintext
23 lines
657 B
Plaintext
/** Shared helpers for drive-resident /bin scripts (prepended before each command). */
|
|
function bareStdin(ctx) {
|
|
return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : ''
|
|
}
|
|
|
|
async function run(ctx, argv) {
|
|
const files = argv.slice(1).filter((a) => !a.startsWith('-'))
|
|
if (!files.length) {
|
|
ctx.console.error('touch: missing file operand')
|
|
ctx.exitCode = 1
|
|
return
|
|
}
|
|
for (const f of files) {
|
|
try {
|
|
const existing = await ctx.vfs.readFile(f)
|
|
await ctx.vfs.writeFile(f, existing || ctx.b4a.from(''))
|
|
} catch (e) {
|
|
ctx.console.error('touch: ' + f + ': ' + (e.message || e))
|
|
ctx.exitCode = 1
|
|
}
|
|
}
|
|
}
|