Add none and inode sort options

This commit is contained in:
Ben S 2014-07-22 21:27:36 +01:00
parent 35a0ba3ba0
commit e2f9a80ca5
2 changed files with 12 additions and 6 deletions

View File

@ -22,10 +22,12 @@ Options
- **-i**, **--inode**: show inode number column
- **-l**, **--long**: display extended details and attributes
- **-r**, **--reverse**: reverse sort order
- **-s**, **--sort=(name, size, ext)**: field to sort by
- **-s**, **--sort=(field)**: field to sort by
- **-S**, **--blocks**: show number of file system blocks
- **-x**, **--across**: sort multi-column view entries across
You can sort by **name**, **size**, **ext**, **inode**, or **none**.
Installation
------------

View File

@ -6,16 +6,18 @@ use std::ascii::StrAsciiExt;
use term;
pub enum SortField {
Name, Extension, Size
Unsorted, Name, Extension, Size, FileInode
}
impl SortField {
fn from_word(word: String) -> SortField {
match word.as_slice() {
"name" => Name,
"size" => Size,
"ext" => Extension,
_ => fail!("Invalid sorting order"),
"name" => Name,
"size" => Size,
"ext" => Extension,
"none" => Unsorted,
"inode" => FileInode,
_ => fail!("Invalid sorting order"),
}
}
}
@ -125,8 +127,10 @@ impl Options {
.collect();
match self.sort_field {
Unsorted => {},
Name => files.sort_by(|a, b| a.parts.cmp(&b.parts)),
Size => files.sort_by(|a, b| a.stat.size.cmp(&b.stat.size)),
FileInode => files.sort_by(|a, b| a.stat.unstable.inode.cmp(&b.stat.unstable.inode)),
Extension => files.sort_by(|a, b| {
let exts = a.ext.clone().map(|e| e.as_slice().to_ascii_lower()).cmp(&b.ext.clone().map(|e| e.as_slice().to_ascii_lower()));
let names = a.name.as_slice().to_ascii_lower().cmp(&b.name.as_slice().to_ascii_lower());