diff options
author | sharkdp <davidpeter@web.de> | 2017-06-05 21:50:46 +0200 |
---|---|---|
committer | sharkdp <davidpeter@web.de> | 2017-06-05 21:51:10 +0200 |
commit | 4d950ae97cc818dfb2707cc125fecd30995e2477 (patch) | |
tree | 88f83864d42a965dd5a5b4feb762411878038372 | |
parent | 8adb5b9f848bb4f3b746254cb07943c6f3593f91 (diff) |
Highlight executable filesv1.0.0
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lscolors/mod.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 10 |
4 files changed, 17 insertions, 2 deletions
@@ -1,6 +1,6 @@ [root] name = "fd" -version = "0.3.0" +version = "1.0.0" dependencies = [ "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,6 +1,6 @@ [package] name = "fd" -version = "0.3.0" +version = "1.0.0" authors = ["David Peter <mail@david-peter.de>"] [dependencies] diff --git a/src/lscolors/mod.rs b/src/lscolors/mod.rs index 8ef2331..d337439 100644 --- a/src/lscolors/mod.rs +++ b/src/lscolors/mod.rs @@ -24,6 +24,9 @@ pub struct LsColors { /// ANSI style for symbolic links. pub symlink: Style, + /// ANSI style for executable files. + pub executable: Style, + /// A map that defines ANSI styles for different file extensions. pub extensions: ExtensionStyles, @@ -37,6 +40,7 @@ impl Default for LsColors { LsColors { directory: Colour::Blue.bold(), symlink: Colour::Cyan.normal(), + executable: Colour::Red.bold(), extensions: HashMap::new(), filenames: HashMap::new() } @@ -125,6 +129,7 @@ impl LsColors { match code.as_ref() { "di" => self.directory = style, "ln" => self.symlink = style, + "ex" => self.executable = style, _ => return } } else if pattern.starts_with("*.") { diff --git a/src/main.rs b/src/main.rs index 3abafdb..4781e53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::error::Error; use std::ffi::OsStr; use std::fs; use std::io::Write; +use std::os::unix::fs::PermissionsExt; use std::path::{Path, Component}; use std::process; @@ -76,6 +77,13 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) { None => return }; + let is_executable = |p: &std::path::PathBuf| { + p.metadata() + .ok() + .map(|f| f.permissions().mode() & 0o111 != 0) + .unwrap_or(false) + }; + if let Some(ref ls_colors) = config.ls_colors { let mut component_path = base.to_path_buf(); @@ -100,6 +108,8 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) { ls_colors.symlink } else if component_path.is_dir() { ls_colors.directory + } else if is_executable(&component_path) { + ls_colors.executable } else { // Look up file name let o_style = |