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: ignore leading period when sorting by name #2101

Closed
tertsdiepraam opened this issue Apr 21, 2021 · 6 comments
Closed

ls: ignore leading period when sorting by name #2101

tertsdiepraam opened this issue Apr 21, 2021 · 6 comments

Comments

@tertsdiepraam
Copy link
Member

The GNU ls ignores the leading period when sorting by name. However, hidden files still get sorted before non-hidden files with the same name, so .a always appears before a.

Here is an example:

$ touch a b .a .b
$ ls -A            # GNU
.a  a  .b  b
$ uu-ls -A         # current uutils
.a  .b  a  b

Code is here:
https://github.com/uutils/coreutils/blob/master/src/uu/ls/src/ls.rs

Tests are here:
https://github.com/uutils/coreutils/blob/master/tests/by-util/test_ls.rs

@ricardoaiglesias
Copy link
Contributor

Just verifying, all this would take is changing the sort_entries function's Sort::Size branch to split into two "buckets" (with dot and without dot), sort each bucket, and then join them, right?
If so, I can tackle this.

@tertsdiepraam
Copy link
Member Author

@ricardoaiglesias If I understand you correctly I think that would lead to our current sorting right? In the example above, this would lead to a bucket with .a .b and a bucket with a b and joining them then gives .a .b a b.

One way this might be implemented is to sort by a tuple of type (String, bool) representing (name_without_leading_period, has_leading_period).

@ricardoaiglesias
Copy link
Contributor

Oh sorry. I misinterpreted the examples you gave.
Yeah, you're correct. I can get something done.

@tertsdiepraam
Copy link
Member Author

Nice! Looking forward to it!

@ricardoaiglesias
Copy link
Contributor

PR Here: #2112

@ricardoaiglesias
Copy link
Contributor

This issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants