Skip to content

Commit

Permalink
fix(plugins/plugin-bash-like): ls command does not pass some options …
Browse files Browse the repository at this point in the history
…to the VFS impl

Fixes #6969
  • Loading branch information
starpit committed Feb 5, 2021
1 parent 7ef4d8a commit a5eae35
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/plugin-bash-like/fs/src/lib/ls.ts
Expand Up @@ -67,7 +67,7 @@ function prettyTime(ms: number): string {
return dateFormatter(new Date(ms)).replace(/(\s)0/g, '$1 ')
}

interface LsOptions extends ParsedOptions {
interface TheLsOptions {
l: boolean // wide output
a: boolean // list with dots except for . and ..
A: boolean // list with dots
Expand All @@ -78,6 +78,8 @@ interface LsOptions extends ParsedOptions {
d: boolean // don't traverse directories
}

type LsOptions = TheLsOptions & ParsedOptions

/** sort by size */
const bySize = (rev: -1 | 1) => (a: GlobStats, b: GlobStats): number => {
return rev * (b.stats.size - a.stats.size)
Expand Down Expand Up @@ -236,6 +238,11 @@ function toTable(entries: GlobStats[], args: Arguments<LsOptions>): Table {
}
}

/** Format a dash option, if specified */
function opt(o: keyof TheLsOptions, opts: Arguments<LsOptions>) {
return opts.parsedOptions[o] ? ` -${o} ` : ''
}

/**
* ls command handler
*
Expand All @@ -257,7 +264,7 @@ const doLs = (cmd: string) => async (opts: Arguments<LsOptions>): Promise<MixedR
//
const srcs = opts.command.replace(/^\s*ls/, '').replace(/\s--?\S+/g, '')

const cmdline = 'vfs ls ' + (opts.parsedOptions.l || cmd === 'lls' ? '-l ' : '') + srcs
const cmdline = 'vfs ls ' + (opts.parsedOptions.l || cmd === 'lls' ? '-l ' : '') + opt('d', opts) + srcs

if (cmd === 'lls') {
opts.parsedOptions.l = true
Expand Down

0 comments on commit a5eae35

Please sign in to comment.