mirror of
https://github.com/sharkdp/fd
synced 2024-10-02 22:13:31 +00:00
Add alias -1 for --max-results=1
This commit is contained in:
parent
95eae00126
commit
2bab4a2249
|
@ -12,6 +12,7 @@
|
|||
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`.
|
||||
- Add the alias `-1` for `--max-results=1`, see #561. (@SimplyDanny).
|
||||
- Support additional ANSI font styles in `LS_COLORS`: faint, slow blink, rapid blink, dimmed, hidden and strikethrough.
|
||||
|
||||
## Bugfixes
|
||||
|
|
3
doc/fd.1
vendored
3
doc/fd.1
vendored
|
@ -89,6 +89,9 @@ Separate search results by the null character (instead of newlines). Useful for
|
|||
.B \-\-max\-results count
|
||||
Limit the number of search results to 'count' and quit immediately.
|
||||
.TP
|
||||
.B \-1
|
||||
Limit the search to a single result and quit immediately. This is an alias for '--max-results=1'.
|
||||
.TP
|
||||
.B \-\-show-errors
|
||||
Enable the display of filesystem errors for situations such as insufficient
|
||||
permissions or dead symlinks.
|
||||
|
|
|
@ -415,6 +415,15 @@ pub fn build_app() -> App<'static, 'static> {
|
|||
.hidden_short_help(true)
|
||||
.long_help("Limit the number of search results to 'count' and quit immediately."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("max-one-result")
|
||||
.short("1")
|
||||
.hidden_short_help(true)
|
||||
.overrides_with("max-results")
|
||||
.conflicts_with_all(&["exec", "exec-batch"])
|
||||
.long_help("Limit the search to a single result and quit immediately. \
|
||||
This is an alias for '--max-results=1'.")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("show-errors")
|
||||
.long("show-errors")
|
||||
|
|
|
@ -295,7 +295,8 @@ fn run() -> Result<ExitCode> {
|
|||
max_results: matches
|
||||
.value_of("max-results")
|
||||
.and_then(|n| usize::from_str_radix(n, 10).ok())
|
||||
.filter(|&n| n != 0),
|
||||
.filter(|&n| n != 0)
|
||||
.or_else(|| if matches.is_present("max-one-result") { Some(1) } else { None }),
|
||||
};
|
||||
|
||||
let re = RegexBuilder::new(&pattern_regex)
|
||||
|
|
|
@ -1458,11 +1458,15 @@ fn test_max_results() {
|
|||
);
|
||||
|
||||
// Limited to one result. We could find either C.Foo2 or c.foo
|
||||
let output = te.assert_success_and_get_output(".", &["--max-results=1", "c.foo"]);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stdout = stdout.trim();
|
||||
let stdout = stdout.replace(&std::path::MAIN_SEPARATOR.to_string(), "/");
|
||||
let assert_just_one_result_with_option = |option| {
|
||||
let output = te.assert_success_and_get_output(".", &[option, "c.foo"]);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout)
|
||||
.trim()
|
||||
.replace(&std::path::MAIN_SEPARATOR.to_string(), "/");
|
||||
assert!(stdout == "one/two/C.Foo2" || stdout == "one/two/c.foo");
|
||||
};
|
||||
assert_just_one_result_with_option("--max-results=1");
|
||||
assert_just_one_result_with_option("-1");
|
||||
}
|
||||
|
||||
/// Filenames with non-utf8 paths are passed to the executed program unchanged
|
||||
|
|
Loading…
Reference in a new issue