summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2017-06-05 21:50:46 +0200
committersharkdp <davidpeter@web.de>2017-06-05 21:51:10 +0200
commit4d950ae97cc818dfb2707cc125fecd30995e2477 (patch)
tree88f83864d42a965dd5a5b4feb762411878038372
parent8adb5b9f848bb4f3b746254cb07943c6f3593f91 (diff)
Highlight executable filesv1.0.0
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lscolors/mod.rs5
-rw-r--r--src/main.rs10
4 files changed, 17 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7e4e9ca..19f0052 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index a2d7289..0f7e4fb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 =