Skip to content

Commit ececddd

Browse files
sylvestrecakebaker
andcommitted
ls: If we have --dired --hyperlink, we don't show dired but we still want to see the
long format Co-authored-by: Daniel Hofstetter <[email protected]>
1 parent 4d70562 commit ececddd

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/uu/ls/src/dired.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ pub fn update_positions(dired: &mut DiredOutput, start: usize, end: usize) {
179179
dired.padding = 0;
180180
}
181181

182+
/// Checks if the "--dired" or "-D" argument is present in the command line arguments.
183+
/// we don't use clap here because we need to know if the argument is present
184+
/// as it can be overridden by --hyperlink
185+
pub fn is_dired_arg_present() -> bool {
186+
let args: Vec<String> = std::env::args().collect();
187+
args.iter().any(|x| x == "--dired" || x == "-D")
188+
}
189+
182190
#[cfg(test)]
183191
mod tests {
184192
use super::*;

src/uu/ls/src/ls.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use uucore::{
6767
};
6868
use uucore::{help_about, help_section, help_usage, parse_glob, show, show_error, show_warning};
6969
mod dired;
70-
use dired::DiredOutput;
70+
use dired::{is_dired_arg_present, DiredOutput};
7171
#[cfg(not(feature = "selinux"))]
7272
static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)";
7373
#[cfg(feature = "selinux")]
@@ -1079,8 +1079,10 @@ impl Config {
10791079
};
10801080

10811081
let dired = options.get_flag(options::DIRED);
1082-
if dired {
1082+
if dired || is_dired_arg_present() {
10831083
// --dired implies --format=long
1084+
// if we have --dired --hyperlink, we don't show dired but we still want to see the
1085+
// long format
10841086
format = Format::Long;
10851087
}
10861088
if dired && options.get_flag(options::ZERO) {

tests/by-util/test_ls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,8 @@ fn test_ls_dired_hyperlink() {
39563956
.arg("-R")
39573957
.succeeds()
39583958
.stdout_contains("file://")
3959+
.stdout_contains("-rw") // we should have the long output
3960+
// even if dired isn't actually run
39593961
.stdout_does_not_contain("//DIRED//");
39603962
// dired is passed after hyperlink
39613963
// so we will have DIRED output

0 commit comments

Comments
 (0)