mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-16 09:17:09 +00:00
Merge pull request #343 from BenWhitehead/mix-hidden-sorting
Add new sort option `.name` and `.Name`
This commit is contained in:
commit
9896f9ed78
@ -191,6 +191,10 @@ pub enum SortField {
|
|||||||
/// bad, even though that’s kind of nonsensical. So it’s its own variant
|
/// bad, even though that’s kind of nonsensical. So it’s its own variant
|
||||||
/// that can be reversed like usual.
|
/// that can be reversed like usual.
|
||||||
ModifiedAge,
|
ModifiedAge,
|
||||||
|
|
||||||
|
/// The file's name, however if the name of the file begins with `.`
|
||||||
|
/// ignore the leading `.` and then sort as Name
|
||||||
|
NameMixHidden(SortCase),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether a field should be sorted case-sensitively or case-insensitively.
|
/// Whether a field should be sorted case-sensitively or case-insensitively.
|
||||||
@ -253,6 +257,23 @@ impl SortField {
|
|||||||
Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name),
|
Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name),
|
||||||
order => order,
|
order => order,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
SortField::NameMixHidden(ABCabc) => natord::compare(
|
||||||
|
SortField::strip_dot(&a.name),
|
||||||
|
SortField::strip_dot(&b.name)
|
||||||
|
),
|
||||||
|
SortField::NameMixHidden(AaBbCc) => natord::compare_ignore_case(
|
||||||
|
SortField::strip_dot(&a.name),
|
||||||
|
SortField::strip_dot(&b.name)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn strip_dot(n: &str) -> &str {
|
||||||
|
if n.starts_with(".") {
|
||||||
|
&n[1..]
|
||||||
|
} else {
|
||||||
|
n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,12 @@ impl SortField {
|
|||||||
else if word == "Name" || word == "Filename" {
|
else if word == "Name" || word == "Filename" {
|
||||||
Ok(SortField::Name(SortCase::ABCabc))
|
Ok(SortField::Name(SortCase::ABCabc))
|
||||||
}
|
}
|
||||||
|
else if word == ".name" || word == ".filename" {
|
||||||
|
Ok(SortField::NameMixHidden(SortCase::AaBbCc))
|
||||||
|
}
|
||||||
|
else if word == ".Name" || word == ".Filename" {
|
||||||
|
Ok(SortField::NameMixHidden(SortCase::ABCabc))
|
||||||
|
}
|
||||||
else if word == "size" || word == "filesize" {
|
else if word == "size" || word == "filesize" {
|
||||||
Ok(SortField::Size)
|
Ok(SortField::Size)
|
||||||
}
|
}
|
||||||
@ -231,6 +237,9 @@ mod test {
|
|||||||
test!(newest: SortField <- ["--sort=oldest"]; Both => Ok(SortField::ModifiedAge));
|
test!(newest: SortField <- ["--sort=oldest"]; Both => Ok(SortField::ModifiedAge));
|
||||||
test!(age: SortField <- ["-sage"]; Both => Ok(SortField::ModifiedAge));
|
test!(age: SortField <- ["-sage"]; Both => Ok(SortField::ModifiedAge));
|
||||||
|
|
||||||
|
test!(mix_hidden_lowercase: SortField <- ["--sort", ".name"]; Both => Ok(SortField::NameMixHidden(SortCase::AaBbCc)));
|
||||||
|
test!(mix_hidden_uppercase: SortField <- ["--sort", ".Name"]; Both => Ok(SortField::NameMixHidden(SortCase::ABCabc)));
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
test!(error: SortField <- ["--sort=colour"]; Both => Err(Misfire::BadArgument(&flags::SORT, OsString::from("colour"))));
|
test!(error: SortField <- ["--sort=colour"]; Both => Err(Misfire::BadArgument(&flags::SORT, OsString::from("colour"))));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user