Skip to content

feat: don't consider "extensions" for directories when sorting #821

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

Open
sdht0 opened this issue Feb 5, 2024 · 8 comments · May be fixed by #1418
Open

feat: don't consider "extensions" for directories when sorting #821

sdht0 opened this issue Feb 5, 2024 · 8 comments · May be fixed by #1418

Comments

@sdht0
Copy link

sdht0 commented Feb 5, 2024

$ mkdir a b.m c.n d.m e ; touch f.txt g.png h.png

$ eza --group-directories-first                              
a  b.m  c.n  d.m  e  f.txt  g.png  h.png

$ eza --group-directories-first --sort=extension
a  e  b.m  d.m  c.n  g.png  h.png  f.txt

The directories are also being sorted by extension based on the dot in the names. even though directories don't have extensions.

@sdht0 sdht0 added the errors Something isn't working label Feb 5, 2024
@cafkafk cafkafk changed the title bug: don't consider "extensions" for directories when sorting feat: don't consider "extensions" for directories when sorting Feb 5, 2024
@cafkafk
Copy link
Member

cafkafk commented Feb 5, 2024

I don't think this technically classifies as a bug (as it is technically correct), but I'd love to see more input on whether this should be changed to reflect your desired behavior. Tentatively, I do agree that this should be changed, but I haven't thought much about it.

@cafkafk cafkafk removed the errors Something isn't working label Feb 5, 2024
@sdht0
Copy link
Author

sdht0 commented Feb 5, 2024

One way to think about it is that directories have an implicit .dir extension and thus any other . in the directory name should be ignored.

I've found the current behavior surprising. For instance, when listing the installed packages on NixOS, I'd expect the multiple eza versions to be listed together. However, the *-eza-0.17.3 and *-eza-0.18.0 directories are sorted with other packages based on .3 and .0, which is not what I want. On the other hand, all files sorted by their extensions is what I want.

Given xkcd 1172, maybe eza can offer a new --sort=fileextension (or equivalent) option?

I do think the current behavior is a bug, but would be happy to be corrected as to why it is useful or expected.

@Omnikron13
Copy link
Contributor

One way to think about it is that directories have an implicit .dir extension and thus any other . in the directory name should be ignored.

I find this is pretty horrifying way of thinking about it, ngl. =P

Shouldn't be a very tricky patch tbh, putting aside bikeshedding over how it should be handled.

@Omnikron13
Copy link
Contributor

no-sort-dir

This is how it behaves if the sorting code just short circuits out to 'equal' if either the A or B input is a directory when it is asked to sort by extension.

@Omnikron13
Copy link
Contributor

@sdht0
Copy link
Author

sdht0 commented Mar 6, 2025

I am wishing this will be considered more seriously in the near term. Just listed a directory containing subdirectories with names like 01. people, 02. cities, etc and eza --group-directories-first --color=auto --sort=extension sorted 02 before 01.

@sdht0
Copy link
Author

sdht0 commented Mar 6, 2025

IMO, using --sort=extension should probably imply --group-directories-first and directories should be sorted by names only.

Alternative is to think of directories as containing an implicit .directory extension and be sorted according (e.g., all directories are sorted to be after file.csv and before ventoy.exe). Not horrible I'd say, but opinions can clearly differ as above.

@cafkafk will you accept a patch for either of these solutions?

@sdht0 sdht0 linked a pull request Mar 14, 2025 that will close this issue
@sdht0
Copy link
Author

sdht0 commented Mar 14, 2025

Thinking more on this, the simplest solution is to treat all directories exactly as if no . is present in the name (i.e., None extension) when sorting.

This was bothering me enough to implement a fix. Thanks @Omnikron13 for showing how to do this.

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

Successfully merging a pull request may close this issue.

3 participants