@@ -0,0 +1,29 @@
|
||||
async function run(ctx, argv) {
|
||||
const vfs = ctx.vfs
|
||||
let n = 10
|
||||
let start = 1
|
||||
if (argv[1] === '-n' && argv[2]) {
|
||||
n = parseInt(argv[2], 10) || 10
|
||||
start = 3
|
||||
}
|
||||
const files = argv.slice(start).filter((a) => a !== '--')
|
||||
const take = (s) => {
|
||||
let lines = s.split('\n')
|
||||
if (s.endsWith('\n') && lines[lines.length - 1] === '') lines.pop()
|
||||
const slice = lines.length <= n ? lines : lines.slice(-n)
|
||||
ctx.console.log(slice.join('\n'))
|
||||
}
|
||||
if (!files.length) {
|
||||
take(bareStdin(ctx))
|
||||
return
|
||||
}
|
||||
for (const f of files) {
|
||||
const buf = await vfs.readFile(f)
|
||||
if (!buf) {
|
||||
ctx.console.error('tail: ' + f + ': No such file')
|
||||
continue
|
||||
}
|
||||
if (files.length > 1) ctx.console.log('==> ' + f + ' <==')
|
||||
take(ctx.b4a.toString(buf))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user