diff --git a/Cargo.toml b/Cargo.toml index fb4629f..bf4723a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,9 @@ nu-ansi-term = { version = "0.50", optional = true } crossterm = { version = "0.27", optional = true } owo-colors = { version = "4.0", optional = true } +[target.'cfg(target_os = "linux")'.dependencies] +capctl = "0.2.4" + [dev-dependencies] tempfile = "^3" diff --git a/src/lib.rs b/src/lib.rs index 1032dc1..05257d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,6 +198,18 @@ pub trait Colorable { /// Try to get the metadata for this file. fn metadata(&self) -> Option; + + #[cfg(target_os = "linux")] + fn has_capabilities(&self) -> bool { + matches!( + capctl::caps::FileCaps::get_for_file(self.path()), + Ok(Some(..)) + ) + } + #[cfg(not(target_os = "linux"))] + fn has_capabilities(&self) -> bool { + false + } } impl Colorable for DirEntry { @@ -333,11 +345,14 @@ impl LsColors { if let Some(metadata) = file.metadata() { let mode = crate::fs::mode(&metadata); let nlink = crate::fs::nlink(&metadata); - if self.has_color_for(Indicator::Setuid) && mode & 0o4000 != 0 { return Indicator::Setuid; } else if self.has_color_for(Indicator::Setgid) && mode & 0o2000 != 0 { return Indicator::Setgid; + } else if self.has_color_for(Indicator::Capabilities) + && file.has_capabilities() + { + return Indicator::Capabilities; } else if self.has_color_for(Indicator::ExecutableFile) && mode & 0o0111 != 0 {