Ben S 11 роки тому
батько
коміт
19e0f9b70d
3 змінених файлів з 13 додано та 3 видалено
  1. 2 0
      column.rs
  2. 2 1
      file.rs
  3. 9 2
      options.rs

+ 2 - 0
column.rs

@@ -5,6 +5,7 @@ pub enum Column {
     User(u64),
     Group,
     HardLinks,
+    Inode,
 }
 
 // Each column can pick its own alignment. Usually, numbers are
@@ -19,6 +20,7 @@ impl Column {
         match *self {
             FileSize(_) => Right,
             HardLinks   => Right,
+            Inode       => Right,
             _           => Left,
         }
     }

+ 2 - 1
file.rs

@@ -2,7 +2,7 @@ use colours::{Plain, Style, Black, Red, Green, Yellow, Blue, Purple, Cyan, Fixed
 use std::io::{fs, IoResult};
 use std::io;
 
-use column::{Column, Permissions, FileName, FileSize, User, Group, HardLinks};
+use column::{Column, Permissions, FileName, FileSize, User, Group, HardLinks, Inode};
 use format::{format_metric_bytes, format_IEC_bytes};
 use unix::Unix;
 use sort::SortPart;
@@ -95,6 +95,7 @@ impl<'a> File<'a> {
             FileName => self.file_name(),
             FileSize(use_iec) => self.file_size(use_iec),
             HardLinks => Red.paint(self.stat.unstable.nlink.to_str().as_slice()),
+            Inode => Purple.paint(self.stat.unstable.inode.to_str().as_slice()),
 
             // Display the ID if the user/group doesn't exist, which
             // usually means it was deleted but its files weren't.

+ 9 - 2
options.rs

@@ -2,7 +2,7 @@ extern crate getopts;
 
 use file::File;
 use std::cmp::lexical_ordering;
-use column::{Column, Permissions, FileName, FileSize, User, Group, HardLinks};
+use column::{Column, Permissions, FileName, FileSize, User, Group, HardLinks, Inode};
 use unix::get_current_user_id;
 use std::ascii::StrAsciiExt;
 
@@ -35,6 +35,7 @@ impl Options {
             getopts::optflag("a", "all", "show dot-files"),
             getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
             getopts::optflag("g", "group", "show group as well as user"),
+            getopts::optflag("i", "inode", "show each file's inode number"),
             getopts::optflag("l", "links", "show number of hard links"),
             getopts::optflag("r", "reverse", "reverse order of files"),
             getopts::optopt("s", "sort", "field to sort by", "WORD"),
@@ -53,7 +54,13 @@ impl Options {
     }
 
     fn columns(matches: getopts::Matches) -> Vec<Column> {
-        let mut columns = vec![Permissions];
+        let mut columns = vec![];
+
+        if matches.opt_present("inode") {
+            columns.push(Inode);
+        }
+
+        columns.push(Permissions);
 
         if matches.opt_present("links") {
             columns.push(HardLinks);