mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-16 01:07:09 +00:00
Allow sorting by file extension
This commit is contained in:
parent
cb1b8bc2d7
commit
184de0ce79
5
file.rs
5
file.rs
@ -31,6 +31,11 @@ impl<'a> File<'a> {
|
|||||||
return File { path: path, stat: stat, name: filename };
|
return File { path: path, stat: stat, name: filename };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ext(&self) -> Option<&'a str> {
|
||||||
|
let re = regex!(r"\.(.+)$");
|
||||||
|
re.captures(self.name).map(|caps| caps.at(1))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_dotfile(&self) -> bool {
|
pub fn is_dotfile(&self) -> bool {
|
||||||
self.name.starts_with(".")
|
self.name.starts_with(".")
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use file::File;
|
use file::File;
|
||||||
|
use std::cmp::lexical_ordering;
|
||||||
|
|
||||||
pub enum SortField {
|
pub enum SortField {
|
||||||
Name, Size
|
Name, Extension, Size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
@ -14,6 +15,7 @@ impl SortField {
|
|||||||
match word.as_slice() {
|
match word.as_slice() {
|
||||||
"name" => Name,
|
"name" => Name,
|
||||||
"size" => Size,
|
"size" => Size,
|
||||||
|
"ext" => Extension,
|
||||||
_ => fail!("Invalid sorting order"),
|
_ => fail!("Invalid sorting order"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,6 +24,11 @@ impl SortField {
|
|||||||
match *self {
|
match *self {
|
||||||
Name => files.sort_by(|a, b| a.name.cmp(&b.name)),
|
Name => files.sort_by(|a, b| a.name.cmp(&b.name)),
|
||||||
Size => files.sort_by(|a, b| a.stat.size.cmp(&b.stat.size)),
|
Size => files.sort_by(|a, b| a.stat.size.cmp(&b.stat.size)),
|
||||||
|
Extension => files.sort_by(|a, b| {
|
||||||
|
let exts = a.ext().cmp(&b.ext());
|
||||||
|
let names = a.name.cmp(&b.name);
|
||||||
|
lexical_ordering(exts, names)
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user