Repository: sharkdp/fd (language: rust)

Issue:
fd -l/--list-details doesn't work in busybox
**Describe the bug you encountered:**

Try to use `fd -l` in my specific case `fd --extension json --list-details`

```
ls: unrecognized option: human-readable
BusyBox v1.32.1 () multi-call binary.

Usage: ls [-1AaCxdLHRFplinshrSXvctu] [-w WIDTH] [FILE]...

List directory contents

	-1	One column output
	-a	Include entries which start with .
	-A	Like -a, but exclude . and ..
	-x	List by lines
	-d	List directory entries instead of contents
	-L	Follow symlinks
	-H	Follow symlinks on command line
	-R	Recurse
	-p	Append / to dir entries
	-F	Append indicator (one of */=@|) to entries
	-l	Long listing format
	-i	List inode numbers
	-n	List numeric UIDs and GIDs instead of names
	-s	List allocated blocks
	-lc	List ctime
	-lu	List atime
	--full-time	List full date and time
	-h	Human readable sizes (1K 243M 2G)
	--group-directories-first
	-S	Sort by size
	-X	Sort by extension
	-v	Sort by version
	-t	Sort by mtime
	-tc	Sort by ctime
	-tu	Sort by atime
	-r	Reverse sort order
	-w N	Format N columns wide
	--color[={always,never,auto}]	Control coloring
```

**Describe what you expected to happen:**
The correct long list

**What version of `fd` are you using?**
Installing fd (8.2.1-r0)

**Which operating system / distribution are you on?**
node:lts-alpine3.13
  Executing busybox-1.32.1-r6.trigger

GitHub action


Discussion / hints:
Thank you for reporting this.

We already do some guesswork to call `ls`/`gls` with the correct arguments:

https://github.com/sharkdp/fd/blob/f60b7687a2f189dfc4009b23e5af6b6049dbd1b5/src/main.rs#L194-L266

... but we don't have a specialized option for the busybox version of `ls`. And I'm not sure if we could detect that somehow. We might need to parse the output of `ls --version` (or similar) in order to distinguish different implementations.
Yeah, alternatively, as a simpler option, are the short `-l -h -d` all standard on Linux? Would using them instead of the long names be an easier fix?

This run as mentioned was on a GitHub action, so fixing detection and ensuring no regression should be fairly easy at least.
Using `-l -h -d` would work for GNU ls, yes. I like the `--long-options` for self-documenting purposes, but if this would really fix the problem on busybox, I'm okay to change it.
> I like the `--long-options` for self-documenting purposes

Makes sense.

> but if this would really fix the problem on busybox, I'm okay to change it.

Well they were certainly reported in the help on the GitHub actions run as above, I wonder if they just don't bother with the complexity of long parsing in BusyBox.
from the man page of busybox it does appear that `-l -h -d` would work. And according to https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/ the short options are posix standard, whereas the long options are not.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9d98d616..35ba6b6f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
 - fd doesn't show substituted drive on Windows, see #365
 - Properly handle write errors to devices that are full, see #737
 - Use local time zone for time functions (`--change-newer-than`, `--change-older-than`), see #631 (@jacobmischka)
+- Support `--list-details` on more platforms (like BusyBox), see #783
 
 ## Changes
 
diff --git a/src/main.rs b/src/main.rs
index 8654688ad..7acba8898 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,8 +20,8 @@ use anyhow::{anyhow, Context, Result};
 use atty::Stream;
 use globset::GlobBuilder;
 use lscolors::LsColors;
-use regex::bytes::{RegexBuilder, RegexSetBuilder};
 use normpath::PathExt;
+use regex::bytes::{RegexBuilder, RegexSetBuilder};
 
 use crate::error::print_error;
 use crate::exec::CommandTemplate;
@@ -210,11 +210,13 @@ fn run() -> Result<ExitCode> {
 
         #[allow(unused)]
         let gnu_ls = |command_name| {
+            // Note: we use short options here (instead of --long-options) to support more
+            // platforms (like BusyBox).
             vec![
                 command_name,
-                "-l",               // long listing format
-                "--human-readable", // human readable file sizes
-                "--directory",      // list directories themselves, not their contents
+                "-l", // long listing format
+                "-h", // human readable file sizes
+                "-d", // list directories themselves, not their contents
                 &color_arg,
             ]
         };


Test patch: