From e2f9a80ca5fa28838392becd33c69a758c34fc53 Mon Sep 17 00:00:00 2001 From: Ben S Date: Tue, 22 Jul 2014 21:27:36 +0100 Subject: [PATCH] Add none and inode sort options --- README.md | 4 +++- src/options.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 20f240b..0e55421 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/src/options.rs b/src/options.rs index 8b51a6d..2cd304b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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());