Merge pull request #861 from jcaplan/no-strip/760

show "./" prefix when search path provided
This commit is contained in:
David Peter 2021-11-26 19:27:44 +01:00 committed by GitHub
commit b211ded5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 425 additions and 378 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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,
}

View File

@ -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 {

View File

@ -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"))),
})
}

View File

@ -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 {

File diff suppressed because it is too large Load Diff