-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ls: ignore leading period when sorting by name #2112
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
Conversation
Every check except |
src/uu/ls/src/ls.rs
Outdated
Sort::Name => entries.sort_by_key(|k| k.file_name.to_lowercase()), | ||
Sort::Name => entries.sort_by_key(|k| { | ||
let has_dot: bool = k.file_name.starts_with('.'); | ||
let filename_nodot: String = if has_dot { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names are usually short so this maybe a nitpick, but we could work with something like this that does not involve clone / collect:
let filename_nodot = &k.file_name[if has_dot { 1 } else { 0 }..];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please add a test to cover this case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I did the clone/collect thing because I was thinking about the general case of "characters in Rust can be up to four bytes long", but I guess if we know the first character is an ASCII .
, then we're free to slice it.
Also, the test case for the "Dot / No Dot" sorting is in test_ls.rs
(inside the test_ls_sort_name
function). Should I add more tests than the simple test case I have right now? (Nevermind. Just saw that these two lines aren't covered... I can try to change that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great :)
@@ -158,7 +158,7 @@ pub fn base_conv_float(src: &[u8], radix_src: u8, _radix_dest: u8) -> f64 { | |||
// to implement this for arbitrary string input. | |||
// until then, the below operates as an outline | |||
// of how it would work. | |||
let result: Vec<u8> = vec![0]; | |||
let _result: Vec<u8> = vec![0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this unrelated change :)
src/uu/ls/src/ls.rs
Outdated
Sort::Name => entries.sort_by_key(|k| k.file_name.to_lowercase()), | ||
Sort::Name => entries.sort_by_key(|k| { | ||
let has_dot: bool = k.file_name.starts_with('.'); | ||
let filename_nodot: String = if has_dot { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please add a test to cover this case :)
ls now behaves like GNU ls with respect to sorting files by ignoring leading periods when sorting by main. Added tests to ensure "touch a .a b .b ; ls" returns ".a a .b b"
8f31505
to
f0aefd9
Compare
ls now behaves like GNU ls with respect to sorting files by ignoring
leading periods when sorting by main.
Added tests to ensure "touch a .a b .b ; ls" returns ".a a .b b"
Note: The non
src/ls/
files that were modified were modified because of clippy warnings that wouldn't let me commit otherwise.