Repository: lsd-rs/lsd (language: rust)

Issue:
ls -U equivalent for lsd?



Discussion / hints:
We do not currently support disabling sorting, but that is something that we could add.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b75c0c54e..38bc4079c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased] - ReleaseDate
 ### Added
+- Add support for `--no-sort` `-U` from [MichaelAug](https://github.com/MichaelAug)
 - Add `--group-directories-first` as an alias for `--group-dirs=first` to improve compatibility with `coreutils/ls`
 ### Fixed
 - Support non-bold bright colors [#248](https://github.com/Peltoche/lsd/issues/248) from [meain](https://github.com/meain)
diff --git a/doc/lsd.md b/doc/lsd.md
index 47dd8afb8..1a77bd730 100644
--- a/doc/lsd.md
+++ b/doc/lsd.md
@@ -122,6 +122,9 @@ lsd is a ls command with a lot of pretty colours and some other stuff to enrich
 `--sort <WORD>...`
 : Sort by WORD instead of name [possible values: size, time, version, extension]
 
+`-U`, `--no-sort`
+: Do not sort. List entries in directory order
+
 # ARGS
 
 `<FILE>...`
diff --git a/src/app.rs b/src/app.rs
index ccbf76fbc..00fff3798 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -158,6 +158,7 @@ pub fn build() -> App<'static, 'static> {
                 .overrides_with("extensionsort")
                 .overrides_with("versionsort")
                 .overrides_with("sort")
+                .overrides_with("no-sort")
                 .multiple(true)
                 .help("Sort by time modified"),
         )
@@ -169,6 +170,7 @@ pub fn build() -> App<'static, 'static> {
                 .overrides_with("extensionsort")
                 .overrides_with("versionsort")
                 .overrides_with("sort")
+                .overrides_with("no-sort")
                 .multiple(true)
                 .help("Sort by size"),
         )
@@ -180,6 +182,7 @@ pub fn build() -> App<'static, 'static> {
                 .overrides_with("timesort")
                 .overrides_with("versionsort")
                 .overrides_with("sort")
+                .overrides_with("no-sort")
                 .multiple(true)
                 .help("Sort by file extension"),
         )
@@ -192,21 +195,35 @@ pub fn build() -> App<'static, 'static> {
                 .overrides_with("sizesort")
                 .overrides_with("extensionsort")
                 .overrides_with("sort")
+                .overrides_with("no-sort")
                 .help("Natural sort of (version) numbers within text"),
         )
         .arg(
             Arg::with_name("sort")
                 .long("sort")
                 .multiple(true)
-                .possible_values(&["size", "time", "version", "extension"])
+                .possible_values(&["size", "time", "version", "extension", "none"])
                 .takes_value(true)
                 .value_name("WORD")
                 .overrides_with("timesort")
                 .overrides_with("sizesort")
                 .overrides_with("extensionsort")
                 .overrides_with("versionsort")
+                .overrides_with("no-sort")
                 .help("sort by WORD instead of name")
         )
+        .arg(
+            Arg::with_name("no-sort")
+            .short("U")
+            .long("no-sort")
+            .multiple(true)
+            .overrides_with("timesort")
+            .overrides_with("sizesort")
+            .overrides_with("extensionsort")
+            .overrides_with("sort")
+            .overrides_with("versionsort")
+            .help("Do not sort. List entries in directory order")
+        )
         .arg(
             Arg::with_name("reverse")
                 .short("r")
diff --git a/src/flags/sorting.rs b/src/flags/sorting.rs
index a568d7671..a791f93ca 100644
--- a/src/flags/sorting.rs
+++ b/src/flags/sorting.rs
@@ -37,6 +37,7 @@ impl Sorting {
 #[derive(Clone, Debug, Copy, PartialEq, Eq, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 pub enum SortColumn {
+    None,
     Extension,
     Name,
     Time,
@@ -62,6 +63,8 @@ impl Configurable<Self> for SortColumn {
             Some(Self::Extension)
         } else if matches.is_present("versionsort") || sort == Some("version") {
             Some(Self::Version)
+        } else if matches.is_present("no-sort") || sort == Some("none") {
+            Some(Self::None)
         } else {
             None
         }
@@ -263,6 +266,16 @@ mod test_sort_column {
         );
     }
 
+    #[test]
+    fn test_from_arg_matches_no_sort() {
+        let argv = vec!["lsd", "--no-sort"];
+        let matches = app::build().get_matches_from_safe(argv).unwrap();
+        assert_eq!(
+            Some(SortColumn::None),
+            SortColumn::from_arg_matches(&matches)
+        );
+    }
+
     #[test]
     fn test_from_arg_matches_sort() {
         let argv = vec!["lsd", "--sort", "time"];
@@ -292,6 +305,13 @@ mod test_sort_column {
             Some(SortColumn::Version),
             SortColumn::from_arg_matches(&matches)
         );
+
+        let argv = vec!["lsd", "--sort", "none"];
+        let matches = app::build().get_matches_from_safe(argv).unwrap();
+        assert_eq!(
+            Some(SortColumn::None),
+            SortColumn::from_arg_matches(&matches)
+        );
     }
 
     #[test]
diff --git a/src/sort.rs b/src/sort.rs
index 99812e588..a80d99084 100644
--- a/src/sort.rs
+++ b/src/sort.rs
@@ -16,14 +16,15 @@ pub fn assemble_sorters(flags: &Flags) -> Vec<(SortOrder, SortFn)> {
         }
         DirGrouping::None => {}
     };
-    let other_sort = match flags.sorting.column {
-        SortColumn::Name => by_name,
-        SortColumn::Size => by_size,
-        SortColumn::Time => by_date,
-        SortColumn::Version => by_version,
-        SortColumn::Extension => by_extension,
-    };
-    sorters.push((flags.sorting.order, other_sort));
+
+    match flags.sorting.column {
+        SortColumn::Name => sorters.push((flags.sorting.order, by_name)),
+        SortColumn::Size => sorters.push((flags.sorting.order, by_size)),
+        SortColumn::Time => sorters.push((flags.sorting.order, by_date)),
+        SortColumn::Version => sorters.push((flags.sorting.order, by_version)),
+        SortColumn::Extension => sorters.push((flags.sorting.order, by_extension)),
+        SortColumn::None => {}
+    }
     sorters
 }
 
@@ -295,4 +296,46 @@ mod tests {
         let sorter = assemble_sorters(&flags);
         assert_eq!(by_meta(&sorter, &meta_b, &meta_c), Ordering::Less);
     }
+
+    #[test]
+    fn test_sort_assemble_sorters_no_sort() {
+        let tmp_dir = tempdir().expect("failed to create temp dir");
+
+        let path_a = tmp_dir.path().join("aaa.aa");
+        File::create(&path_a).expect("failed to create file");
+        let meta_a = Meta::from_path(&path_a, false).expect("failed to get meta");
+
+        let path_b = tmp_dir.path().join("aaa");
+        create_dir(&path_b).expect("failed to create dir");
+        let meta_b = Meta::from_path(&path_b, false).expect("failed to get meta");
+
+        let path_c = tmp_dir.path().join("zzz.zz");
+        File::create(&path_c).expect("failed to create file");
+        let meta_c = Meta::from_path(&path_c, false).expect("failed to get meta");
+
+        let path_d = tmp_dir.path().join("zzz");
+        create_dir(&path_d).expect("failed to create dir");
+        let meta_d = Meta::from_path(&path_d, false).expect("failed to get meta");
+
+        let mut flags = Flags::default();
+        flags.sorting.column = SortColumn::None;
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_a, &meta_b), Ordering::Equal);
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_a, &meta_c), Ordering::Equal);
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_a, &meta_d), Ordering::Equal);
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_b, &meta_c), Ordering::Equal);
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_b, &meta_d), Ordering::Equal);
+
+        let sorter = assemble_sorters(&flags);
+        assert_eq!(by_meta(&sorter, &meta_c, &meta_d), Ordering::Equal);
+    }
 }


Test patch: