Skip to content
Myr

Add MacOS support for -l/--list-details

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by David Peter · parent 789706c · Browse files · 1 file+48 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+48 added−10 removed

  • other:+48 added−10 removed

1 file+48 added−10 removed

modified:src/main.rs+48 added-10 removed
159 unmodified lines
160 } else if let Some(args) = matches.values_of("exec-batch") {161 Some(CommandTemplate::new_batch(args)?)162 } else if matches.is_present("list-details") {163 let color = matches.value_of("color").unwrap_or("auto");164 #[allow(unused)]165 let color_arg = ["--color=", color].concat();166166 Some(167 CommandTemplate::new_batch(&[168 "ls",169 "-l", // long listing format170 "--human-readable", // human readable file sizes171 "--directory", // list directories themselves, not their contents172 &color_arg, // enable colorized output, if enabled173 ])174 .unwrap(),175 )167 let cmd: Vec<&str> = if cfg!(unix) {168 if !cfg!(target_os = "macos") {169 // Non-MacOS Unix170 vec![171 "ls",172 "-l", // long listing format173 "--human-readable", // human readable file sizes174 "--directory", // list directories themselves, not their contents175 &color_arg,176 ]177 } else {178 // MacOS179 use std::process::Command;180181 // Use GNU ls, if available182 let gnu_ls_exists = Command::new("gls").arg("--version").status().is_ok();183184 if gnu_ls_exists {185 vec![186 "gls",187 "-l", // long listing format188 "--human-readable", // human readable file sizes189 "--directory", // list directories themselves, not their contents190 &color_arg,191 ]192 } else {193 let mut cmd = vec![194 "ls", // MacOS version of ls195 "-l", // long listing format196 "-h", // '--human-readable' is not available on MacOS, '-h' is197 "-d", // '--directory' is not available, but '-d' is198 ];199200 if colored_output {201 cmd.push("-G");202 }203204 cmd205 }206 }207 } else {208 return Err(anyhow!(209 "'fd --list-details' is not supported on this platform."210 ));211 };212213 Some(CommandTemplate::new_batch(&cmd).unwrap())214 } else {215 None216 };217
161 unmodified lines