async function run(ctx, argv) { let wantDir = false /** @type {string | null} */ let template = null for (let i = 1; i < argv.length; i++) { const a = argv[i] if (a === '-d') wantDir = true else if (!a.startsWith('-')) template = a } const rnd = () => Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 6) const sixX = 'X'.repeat(6) let rel = template || `tmp.${sixX}` if (rel.includes(sixX)) rel = rel.replace(new RegExp(sixX, 'g'), rnd()) else rel = `${rel.replace(/\/+$/, '')}.${rnd()}` const full = rel.startsWith('/') ? rel : `/tmp/${rel.replace(/^\/+/, '')}` try { if (wantDir) await ctx.vfs.mkdir(full, { recursive: false }) else await ctx.vfs.writeFile(full, ctx.b4a.from('')) ctx.console.log(full) ctx.exitCode = 0 } catch (e) { ctx.console.error('mktemp: ' + ((e && e.message) || e)) ctx.exitCode = 1 } }