Add inode number column

This commit is contained in:
Ben S 2014-06-22 07:44:00 +01:00
parent fc8f8d6c6a
commit 19e0f9b70d
3 changed files with 13 additions and 3 deletions

View File

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

View File

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

View File

@ -2,7 +2,7 @@ extern crate getopts;
use file::File; use file::File;
use std::cmp::lexical_ordering; 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 unix::get_current_user_id;
use std::ascii::StrAsciiExt; use std::ascii::StrAsciiExt;
@ -35,6 +35,7 @@ impl Options {
getopts::optflag("a", "all", "show dot-files"), getopts::optflag("a", "all", "show dot-files"),
getopts::optflag("b", "binary", "use binary prefixes in file sizes"), getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
getopts::optflag("g", "group", "show group as well as user"), 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("l", "links", "show number of hard links"),
getopts::optflag("r", "reverse", "reverse order of files"), getopts::optflag("r", "reverse", "reverse order of files"),
getopts::optopt("s", "sort", "field to sort by", "WORD"), getopts::optopt("s", "sort", "field to sort by", "WORD"),
@ -53,7 +54,13 @@ impl Options {
} }
fn columns(matches: getopts::Matches) -> Vec<Column> { 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") { if matches.opt_present("links") {
columns.push(HardLinks); columns.push(HardLinks);