Skip to content

Commit

Permalink
feat: Add option to always include cwd prefix
Browse files Browse the repository at this point in the history
Fixes: #1243
Fixes: #1331
  • Loading branch information
tmccombs committed Dec 6, 2023
1 parent 74b850a commit 9121245
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion contrib/completion/_fd
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ _fd() {
$no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'

+ strip-cwd-prefix
$no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix[Strip ./ prefix when output is redirected]'
$no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix[Strip ./ prefix unconditionally]'
$no'(abs-path)--cwd-prefix[Include ./ prefix unconditionally]'

+ and
'--and=[additional required search path]:pattern'
Expand Down
11 changes: 9 additions & 2 deletions doc/fd.1
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,15 @@ Enable the display of filesystem errors for situations such as insufficient
permissions or dead symlinks.
.TP
.B \-\-strip-cwd-prefix
By default, relative paths are prefixed with './' when the output goes to a non interactive terminal
(TTY). Use this flag to disable this behaviour.
By default, relative paths are prefixed with './' when -x/--exec,
-X/--exec-batch, or -0/--print0 are given, to reduce the risk of a
path starting with '-' being treated as a command line option. Use
this flag to disable this behaviour.
.TP
.B \-\-cwd\-prefix
Force including the './' prefix for relative paths. By default, this
is not included unless using --exec, --exec-batch, or --print0. But with
this option, the prefix is never stripped.
.TP
.B \-\-one\-file\-system, \-\-mount, \-\-xdev
By 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).
Expand Down
12 changes: 12 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ pub struct Opts {
#[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]
pub strip_cwd_prefix: bool,

/// Force including the './' prefix for relative paths. By default, this
/// is not included unless using --exec, --exec-batch, or --print0. But with
/// this option, the prefix is never stripped.
#[arg(
long,
hide_short_help = true,
conflicts_with("absolute_path"),
overrides_with("strip_cwd_prefix"),
long_help
)]
pub cwd_prefix: bool,

/// By 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
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
actual_path_separator,
max_results: opts.max_results(),
strip_cwd_prefix: (opts.no_search_paths()
&& !opts.cwd_prefix
&& (opts.strip_cwd_prefix || !(opts.null_separator || has_command))),
})
}
Expand Down

0 comments on commit 9121245

Please sign in to comment.