1
0
mirror of https://github.com/sharkdp/fd synced 2024-07-05 09:19:11 +00:00

Add -l/--list option

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)
This commit is contained in:
sharkdp 2020-04-02 21:40:57 +02:00 committed by David Peter
parent 1714d416e2
commit da5cd12b24
4 changed files with 50 additions and 4 deletions

View File

@ -2,7 +2,14 @@
## Features ## Features
- Added `--max-results=<count>` 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=<count>` 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. 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 <count>` where `fd` can only Using this option is also (slightly) faster than piping to `head -n <count>` where `fd` can only
exit when it finds the search results `<count> + 1`. exit when it finds the search results `<count> + 1`.

6
doc/fd.1 vendored
View File

@ -66,6 +66,12 @@ Treat the pattern as a literal string instead of a regular expression.
.B \-a, \-\-absolute\-path .B \-a, \-\-absolute\-path
Shows the full path starting from the root as opposed to relative paths. Shows the full path starting from the root as opposed to relative paths.
.TP .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 .B \-L, \-\-follow
By default, fd does not descend into symlinked directories. Using this flag, symbolic links are By default, fd does not descend into symlinked directories. Using this flag, symbolic links are
also traversed. also traversed.

View File

@ -108,6 +108,12 @@ pub fn build_app() -> App<'static, 'static> {
.short("a") .short("a")
.overrides_with("absolute-path"), .overrides_with("absolute-path"),
) )
.arg(
arg("list")
.long("list")
.short("l")
.conflicts_with("absolute-path"),
)
.arg( .arg(
arg("follow") arg("follow")
.long("follow") .long("follow")
@ -125,7 +131,8 @@ pub fn build_app() -> App<'static, 'static> {
arg("null_separator") arg("null_separator")
.long("print0") .long("print0")
.short("0") .short("0")
.overrides_with("print0"), .overrides_with("print0")
.conflicts_with("list"),
) )
.arg(arg("depth").long("max-depth").short("d").takes_value(true)) .arg(arg("depth").long("max-depth").short("d").takes_value(true))
// support --maxdepth as well, for compatibility with rg // support --maxdepth as well, for compatibility with rg
@ -173,7 +180,8 @@ pub fn build_app() -> App<'static, 'static> {
.min_values(1) .min_values(1)
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_terminator(";") .value_terminator(";")
.value_name("cmd"), .value_name("cmd")
.conflicts_with("list"),
) )
.arg( .arg(
arg("exec-batch") arg("exec-batch")
@ -183,7 +191,7 @@ pub fn build_app() -> App<'static, 'static> {
.allow_hyphen_values(true) .allow_hyphen_values(true)
.value_terminator(";") .value_terminator(";")
.value_name("cmd") .value_name("cmd")
.conflicts_with("exec"), .conflicts_with_all(&["exec", "list"]),
) )
.arg( .arg(
arg("exclude") arg("exclude")
@ -343,6 +351,12 @@ fn usage() -> HashMap<&'static str, Help> {
doc!(h, "absolute-path" doc!(h, "absolute-path"
, "Show absolute instead of relative paths" , "Show absolute instead of relative paths"
, "Shows the full path starting from the root as opposed to 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" doc!(h, "path-separator"
, "Set the path separator to use when printing file paths." , "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 \ , "Set the path separator to use when printing file paths. The default is the OS-specific \

View File

@ -165,6 +165,25 @@ fn main() {
print_error_and_exit!("{}", e); 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<SizeFilter> = matches let size_limits: Vec<SizeFilter> = matches