Skip to content

Commit

Permalink
ls: If we have --dired --hyperlink, we don't show dired but we still …
Browse files Browse the repository at this point in the history
…want to see the

long format
  • Loading branch information
sylvestre committed Jun 23, 2024
1 parent 4d70562 commit 572485c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/uu/ls/src/dired.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ 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();
let dired_index = args.iter().position(|x| x == "--dired" || x == "-D");

dired_index.is_some()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 4 additions & 2 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 572485c

Please sign in to comment.