nushell icon indicating copy to clipboard operation
nushell copied to clipboard

`ls` behavior with glob patterns is surprising

Open yizhepku opened this issue 1 year ago • 4 comments

When given a glob pattern as argument, ls will behave in the exact same way as glob, listing the paths themselves instead of the content of any directories.

Suppose I have two directories, foo-1 and foo-2, both of which have a empty.txt in them. Compare:

> ls foo-1 foo-2                                                                                                                                          
╭───┬─────────────────┬──────┬──────┬──────────╮
│ # │      name       │ type │ size │ modified │
├───┼─────────────────┼──────┼──────┼──────────┤
│ 0 │ foo-1\empty.txt │ file │  0 B │ now      │
│ 1 │ foo-2\empty.txt │ file │  0 B │ now      │
╰───┴─────────────────┴──────┴──────┴──────────╯

> ls foo*                                                                                                                                                 
╭───┬───────┬──────┬──────┬──────────╮
│ # │ name  │ type │ size │ modified │
├───┼───────┼──────┼──────┼──────────┤
│ 0 │ foo-1 │ dir  │  0 B │ now      │
│ 1 │ foo-2 │ dir  │  0 B │ now      │
╰───┴───────┴──────┴──────┴──────────╯

This is surprising. I would expect the output of these two commands to be the same.

For reference, here's how ^ls works:

> ^ls foo-1 foo-2
foo-1:
empty.txt

foo-2:
empty.txt

> ^ls foo*
foo-1:
empty.txt

foo-2:
empty.txt

We can discuss whether it's better to group the output (like ^ls) or merge the output (like ls foo-1 foo-2), but I don't think it's right to list the directories themselves instead of their content.

yizhepku avatar Apr 24 '24 07:04 yizhepku

I originally thought that they should both work like ls foo* works now, but now I'm not sure what "right" is. Seems like if you wanted to list what was inside the folder you'd do ls foo*/*.

What do you think @WindSoilder?

fdncred avatar Apr 24 '24 11:04 fdncred

I have played with bash and fish, what they do for ls foo* is like:

  1. find all files which starts with foo
  2. then lists all these files, if it's a directory, then list files inside that directory.

So yeah it behaves like ls foo*/* in nushell

WindSoilder avatar Apr 24 '24 14:04 WindSoilder

This may be related to ls ** only recursively listing folders, requiring ls **/* to recursively list files

umnikos avatar Apr 27 '24 00:04 umnikos

Issue #12046 also has relavent discussion.

yizhepku avatar Apr 27 '24 01:04 yizhepku