diff --git a/CHANGELOG.md b/CHANGELOG.md index ce93757..82ae9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ ## Features -- Added `--max-results=` option to limit the number of search results, see #472 and #476 +- Add a new `-l`/`--list` option to show more details about the search results. This is basically + an alias for `--exec-batch ls -l` with some additional `ls` options. + This can be used in order to: + * see metadata like permissions, owner, file size, modification times (#491) + * see symlink targets (#482) + * achieve a deterministic output order (#324, #196, #159) + * avoid duplicate search results when multiple search paths are given (#405) +- Add a new `--max-results=` option to limit the number of search results, see #472 and #476 This can be useful to speed up searches in cases where you know that there are only N results. Using this option is also (slightly) faster than piping to `head -n ` where `fd` can only exit when it finds the search results ` + 1`. diff --git a/doc/fd.1 b/doc/fd.1 index 8bb2eff..974a4f4 100644 --- a/doc/fd.1 +++ b/doc/fd.1 @@ -66,6 +66,12 @@ Treat the pattern as a literal string instead of a regular expression. .B \-a, \-\-absolute\-path Shows the full path starting from the root as opposed to relative paths. .TP +.B \-l, \-\-list +Use a detailed listing format like 'ls -l'. This is basically an alias +for '--exec-batch ls -l' with some additional 'ls' options. This can be used +to see more metadata, to show symlink targets, to achieve a deterministic +sort order and to avoid duplicate search results when using multiple search paths. +.TP .B \-L, \-\-follow By default, fd does not descend into symlinked directories. Using this flag, symbolic links are also traversed. diff --git a/src/app.rs b/src/app.rs index 57156e1..4a391f5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -108,6 +108,12 @@ pub fn build_app() -> App<'static, 'static> { .short("a") .overrides_with("absolute-path"), ) + .arg( + arg("list") + .long("list") + .short("l") + .conflicts_with("absolute-path"), + ) .arg( arg("follow") .long("follow") @@ -125,7 +131,8 @@ pub fn build_app() -> App<'static, 'static> { arg("null_separator") .long("print0") .short("0") - .overrides_with("print0"), + .overrides_with("print0") + .conflicts_with("list"), ) .arg(arg("depth").long("max-depth").short("d").takes_value(true)) // support --maxdepth as well, for compatibility with rg @@ -173,7 +180,8 @@ pub fn build_app() -> App<'static, 'static> { .min_values(1) .allow_hyphen_values(true) .value_terminator(";") - .value_name("cmd"), + .value_name("cmd") + .conflicts_with("list"), ) .arg( arg("exec-batch") @@ -183,7 +191,7 @@ pub fn build_app() -> App<'static, 'static> { .allow_hyphen_values(true) .value_terminator(";") .value_name("cmd") - .conflicts_with("exec"), + .conflicts_with_all(&["exec", "list"]), ) .arg( arg("exclude") @@ -343,6 +351,12 @@ fn usage() -> HashMap<&'static str, Help> { doc!(h, "absolute-path" , "Show absolute instead of relative paths" , "Shows the full path starting from the root as opposed to relative paths."); + doc!(h, "list" + , "Use a detailed listing format" + , "Use a detailed listing format like 'ls -l'. This is basically an alias \ + for '--exec-batch ls -l' with some additional 'ls' options. This can be used \ + to see more metadata, to show symlink targets, to achieve a deterministic \ + sort order and to avoid duplicate search results when using multiple search paths."); doc!(h, "path-separator" , "Set the path separator to use when printing file paths." , "Set the path separator to use when printing file paths. The default is the OS-specific \ diff --git a/src/main.rs b/src/main.rs index f3750fe..cbf90f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -165,6 +165,25 @@ fn main() { print_error_and_exit!("{}", e); }) }) + }) + .or_else(|| { + if matches.is_present("list") { + let color = matches.value_of("color").unwrap_or("auto"); + let color_arg = ["--color=", color].concat(); + + Some( + CommandTemplate::new_batch(&[ + "ls", + "-l", // long listing format + "--human-readable", // human readable file sizes + "--directory", // list directories themselves, not their contents + &color_arg, // enable colorized output, if enabled + ]) + .unwrap(), + ) + } else { + None + } }); let size_limits: Vec = matches