summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/uu/ls/src/dired.rs8
-rw-r--r--src/uu/ls/src/ls.rs6
-rw-r--r--tests/by-util/test_ls.rs2
3 files changed, 14 insertions, 2 deletions
diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs
index c73b11ae3..afb82a509 100644
--- a/src/uu/ls/src/dired.rs
+++ b/src/uu/ls/src/dired.rs
@@ -179,6 +179,14 @@ pub fn update_positions(dired: &mut DiredOutput, start: usize, end: usize) {
dired.padding = 0;
}
+/// Checks if the "--dired" or "-D" argument is present in the command line arguments.
+/// we don't use clap here because we need to know if the argument is present
+/// as it can be overridden by --hyperlink
+pub fn is_dired_arg_present() -> bool {
+ let args: Vec<String> = std::env::args().collect();
+ args.iter().any(|x| x == "--dired" || x == "-D")
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs
index 8db3f25b3..520b634d3 100644
--- a/src/uu/ls/src/ls.rs
+++ b/src/uu/ls/src/ls.rs
@@ -67,7 +67,7 @@ use uucore::{
};
use uucore::{help_about, help_section, help_usage, parse_glob, show, show_error, show_warning};
mod dired;
-use dired::DiredOutput;
+use dired::{is_dired_arg_present, DiredOutput};
#[cfg(not(feature = "selinux"))]
static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)";
#[cfg(feature = "selinux")]
@@ -1079,8 +1079,10 @@ impl Config {
};
let dired = options.get_flag(options::DIRED);
- if dired {
+ if dired || is_dired_arg_present() {
// --dired implies --format=long
+ // if we have --dired --hyperlink, we don't show dired but we still want to see the
+ // long format
format = Format::Long;
}
if dired && options.get_flag(options::ZERO) {
diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs
index f8f638fd7..edb2cd62d 100644
--- a/tests/by-util/test_ls.rs
+++ b/tests/by-util/test_ls.rs
@@ -3956,6 +3956,8 @@ fn test_ls_dired_hyperlink() {
.arg("-R")
.succeeds()
.stdout_contains("file://")
+ .stdout_contains("-rw") // we should have the long output
+ // even if dired isn't actually run
.stdout_does_not_contain("//DIRED//");
// dired is passed after hyperlink
// so we will have DIRED output