Skip to content

Commit

Permalink
Add -l/--list option
Browse files Browse the repository at this point in the history
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 determinstic output order (#324, #196, #159)
    * avoid duplicate search results when multiple search paths are given (#405)
  • Loading branch information
sharkdp committed Apr 2, 2020
1 parent 1714d41 commit 6cb2f88
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

## 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 determinstic 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.
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`.
Expand Down
6 changes: 6 additions & 0 deletions doc/fd.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 17 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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 \
Expand Down
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SizeFilter> = matches
Expand Down

0 comments on commit 6cb2f88

Please sign in to comment.