Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls behavior with glob patterns is surprising #12641

Open
YizhePKU opened this issue Apr 24, 2024 · 4 comments
Open

ls behavior with glob patterns is surprising #12641

YizhePKU opened this issue Apr 24, 2024 · 4 comments
Labels
file-system Related to commands and core nushell behavior around the file system glob-expansion Specific behavior around file-system globbing with regular commands or `glob`

Comments

@YizhePKU
Copy link
Contributor

YizhePKU commented Apr 24, 2024

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.

@fdncred
Copy link
Collaborator

fdncred commented Apr 24, 2024

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?

@WindSoilder
Copy link
Collaborator

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

@umnikos
Copy link

umnikos commented Apr 27, 2024

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

@YizhePKU
Copy link
Contributor Author

Issue #12046 also has relavent discussion.

@sholderbach sholderbach added file-system Related to commands and core nushell behavior around the file system glob-expansion Specific behavior around file-system globbing with regular commands or `glob` labels May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
file-system Related to commands and core nushell behavior around the file system glob-expansion Specific behavior around file-system globbing with regular commands or `glob`
Projects
None yet
Development

No branches or pull requests

5 participants