Explorar o código

Add none and inode sort options

Ben S %!s(int64=11) %!d(string=hai) anos
pai
achega
e2f9a80ca5
Modificáronse 2 ficheiros con 12 adicións e 6 borrados
  1. 3 1
      README.md
  2. 9 5
      src/options.rs

+ 3 - 1
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
 ------------
 

+ 9 - 5
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());