diff --git a/src/bin/main.rs b/src/bin/main.rs index e0d0271..50fc764 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -63,12 +63,22 @@ fn print_entry(path_root: &Path, path_entry: &Path, config: &FdOptions) { } else if component_path.is_dir() { config.ls_colors.directory } else { - // Loop up file extension - component_path.extension() - .and_then(|e| e.to_str()) - .and_then(|e| config.ls_colors.extensions.get(e)) - .map(|r| r.clone()) - .unwrap_or(Style::new()) + // Look up file name + let o_style = + component_path.file_name() + .and_then(|n| n.to_str()) + .and_then(|n| config.ls_colors.filenames.get(n)); + + match o_style { + Some(s) => s.clone(), + None => + // Look up file extension + component_path.extension() + .and_then(|e| e.to_str()) + .and_then(|e| config.ls_colors.extensions.get(e)) + .map(|r| r.clone()) + .unwrap_or(Style::new()) + } }; print!("{}", style.paint(comp_str.to_str().unwrap())); diff --git a/src/lscolors/mod.rs b/src/lscolors/mod.rs index b189ac9..34976a4 100644 --- a/src/lscolors/mod.rs +++ b/src/lscolors/mod.rs @@ -109,7 +109,7 @@ impl LsColors { } else if pattern.starts_with("*") { let filename = String::from(pattern).split_off(1); - self.extensions.insert(filename, style); + self.filenames.insert(filename, style); } else { // Unknown/corrupt pattern return; @@ -154,8 +154,10 @@ fn test_lscolors() { assert_eq!(LsColors::default(), LsColors::from_string(&String::new())); let result = LsColors::from_string( - &String::from("rs=0:di=03;34:ln=01;36:*.foo=01;31:")); + &String::from("rs=0:di=03;34:ln=01;36:*.foo=01;35:*README=33")); assert_eq!(Colour::Blue.italic(), result.directory); assert_eq!(Colour::Cyan.bold(), result.symlink); + assert_eq!(Some(&Colour::Purple.bold()), result.extensions.get("foo")); + assert_eq!(Some(&Colour::Yellow.normal()), result.filenames.get("README")); }