@@ -0,0 +1,19 @@
|
||||
/** 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('dirname: missing operand')
|
||||
return
|
||||
}
|
||||
for (const path of parts) {
|
||||
const cleaned = path.replace(/\/+$/, '') || '/'
|
||||
const i = cleaned.lastIndexOf('/')
|
||||
const out =
|
||||
i <= 0 ? (cleaned[0] === '/' ? '/' : '.') : cleaned.slice(0, i) || '/'
|
||||
ctx.console.log(out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user