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

This commit is contained in:
sharkdp 2020-04-15 20:29:59 +02:00 committed by David Peter
parent 789706c3ab
commit 2685728695
1 changed files with 48 additions and 10 deletions

View File

@ -161,18 +161,56 @@ fn run() -> Result<ExitCode> {
Some(CommandTemplate::new_batch(args)?)
} else if matches.is_present("list-details") {
let color = matches.value_of("color").unwrap_or("auto");
#[allow(unused)]
let color_arg = ["--color=", color].concat();
Some(
CommandTemplate::new_batch(&[
"ls",
"-l", // long listing format
"--human-readable", // human readable file sizes
"--directory", // list directories themselves, not their contents
&color_arg, // enable colorized output, if enabled
])
.unwrap(),
)
let cmd: Vec<&str> = if cfg!(unix) {
if !cfg!(target_os = "macos") {
// Non-MacOS Unix
vec![
"ls",
"-l", // long listing format
"--human-readable", // human readable file sizes
"--directory", // list directories themselves, not their contents
&color_arg,
]
} else {
// MacOS
use std::process::Command;
// Use GNU ls, if available
let gnu_ls_exists = Command::new("gls").arg("--version").status().is_ok();
if gnu_ls_exists {
vec![
"gls",
"-l", // long listing format
"--human-readable", // human readable file sizes
"--directory", // list directories themselves, not their contents
&color_arg,
]
} else {
let mut cmd = vec![
"ls", // MacOS version of ls
"-l", // long listing format
"-h", // '--human-readable' is not available on MacOS, '-h' is
"-d", // '--directory' is not available, but '-d' is
];
if colored_output {
cmd.push("-G");
}
cmd
}
}
} else {
return Err(anyhow!(
"'fd --list-details' is not supported on this platform."
));
};
Some(CommandTemplate::new_batch(&cmd).unwrap())
} else {
None
};