mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-18 01:40:34 +01:00
Merge pull request #861 from jcaplan/no-strip/760
show "./" prefix when search path provided
This commit is contained in:
commit
b211ded5de
7 changed files with 425 additions and 378 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
## Bugfixes
|
||||
|
||||
- Always show the `./` prefix for search results unless the output is a TTY or `--strip-cwd-prefix` is set, see #760 and #861 (@jcaplan)
|
||||
- Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)
|
||||
- fd cannot search files under a RAM disk, see #752
|
||||
- fd doesn't show substituted drive on Windows, see #365
|
||||
|
|
11
src/app.rs
11
src/app.rs
|
@ -704,6 +704,17 @@ pub fn build_app() -> App<'static, 'static> {
|
|||
argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \
|
||||
--search-path <path2> [<pattern>]`",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("strip-cwd-prefix")
|
||||
.long("strip-cwd-prefix")
|
||||
.conflicts_with_all(&["path", "search-path"])
|
||||
.hidden_short_help(true)
|
||||
.help("strip './' prefix from non-tty outputs")
|
||||
.long_help(
|
||||
"By default, relative paths are prefixed with './' when the output goes to a non \
|
||||
interactive terminal (TTY). Use this flag to disable this behaviour."
|
||||
)
|
||||
);
|
||||
|
||||
if cfg!(unix) {
|
||||
|
|
|
@ -113,4 +113,7 @@ pub struct Config {
|
|||
|
||||
/// The maximum number of search results
|
||||
pub max_results: Option<usize>,
|
||||
|
||||
/// Whether or not to strip the './' prefix for search results
|
||||
pub strip_cwd_prefix: bool,
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ use once_cell::sync::Lazy;
|
|||
use regex::Regex;
|
||||
|
||||
use crate::exit_codes::ExitCode;
|
||||
use crate::filesystem::strip_current_dir;
|
||||
|
||||
use self::command::execute_command;
|
||||
use self::input::{basename, dirname, remove_extension};
|
||||
|
@ -144,8 +143,6 @@ impl CommandTemplate {
|
|||
out_perm: Arc<Mutex<()>>,
|
||||
buffer_output: bool,
|
||||
) -> ExitCode {
|
||||
let input = strip_current_dir(input);
|
||||
|
||||
let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref()));
|
||||
for arg in &self.args[1..] {
|
||||
cmd.arg(arg.generate(&input, self.path_separator.as_deref()));
|
||||
|
@ -177,7 +174,7 @@ impl CommandTemplate {
|
|||
// A single `Tokens` is expected
|
||||
// So we can directly consume the iterator once and for all
|
||||
for path in &mut paths {
|
||||
cmd.arg(arg.generate(strip_current_dir(path), self.path_separator.as_deref()));
|
||||
cmd.arg(arg.generate(path, self.path_separator.as_deref()));
|
||||
has_path = true;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -380,6 +380,9 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
|
|||
None
|
||||
}
|
||||
}),
|
||||
strip_cwd_prefix: (!matches.is_present("path")
|
||||
&& !matches.is_present("search-path")
|
||||
&& (interactive_terminal || matches.is_present("strip-cwd-prefix"))),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ pub fn print_entry(
|
|||
config: &Config,
|
||||
wants_to_quit: &Arc<AtomicBool>,
|
||||
) {
|
||||
let path = if entry.is_absolute() {
|
||||
entry
|
||||
} else {
|
||||
let path = if config.strip_cwd_prefix {
|
||||
strip_current_dir(entry)
|
||||
} else {
|
||||
entry
|
||||
};
|
||||
|
||||
let r = if let Some(ref ls_colors) = config.ls_colors {
|
||||
|
|
774
tests/tests.rs
774
tests/tests.rs
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue