dir: order of directories and hidden directories is incorrect with -a flag
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
By default, from GNU's help page on the dir command, it seems like GNU's dir command sorts by WORD. One thing that I noticed is when I used dir command on my home directory is the following:
asder8215@new-host-4:~$ dir -a
. .bashrc .debug .gtkrc-2.0 Pictures .ssh
.. .cache Desktop .local .pki Templates
.bash_history .cargo Documents .mozilla .profile .var
.bash_logout coding-project Downloads Music Public Videos
.bash_profile .config .gitconfig .npm .rustup .vscode-oss
GNU's dir command, by default, outputs the order of the directories in alphabetical order ignoring the leading dots for hidden directories. This logic follows through with all other sort options, like sizes, as shown in the following example:
asder8215@new-host-4:~$ dir -a --size
total 64
0 . 0 .cache 0 Documents 0 Music 0 .rustup
0 .. 4 .cargo 0 Downloads 0 .npm 0 .ssh
36 .bash_history 0 coding-project 4 .gitconfig 0 Pictures 0 Templates
4 .bash_logout 0 .config 4 .gtkrc-2.0 0 .pki 0 .var
4 .bash_profile 0 .debug 0 .local 4 .profile 0 Videos
4 .bashrc 0 Desktop 0 .mozilla 0 Public 0 .vscode-oss
Unfortunately, this does not appear to be the case in uutils dir because when I run the same command, I get the following result:
asder8215@new-host-4:~$ ~/coding-project/coreutils/target/release/dir -a
. .bashrc .gitconfig .pki .vscode-oss Pictures
.. .cache .gtkrc-2.0 .profile Desktop Public
.bash_history .cargo .local .rustup Documents Templates
.bash_logout .config .mozilla .ssh Downloads Videos
.bash_profile .debug .npm .var Music coding-project
Moreover, taking away the -a flag and comparing the results of what GNU's dir command and uutils dir command on the home directory, we can see the following difference:
asder8215@new-host-4:~$ dir
coding-project Desktop Documents Downloads Music Pictures Public Templates Videos
asder8215@new-host-4:~$ ~/coding-project/coreutils/target/release/dir
Desktop Downloads Pictures Templates coding-project
Documents Music Public Videos
GNU's dir command is ascii insensitive in the sense that it treats 'c' and 'C' as preceding that of 'd' or 'D'. uutils' dir command seems to be ascii sensitive, which lines up with how it currently orders the directories (and why all the hidden directories are printed earlier than regular directories due to '.' having an ascii value of 46 which precedes the alphabetical characters' ascii values). We should make uutils' dir command ascii insensitive and remove consideration of leading dots when outputting the order of directories with -a flag.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the uutils dir command and compare its default and -a output with GNU dir, including mixed-case names and hidden entries. Done means directory names sort case-insensitively and leading dots are ignored for ordering under -a, while the shown default and size-sorting behavior matches GNU.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100