Windows support (if GNU ls is installed)
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 d91100e · Browse files · 1 file·+31 added−15 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+31 added−15 removed
- other:+31 added−15 removed
Provenance
- Commit
0b7febc- Tree
bed0a8d- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
d91100e
1 file changed+31 added−15 removed
modified:src/main.rs+31 added-15 removed
162 unmodified lines163 let color = matches.value_of("color").unwrap_or("auto");164 #[allow(unused)]165 let color_arg = ["--color=", color].concat();166 167+ let gnu_ls = |command_name| {168+ vec![169+ command_name,170+ "-l", // long listing format171+ "--human-readable", // human readable file sizes172+ "--directory", // list directories themselves, not their contents173+ &color_arg,174+ ]175+ };176+177 let cmd: Vec<&str> = if cfg!(unix) {178 if !cfg!(target_os = "macos") {179 // 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- ]180+ gnu_ls("ls")181 } else {182 // MacOS183 use std::process::{Command, Stdio};184 5 unmodified lines190 .status()191 .is_ok();192 193 if gnu_ls_exists {190- vec![191- "gls",192- "-l", // long listing format193- "--human-readable", // human readable file sizes194- "--directory", // list directories themselves, not their contents195- &color_arg,196- ]194+ gnu_ls("gls")195 } else {196 let mut cmd = vec![197 "ls", // MacOS version of ls198 "-l", // long listing format7 unmodified lines206 207 cmd208 }209 }210+ } else if cfg!(windows) {211+ use std::process::{Command, Stdio};212+213+ // Use GNU ls, if available214+ let gnu_ls_exists = Command::new("ls")215+ .arg("--version")216+ .stdout(Stdio::null())217+ .stderr(Stdio::null())218+ .status()219+ .is_ok();220+221+ if gnu_ls_exists {222+ gnu_ls("ls")223+ } else {224+ return Err(anyhow!(225+ "'fd --list-details' is not supported on this platform."226+ ));227+ }228 } else {229 return Err(anyhow!(214- "'fd --list-details' is not supported on this platform."230+ "'fd --list-details' is not supported on Windows unless GNU 'ls' is installed."231 ));232 };233 234 Some(CommandTemplate::new_batch(&cmd).unwrap())165 unmodified lines