Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Improve ls command
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed May 16, 2023
1 parent c5c575e commit 115e8e2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/puter-shell/coreutils/ls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// INCONST: called 'path' instead of 'path_' elsewhere
import path_ from "path-browserify";

export default {
name: 'ls',
args: {
Expand All @@ -18,8 +21,25 @@ export default {

const paths = positionals.length < 1
? [pwd] : positionals ;


// DRY: also done in mkdir, cat, and mv
const resolve = relPath => {
if ( relPath.startsWith('/') ) {
return relPath;
}
return path_.resolve(ctx.vars.pwd, relPath);
}

const showHeadings = paths.length > 1 ? async ({ i, path }) => {
if ( i !== 0 ) ctx.externs.out.write('\n');
await ctx.externs.out.write(path + ':\n');
} : () => {};

for ( const path of paths ) {
for ( let i=0 ; i < paths.length ; i++ ) {
let path = paths[i];
await showHeadings({ i, path });
path = resolve(path);
const result = await puterShell.command('list', { path });
for ( const item of result ) {
await ctx.externs.out.write(item.name + '\n');
Expand Down

0 comments on commit 115e8e2

Please sign in to comment.