diff --git a/doc/lsd.md b/doc/lsd.md index 78a120465..791d680de 100644 --- a/doc/lsd.md +++ b/doc/lsd.md @@ -134,6 +134,9 @@ lsd is a ls command with a lot of pretty colours and some other stuff to enrich `-U`, `--no-sort` : Do not sort. List entries in directory order +`-f` +: Do not sort and show hidden entries. Same as `-a -U` + `-Z` `--context` : Display SELinux or SMACK security context diff --git a/src/app.rs b/src/app.rs index c8d80c7cb..73a947d02 100644 --- a/src/app.rs +++ b/src/app.rs @@ -121,6 +121,10 @@ pub struct Cli { #[arg(short = 'U', long, overrides_with_all = ["timesort", "sizesort", "extensionsort", "versionsort", "gitsort", "sort"])] pub no_sort: bool, + /// Do not sort and show hidden entries. Same as -a -U + #[arg(short = 'f', overrides_with_all = ["timesort", "sizesort", "extensionsort", "versionsort", "gitsort", "sort"])] + pub no_sort_all: bool, + /// Reverse the order of the sort #[arg(short, long)] pub reverse: bool, diff --git a/src/flags/display.rs b/src/flags/display.rs index a9fe8c4b8..bdcebf3d4 100644 --- a/src/flags/display.rs +++ b/src/flags/display.rs @@ -32,7 +32,7 @@ impl Configurable for Display { Some(Self::DirectoryOnly) } else if cli.almost_all { Some(Self::AlmostAll) - } else if cli.all { + } else if cli.all || cli.no_sort_all { Some(Self::All) } else if cli.system_protected { #[cfg(windows)] @@ -91,6 +91,13 @@ mod test { assert_eq!(Some(Display::All), Display::from_cli(&cli)); } + #[test] + fn test_from_cli_no_sort_all() { + let argv = ["lsd", "-f"]; + let cli = Cli::try_parse_from(argv).unwrap(); + assert_eq!(Some(Display::All), Display::from_cli(&cli)); + } + #[test] fn test_from_cli_almost_all() { let argv = ["lsd", "--almost-all"]; diff --git a/src/flags/sorting.rs b/src/flags/sorting.rs index 3e895933d..be587c200 100644 --- a/src/flags/sorting.rs +++ b/src/flags/sorting.rs @@ -65,7 +65,7 @@ impl Configurable for SortColumn { Some(Self::Version) } else if cli.gitsort || sort == Some("git") { Some(Self::GitStatus) - } else if cli.no_sort || sort == Some("none") { + } else if cli.no_sort || cli.no_sort_all || sort == Some("none") { Some(Self::None) } else { None @@ -236,6 +236,27 @@ mod test_sort_column { assert_eq!(Some(SortColumn::None), SortColumn::from_cli(&cli)); } + #[test] + fn test_from_cli_no_sort_all() { + let argv = ["lsd", "-f"]; + let cli = Cli::try_parse_from(argv).unwrap(); + assert_eq!(Some(SortColumn::None), SortColumn::from_cli(&cli)); + } + + #[test] + fn test_from_cli_no_sort_all_overridden_by_later_sort_flag() { + let argv = ["lsd", "-f", "-t"]; + let cli = Cli::try_parse_from(argv).unwrap(); + assert_eq!(Some(SortColumn::Time), SortColumn::from_cli(&cli)); + } + + #[test] + fn test_from_cli_no_sort_all_overrides_earlier_sort_flag() { + let argv = ["lsd", "-t", "-f"]; + let cli = Cli::try_parse_from(argv).unwrap(); + assert_eq!(Some(SortColumn::None), SortColumn::from_cli(&cli)); + } + #[test] fn test_from_cli_sort() { let argv = ["lsd", "--sort", "time"]; diff --git a/tests/integration.rs b/tests/integration.rs index 72442331c..5fa2dd247 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -411,6 +411,21 @@ fn test_show_folder_of_symlink_for_long_multi() { .stdout(predicate::str::contains("link/:")); } +#[test] +fn test_no_sort_all_shows_hidden_entries() { + let dir = tempdir(); + dir.child(".hidden").touch().unwrap(); + dir.child("visible").touch().unwrap(); + cmd() + .arg("-f") + .arg("-1") + .arg("--ignore-config") + .arg(dir.path()) + .assert() + .stdout(predicate::str::contains(".hidden")) + .stdout(predicate::str::contains("visible")); +} + #[test] fn test_version_sort() { let dir = tempdir();