/** 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 parts = argv.slice(1).filter((a) => a !== '--') if (!parts.length) { ctx.console.error('basename: missing operand') return } const path = parts[0] const suffix = parts[1] || '' let base = path.replace(/\/+$/, '') const slash = base.lastIndexOf('/') base = slash === -1 ? base : base.slice(slash + 1) if (!base) base = path if (suffix && base.endsWith(suffix) && base.length > suffix.length) { base = base.slice(0, -suffix.length) } ctx.console.log(base) }