Highlight executable files
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 8adb5b9 · Browse files · 4 files·+17 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+17 added−2 removed
- other:+17 added−2 removed
Provenance
- Commit
4d950ae- Tree
88f8386- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
8adb5b9
4 files changed+17 added−2 removed
modified:src/lscolors/mod.rs+5 added
22 unmodified lines23 24 /// ANSI style for symbolic links.25 pub symlink: Style,26 27+ /// ANSI style for executable files.28+ pub executable: Style,29+30 /// A map that defines ANSI styles for different file extensions.31 pub extensions: ExtensionStyles,32 33 /// A map that defines ANSI styles for different specific filenames.5 unmodified lines39 fn default() -> LsColors {40 LsColors {41 directory: Colour::Blue.bold(),42 symlink: Colour::Cyan.normal(),43+ executable: Colour::Red.bold(),44 extensions: HashMap::new(),45 filenames: HashMap::new()46 }47 }80 unmodified lines128 if let Some(code) = res {129 match code.as_ref() {130 "di" => self.directory = style,131 "ln" => self.symlink = style,132+ "ex" => self.executable = style,133 _ => return134 }135 } else if pattern.starts_with("*.") {136 let extension = String::from(pattern).split_off(2);83 unmodified linesmodified:src/main.rs+10 added
10 unmodified lines11 use std::error::Error;12 use std::ffi::OsStr;13 use std::fs;14 use std::io::Write;15+use std::os::unix::fs::PermissionsExt;16 use std::path::{Path, Component};17 use std::process;18 19 use getopts::Options;56 unmodified lines76 Some(p) => p,77 None => return78 };79 80+ let is_executable = |p: &std::path::PathBuf| {81+ p.metadata()82+ .ok()83+ .map(|f| f.permissions().mode() & 0o111 != 0)84+ .unwrap_or(false)85+ };86+87 if let Some(ref ls_colors) = config.ls_colors {88 let mut component_path = base.to_path_buf();89 90 if config.path_display == PathDisplay::Absolute {16 unmodified lines107 .unwrap_or(false) {108 ls_colors.symlink109 } else if component_path.is_dir() {110 ls_colors.directory111+ } else if is_executable(&component_path) {112+ ls_colors.executable113 } else {114 // Look up file name115 let o_style =116 component_path.file_name()176 unmodified linesmodified:Cargo.lock+1 added-1 removed
1 [root]2 name = "fd"3-version = "0.3.0"3+version = "1.0.0"4 dependencies = [5 "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",6 "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",7 "ignore 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",208 unmodified linesmodified:Cargo.toml+1 added-1 removed
123345674 unmodified lines[package]name = "fd"version = "0.3.0"version = "1.0.0"authors = ["David Peter <mail@david-peter.de>"]
[dependencies]ansi_term = "0.9"4 unmodified lines