mirror of
https://github.com/sharkdp/fd.git
synced 2024-10-01 14:31:29 +02:00
add -N/--no-strip option to show "./" prefix on relative paths
This commit is contained in:
parent
7b5b3ec47b
commit
6b92c5db90
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
- Add new `--no-ignore-parent` flag, see #787 (@will459)
|
- Add new `--no-ignore-parent` flag, see #787 (@will459)
|
||||||
|
|
||||||
|
- Add new `-N, --no-strip` flag, see #760 (@jcaplan)
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
||||||
- Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)
|
- Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)
|
||||||
|
11
src/app.rs
11
src/app.rs
@ -615,6 +615,17 @@ pub fn build_app() -> App<'static, 'static> {
|
|||||||
argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \
|
argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \
|
||||||
--search-path <path2> [<pattern>]`",
|
--search-path <path2> [<pattern>]`",
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("no-strip")
|
||||||
|
.long("no-strip")
|
||||||
|
.short("N")
|
||||||
|
.conflicts_with_all(&["absolute-path", "list-details"])
|
||||||
|
.help("Show all non-absolute paths with './' prefix")
|
||||||
|
.long_help(
|
||||||
|
"Show all non-absolute paths with './' prefix. This flag only affects \
|
||||||
|
the output when no search path is provided.")
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
|
@ -109,4 +109,7 @@ pub struct Config {
|
|||||||
|
|
||||||
/// The maximum number of search results
|
/// The maximum number of search results
|
||||||
pub max_results: Option<usize>,
|
pub max_results: Option<usize>,
|
||||||
|
|
||||||
|
/// Whether to prefix each relative path with "./"
|
||||||
|
pub no_strip: bool,
|
||||||
}
|
}
|
||||||
|
@ -375,6 +375,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
no_strip: matches.is_present("no-strip"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ pub fn print_entry(
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
wants_to_quit: &Arc<AtomicBool>,
|
wants_to_quit: &Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
let path = if entry.is_absolute() {
|
let path = if entry.is_absolute() || config.no_strip {
|
||||||
entry
|
entry
|
||||||
} else {
|
} else {
|
||||||
strip_current_dir(entry)
|
strip_current_dir(entry)
|
||||||
|
@ -1901,3 +1901,40 @@ fn test_error_if_hidden_not_set_and_pattern_starts_with_dot() {
|
|||||||
te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore");
|
te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore");
|
||||||
te.assert_output(&[".gitignore"], "");
|
te.assert_output(&[".gitignore"], "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show "./" prefix if the --no-strip flag is provided
|
||||||
|
#[test]
|
||||||
|
fn test_no_strip() {
|
||||||
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
te.assert_output(
|
||||||
|
&["--no-strip"],
|
||||||
|
"./a.foo
|
||||||
|
./e1 e2
|
||||||
|
./one
|
||||||
|
./one/b.foo
|
||||||
|
./one/two
|
||||||
|
./one/two/c.foo
|
||||||
|
./one/two/C.Foo2
|
||||||
|
./one/two/three
|
||||||
|
./one/two/three/d.foo
|
||||||
|
./one/two/three/directory_foo
|
||||||
|
./symlink"
|
||||||
|
);
|
||||||
|
|
||||||
|
te.assert_output(
|
||||||
|
&["--no-strip", "foo", "./one"],
|
||||||
|
"./one/b.foo
|
||||||
|
./one/two/c.foo
|
||||||
|
./one/two/C.Foo2
|
||||||
|
./one/two/three/d.foo
|
||||||
|
./one/two/three/directory_foo"
|
||||||
|
);
|
||||||
|
te.assert_output(
|
||||||
|
&["--no-strip", "foo", "one"],
|
||||||
|
"one/b.foo
|
||||||
|
one/two/c.foo
|
||||||
|
one/two/C.Foo2
|
||||||
|
one/two/three/d.foo
|
||||||
|
one/two/three/directory_foo"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user