Skip to content
Myr

Merge pull request #1445 from tmccombs/cwd-prefix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Thayne McCombs · committed by GitHub · parents 1a1f057, 90d3381 · Browse files · 5 files+41 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • feat: Add option to always include cwd prefix

Diff stats

5 files+41 added−9 removed

  • other:+41 added−9 removed

5 files+41 added−9 removed

modified:contrib/completion/_fd+1 added-1 removed
160 unmodified lines
161 $no'(--base-directory)--base-directory=[change the current working directory to the given path]:directory:_files -/'162 $no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'163164 + strip-cwd-prefix165 $no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix[Strip ./ prefix when output is redirected]'165 $no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix=[When to strip ./]:when:(always never auto)'166167 + and168 '--and=[additional required search path]:pattern'169
114 unmodified lines
modified:doc/fd.1+14 added-3 removed
154 unmodified lines
155.B \-\-show-errors156Enable the display of filesystem errors for situations such as insufficient157permissions or dead symlinks.158.TP159.B \-\-strip-cwd-prefix160By default, relative paths are prefixed with './' when the output goes to a non interactive terminal161(TTY). Use this flag to disable this behaviour.159.B \-\-strip-cwd-prefix [when]160By default, relative paths are prefixed with './' when -x/--exec,161-X/--exec-batch, or -0/--print0 are given, to reduce the risk of a162path starting with '-' being treated as a command line option. Use163this flag to change this behavior. If this flag is used without a value,164it is equivalent to passing "always". Possible values are:165.RS166.IP never167Never strip the ./ at the beginning of paths168.IP always169Always strip the ./ at the beginning of paths170.IP auto171Only strip if used with --exec, --exec-batch, or --print0. That is, it resets to the default behavior.172.RE173.TP174.B \-\-one\-file\-system, \-\-mount, \-\-xdev175By default, fd will traverse the file system tree as far as other options dictate. With this flag, fd ensures that it does not descend into a different file system than the one it started in. Comparable to the -mount or -xdev filters of find(1).176.TP
366 unmodified lines
modified:src/cli.rs+24 added-3 removed
615 unmodified lines
616617 /// By default, relative paths are prefixed with './' when -x/--exec,618 /// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a619 /// path starting with '-' being treated as a command line option. Use620 /// this flag to disable this behaviour.621 #[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]622 pub strip_cwd_prefix: bool,620 /// this flag to change this behavior. If this flag is used without a value,621 /// it is equivalent to passing "always".622 #[arg(long, conflicts_with_all(&["path", "search_path"]), value_name = "when", hide_short_help = true, require_equals = true, long_help)]623 strip_cwd_prefix: Option<Option<StripCwdWhen>>,624625 /// By default, fd will traverse the file system tree as far as other options626 /// dictate. With this flag, fd ensures that it does not descend into a627 /// different file system than the one it started in. Comparable to the -mount
72 unmodified lines
700 .filter(|&m| m > 0)701 .or_else(|| self.max_one_result.then_some(1))702 }703704 pub fn strip_cwd_prefix<P: FnOnce() -> bool>(&self, auto_pred: P) -> bool {705 use self::StripCwdWhen::*;706 self.no_search_paths()707 && match self.strip_cwd_prefix.map_or(Auto, |o| o.unwrap_or(Always)) {708 Auto => auto_pred(),709 Always => true,710 Never => false,711 }712 }713714 #[cfg(feature = "completions")]715 pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {716 self.gen_completions717 .map(|maybe_shell| match maybe_shell {
52 unmodified lines
770 /// do not use colorized output771 Never,772}773774#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]775pub enum StripCwdWhen {776 /// Use the default behavior777 Auto,778 /// Always strip the ./ at the beginning of paths779 Always,780 /// Never strip the ./781 Never,782}783784// there isn't a derive api for getting grouped values yet,785// so we have to use hand-rolled parsing for exec and exec-batch786pub struct Exec {787 pub command: Option<CommandSet>,
110 unmodified lines
modified:src/main.rs+1 added-2 removed
309 unmodified lines
310 show_filesystem_errors: opts.show_errors,311 path_separator,312 actual_path_separator,313 max_results: opts.max_results(),314 strip_cwd_prefix: (opts.no_search_paths()315 && (opts.strip_cwd_prefix || !(opts.null_separator || has_command))),314 strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),315 })316}317318fn extract_command(opts: &mut Opts, colored_output: bool) -> Result<Option<CommandSet>> {
160 unmodified lines
modified:CHANGELOG.md+1 added
1# Upcoming release23## Features45- Allow passing an optional argument to `--strip-cwd-prefix` of "always", "never", or "auto". to force whether the cwd prefix is stripped or not.67## Bugfixes89
760 unmodified lines