diff --git a/src/exa.rs b/src/exa.rs index e84414c..87be7a3 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -42,10 +42,14 @@ fn exa(opts: &Options) { let mut dirs: Vec = vec![]; let mut files: Vec = vec![]; + // It's only worth printing out directory names if the user supplied + // more than one of them. + let mut print_dir_names = false; + // Separate the user-supplied paths into directories and files. // Files are shown first, and then each directory is expanded // and listed second. - for file in opts.path_strs.iter() { + for file in opts.path_strings() { let path = Path::new(file); match fs::stat(&path) { Ok(stat) => { @@ -60,11 +64,10 @@ fn exa(opts: &Options) { } Err(e) => println!("{}: {}", file, e), } + + print_dir_names = true; } - // It's only worth printing out directory names if the user supplied - // more than one of them. - let print_dir_names = opts.path_strs.len() > 1; let mut first = files.is_empty(); if !files.is_empty() { diff --git a/src/options.rs b/src/options.rs index 3a284b9..054413d 100644 --- a/src/options.rs +++ b/src/options.rs @@ -7,6 +7,7 @@ use column::Column::*; use term::dimensions; use std::ascii::AsciiExt; +use std::slice::Iter; pub enum SortField { Unsorted, Name, Extension, Size, FileInode @@ -36,10 +37,10 @@ pub enum View { pub struct Options { pub header: bool, pub list_dirs: bool, - pub path_strs: Vec, - pub reverse: bool, - pub show_invisibles: bool, - pub sort_field: SortField, + path_strs: Vec, + reverse: bool, + show_invisibles: bool, + sort_field: SortField, pub view: View, } @@ -87,6 +88,10 @@ impl Options { }) } + pub fn path_strings(&self) -> Iter { + self.path_strs.iter() + } + fn view(matches: &getopts::Matches) -> View { if matches.opt_present("long") { View::Details(Options::columns(matches))