mirror of https://github.com/sharkdp/fd.git
Compare commits
23 Commits
4115cc9736
...
447edc7604
Author | SHA1 | Date |
---|---|---|
Thayne McCombs | 447edc7604 | |
Thayne McCombs | 11e328cecd | |
Thayne McCombs | cd96ca071d | |
Tavian Barnes | 216472ff9f | |
Thayne McCombs | 3680d10e5c | |
dependabot[bot] | abe3b9cd78 | |
Thayne McCombs | 7aad6c9edf | |
Thayne McCombs | ddd3aae249 | |
dependabot[bot] | 6d3bb68faf | |
dependabot[bot] | 21d50dae8c | |
David Peter | 9279b1f0af | |
Thayne McCombs | 6647085015 | |
Thayne McCombs | 6af8f092ee | |
Thayne McCombs | c4094c7a05 | |
AlbydS | 6d58df5f0c | |
AlbydS | ffecccf209 | |
Thayne McCombs | 31f2839751 | |
Thayne McCombs | e10a4eab2b | |
Thayne McCombs | 8eb047945e | |
Tavian Barnes | 1031325cca | |
Tavian Barnes | 9fc2167cf9 | |
Jian Wang | f875ea9a52 | |
AlbydS | d651a595d4 |
|
@ -134,7 +134,11 @@ jobs:
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
|
run: |
|
||||||
|
case ${{ matrix.job.target }} in
|
||||||
|
aarch64-*) export JEMALLOC_SYS_WITH_LG_PAGE=16 ;;
|
||||||
|
esac;
|
||||||
|
$BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
|
||||||
|
|
||||||
- name: Set binary name & path
|
- name: Set binary name & path
|
||||||
id: bin
|
id: bin
|
||||||
|
|
|
@ -4,10 +4,17 @@
|
||||||
|
|
||||||
- Add `dir` as an alias to `directory` when using `-t` \ `--type`, see #1460 and #1464 (@Ato2207).
|
- Add `dir` as an alias to `directory` when using `-t` \ `--type`, see #1460 and #1464 (@Ato2207).
|
||||||
- Add support for @%s date format in time filters similar to GNU date (seconds since Unix epoch for --older/--newer), see #1493 (@nabellows)
|
- Add support for @%s date format in time filters similar to GNU date (seconds since Unix epoch for --older/--newer), see #1493 (@nabellows)
|
||||||
|
- Breaking: No longer automatically ignore `.git` when using `--hidden` with vcs ignore enabled. This reverts the change in v9.0.0. While this feature
|
||||||
|
was often useful, it also broke some existing workflows, and there wasn't a good way to opt out of it. And there isn't really a good way for us to add
|
||||||
|
a way to opt out of it. And you can easily get similar behavior by adding `.git/` to your global fdignore file.
|
||||||
|
See #1457.
|
||||||
|
- Allow passing an optional argument to `--strip-cwd-prefix` of "always", "never", or "auto". to force whether the cwd prefix is stripped or not.
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
||||||
- Respect NO_COLOR environment variable with `--list-details` option. (#1455)
|
- Respect NO_COLOR environment variable with `--list-details` option. (#1455)
|
||||||
|
- Fix bug that would cause hidden files to be included despite gitignore rules
|
||||||
|
if search path is "." (#1461, BurntSushi/ripgrep#2711).
|
||||||
|
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
|
@ -145,9 +145,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.37"
|
version = "0.4.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
|
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
@ -327,7 +327,7 @@ dependencies = [
|
||||||
"jemallocator",
|
"jemallocator",
|
||||||
"libc",
|
"libc",
|
||||||
"lscolors",
|
"lscolors",
|
||||||
"nix 0.27.1",
|
"nix 0.28.0",
|
||||||
"normpath",
|
"normpath",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"regex",
|
"regex",
|
||||||
|
@ -459,9 +459,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.153"
|
version = "0.2.154"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
|
@ -501,17 +501,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.27.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.5.0",
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.28.0"
|
version = "0.28.0"
|
||||||
|
|
|
@ -55,7 +55,7 @@ version = "4.4.13"
|
||||||
features = ["suggestions", "color", "wrap_help", "cargo", "derive"]
|
features = ["suggestions", "color", "wrap_help", "cargo", "derive"]
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
version = "0.4.34"
|
version = "0.4.38"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["std", "clock"]
|
features = ["std", "clock"]
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ default-features = false
|
||||||
features = ["nu-ansi-term"]
|
features = ["nu-ansi-term"]
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
nix = { version = "0.27.1", default-features = false, features = ["signal", "user"] }
|
nix = { version = "0.28.0", default-features = false, features = ["signal", "user"] }
|
||||||
|
|
||||||
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
|
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
29
README.md
29
README.md
|
@ -282,6 +282,9 @@ If you want `fd` to ignore these patterns globally, you can put them in `fd`'s g
|
||||||
This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in
|
This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in
|
||||||
Windows.
|
Windows.
|
||||||
|
|
||||||
|
You may wish to include `.git/` in your `fd/ignore` file so that `.git` directories, and their contents
|
||||||
|
are not included in output if you use the `--hidden` option.
|
||||||
|
|
||||||
### Deleting files
|
### Deleting files
|
||||||
|
|
||||||
You can use `fd` to remove all files and directories that are matched by your search pattern.
|
You can use `fd` to remove all files and directories that are matched by your search pattern.
|
||||||
|
@ -533,7 +536,7 @@ newlines). In the same way, the `-0` option of `xargs` tells it to read the inpu
|
||||||
If you run Ubuntu 19.04 (Disco Dingo) or newer, you can install the
|
If you run Ubuntu 19.04 (Disco Dingo) or newer, you can install the
|
||||||
[officially maintained package](https://packages.ubuntu.com/fd-find):
|
[officially maintained package](https://packages.ubuntu.com/fd-find):
|
||||||
```
|
```
|
||||||
sudo apt install fd-find
|
apt install fd-find
|
||||||
```
|
```
|
||||||
Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.
|
Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.
|
||||||
It is recommended that after installation, you add a link to `fd` by executing command
|
It is recommended that after installation, you add a link to `fd` by executing command
|
||||||
|
@ -543,7 +546,7 @@ Make sure that `$HOME/.local/bin` is in your `$PATH`.
|
||||||
If you use an older version of Ubuntu, you can download the latest `.deb` package from the
|
If you use an older version of Ubuntu, you can download the latest `.deb` package from the
|
||||||
[release page](https://github.com/sharkdp/fd/releases) and install it via:
|
[release page](https://github.com/sharkdp/fd/releases) and install it via:
|
||||||
``` bash
|
``` bash
|
||||||
sudo dpkg -i fd_9.0.0_amd64.deb # adapt version number and architecture
|
dpkg -i fd_9.0.0_amd64.deb # adapt version number and architecture
|
||||||
```
|
```
|
||||||
|
|
||||||
### On Debian
|
### On Debian
|
||||||
|
@ -551,7 +554,7 @@ sudo dpkg -i fd_9.0.0_amd64.deb # adapt version number and architecture
|
||||||
If you run Debian Buster or newer, you can install the
|
If you run Debian Buster or newer, you can install the
|
||||||
[officially maintained Debian package](https://tracker.debian.org/pkg/rust-fd-find):
|
[officially maintained Debian package](https://tracker.debian.org/pkg/rust-fd-find):
|
||||||
```
|
```
|
||||||
sudo apt-get install fd-find
|
apt-get install fd-find
|
||||||
```
|
```
|
||||||
Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.
|
Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.
|
||||||
It is recommended that after installation, you add a link to `fd` by executing command
|
It is recommended that after installation, you add a link to `fd` by executing command
|
||||||
|
@ -579,6 +582,8 @@ You can install [the fd package](https://www.archlinux.org/packages/community/x8
|
||||||
```
|
```
|
||||||
pacman -S fd
|
pacman -S fd
|
||||||
```
|
```
|
||||||
|
You can also install fd [from the AUR](https://aur.archlinux.org/packages/fd-git).
|
||||||
|
|
||||||
### On Gentoo Linux
|
### On Gentoo Linux
|
||||||
|
|
||||||
You can use [the fd ebuild](https://packages.gentoo.org/packages/sys-apps/fd) from the official repo:
|
You can use [the fd ebuild](https://packages.gentoo.org/packages/sys-apps/fd) from the official repo:
|
||||||
|
@ -600,6 +605,20 @@ You can install `fd` via xbps-install:
|
||||||
xbps-install -S fd
|
xbps-install -S fd
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### On ALT Linux
|
||||||
|
|
||||||
|
You can install [the fd package](https://packages.altlinux.org/en/sisyphus/srpms/fd/) from the official repo:
|
||||||
|
```
|
||||||
|
apt-get install fd
|
||||||
|
```
|
||||||
|
|
||||||
|
### On Solus
|
||||||
|
|
||||||
|
You can install [the fd package](https://github.com/getsolus/packages/tree/main/packages/f/fd) from the official repo:
|
||||||
|
```
|
||||||
|
eopkg install fd
|
||||||
|
```
|
||||||
|
|
||||||
### On RedHat Enterprise Linux 8/9 (RHEL8/9), Almalinux 8/9, EuroLinux 8/9 or Rocky Linux 8/9
|
### On RedHat Enterprise Linux 8/9 (RHEL8/9), Almalinux 8/9, EuroLinux 8/9 or Rocky Linux 8/9
|
||||||
|
|
||||||
You can install [the `fd` package](https://copr.fedorainfracloud.org/coprs/tkbcopr/fd/) from Fedora Copr.
|
You can install [the `fd` package](https://copr.fedorainfracloud.org/coprs/tkbcopr/fd/) from Fedora Copr.
|
||||||
|
@ -620,7 +639,7 @@ brew install fd
|
||||||
|
|
||||||
… or with MacPorts:
|
… or with MacPorts:
|
||||||
```
|
```
|
||||||
sudo port install fd
|
port install fd
|
||||||
```
|
```
|
||||||
|
|
||||||
### On Windows
|
### On Windows
|
||||||
|
@ -665,7 +684,7 @@ pkg install fd-find
|
||||||
|
|
||||||
### From npm
|
### From npm
|
||||||
|
|
||||||
On linux and macOS, you can install the [fd-find](https://npm.im/fd-find) package:
|
On Linux and macOS, you can install the [fd-find](https://npm.im/fd-find) package:
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install -g fd-find
|
npm install -g fd-find
|
||||||
|
|
|
@ -162,7 +162,7 @@ _fd() {
|
||||||
$no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'
|
$no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'
|
||||||
|
|
||||||
+ strip-cwd-prefix
|
+ 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=[When to strip ./]:when:(always never auto)'
|
||||||
|
|
||||||
+ and
|
+ and
|
||||||
'--and=[additional required search path]:pattern'
|
'--and=[additional required search path]:pattern'
|
||||||
|
|
|
@ -33,16 +33,14 @@ with the '\-\-glob' option.
|
||||||
By default
|
By default
|
||||||
.B fd
|
.B fd
|
||||||
will exclude hidden files and directories, as well as any files that match gitignore rules
|
will exclude hidden files and directories, as well as any files that match gitignore rules
|
||||||
or ignore rules in .ignore or .fdignore files. For convenenience, '.git' is treated as if it
|
or ignore rules in .ignore or .fdignore files.
|
||||||
was always included in gitignore rules. These files can be included with options such as
|
|
||||||
'\-\-hidden' and '\-\-no\-ignore'.
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.B \-H, \-\-hidden
|
.B \-H, \-\-hidden
|
||||||
Include hidden files and directories in the search results
|
Include hidden files and directories in the search results
|
||||||
(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.
|
(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.
|
||||||
.IP
|
.IP
|
||||||
Ignored files and .git/ are still excluded unless \-\-no\-ignore or \-\-no\-ignore\-vcs
|
Ignored files are still excluded unless \-\-no\-ignore or \-\-no\-ignore\-vcs
|
||||||
is also used.
|
is also used.
|
||||||
.TP
|
.TP
|
||||||
.B \-I, \-\-no\-ignore
|
.B \-I, \-\-no\-ignore
|
||||||
|
@ -79,7 +77,6 @@ and the global gitignore configuration
|
||||||
.RI ( core.excludesFile
|
.RI ( core.excludesFile
|
||||||
git setting, which defaults to
|
git setting, which defaults to
|
||||||
.IR $HOME/.config/git/ignore ).
|
.IR $HOME/.config/git/ignore ).
|
||||||
The pattern ".git/" is automatically added to the list of VCS ignore rules.
|
|
||||||
The flag can be overridden with '--ignore-vcs'.
|
The flag can be overridden with '--ignore-vcs'.
|
||||||
.TP
|
.TP
|
||||||
.B \-\-no\-require\-git
|
.B \-\-no\-require\-git
|
||||||
|
@ -159,9 +156,20 @@ can be used as an alias.
|
||||||
Enable the display of filesystem errors for situations such as insufficient
|
Enable the display of filesystem errors for situations such as insufficient
|
||||||
permissions or dead symlinks.
|
permissions or dead symlinks.
|
||||||
.TP
|
.TP
|
||||||
.B \-\-strip-cwd-prefix
|
.B \-\-strip-cwd-prefix [when]
|
||||||
By default, relative paths are prefixed with './' when the output goes to a non interactive terminal
|
By default, relative paths are prefixed with './' when -x/--exec,
|
||||||
(TTY). Use this flag to disable this behaviour.
|
-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 change this behavior. If this flag is used without a value,
|
||||||
|
it is equivalent to passing "always". Possible values are:
|
||||||
|
.RS
|
||||||
|
.IP auto
|
||||||
|
Use the default behavior.
|
||||||
|
.IP never
|
||||||
|
Never strip the ./ at the beginning of paths
|
||||||
|
.IP always
|
||||||
|
Always strip the ./ at the beginning of paths
|
||||||
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.B \-\-one\-file\-system, \-\-mount, \-\-xdev
|
.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).
|
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).
|
||||||
|
@ -494,6 +502,17 @@ is set, use
|
||||||
.IR $XDG_CONFIG_HOME/fd/ignore .
|
.IR $XDG_CONFIG_HOME/fd/ignore .
|
||||||
Otherwise, use
|
Otherwise, use
|
||||||
.IR $HOME/.config/fd/ignore .
|
.IR $HOME/.config/fd/ignore .
|
||||||
|
.SH FILES
|
||||||
|
.TP
|
||||||
|
.B .fdignore
|
||||||
|
This file works similarly to a .gitignore file anywhere in the searched tree and specifies patterns
|
||||||
|
that should be excluded from the search. However, this file is specific to fd, and will be used even
|
||||||
|
if the --no-ignore-vcs option is used.
|
||||||
|
.TP
|
||||||
|
.B $XDG_CONFIG_HOME/fd/ignore
|
||||||
|
Global ignore file. Unless ignore mode is turned off (such as with --no-ignore)
|
||||||
|
ignore entries in this file will be ignored, as if it was an .fdignore file in the
|
||||||
|
current directory.
|
||||||
.SH EXAMPLES
|
.SH EXAMPLES
|
||||||
.TP
|
.TP
|
||||||
.RI "Find files and directories that match the pattern '" needle "':"
|
.RI "Find files and directories that match the pattern '" needle "':"
|
||||||
|
@ -507,6 +526,16 @@ $ fd -e py
|
||||||
.TP
|
.TP
|
||||||
.RI "Open all search results with vim:"
|
.RI "Open all search results with vim:"
|
||||||
$ fd pattern -X vim
|
$ fd pattern -X vim
|
||||||
|
.SH Tips and Tricks
|
||||||
|
.IP \[bu]
|
||||||
|
If you add ".git/" to your global ignore file ($XDG_CONFIG_HOME/fd/ignore), then
|
||||||
|
".git" folders will be ignored by default, even when the --hidden option is used.
|
||||||
|
.IP \[bu]
|
||||||
|
You can use a shell alias or a wrapper script in order to pass desired flags to fd
|
||||||
|
by default. For example if you do not like the default behavior of respecting gitignore,
|
||||||
|
you can use
|
||||||
|
`alias fd="/usr/bin/fd --no-ignore-vcs"`
|
||||||
|
in your .bashrc to create an alias for fd that doesn't ignore git files by default.
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues
|
Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
|
37
src/cli.rs
37
src/cli.rs
|
@ -49,8 +49,7 @@ pub struct Opts {
|
||||||
no_hidden: (),
|
no_hidden: (),
|
||||||
|
|
||||||
/// Show search results from files and directories that would otherwise be
|
/// Show search results from files and directories that would otherwise be
|
||||||
/// ignored by '.gitignore', '.ignore', '.fdignore', the global ignore file,
|
/// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file,
|
||||||
/// or the default rule that excludes .git/.
|
|
||||||
/// The flag can be overridden with --ignore.
|
/// The flag can be overridden with --ignore.
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
|
@ -64,7 +63,7 @@ pub struct Opts {
|
||||||
#[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]
|
#[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]
|
||||||
ignore: (),
|
ignore: (),
|
||||||
|
|
||||||
///Show search results from '.git/' folders and files and directories that
|
///Show search results from files and directories that
|
||||||
///would otherwise be ignored by '.gitignore' files.
|
///would otherwise be ignored by '.gitignore' files.
|
||||||
///The flag can be overridden with --ignore-vcs.
|
///The flag can be overridden with --ignore-vcs.
|
||||||
#[arg(
|
#[arg(
|
||||||
|
@ -618,9 +617,10 @@ pub struct Opts {
|
||||||
/// By default, relative paths are prefixed with './' when -x/--exec,
|
/// By default, relative paths are prefixed with './' when -x/--exec,
|
||||||
/// -X/--exec-batch, or -0/--print0 are given, to reduce the risk of a
|
/// -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
|
/// path starting with '-' being treated as a command line option. Use
|
||||||
/// this flag to disable this behaviour.
|
/// this flag to change this behavior. If this flag is used without a value,
|
||||||
#[arg(long, conflicts_with_all(&["path", "search_path"]), hide_short_help = true, long_help)]
|
/// it is equivalent to passing "always".
|
||||||
pub strip_cwd_prefix: bool,
|
#[arg(long, conflicts_with_all(&["path", "search_path"]), value_name = "when", hide_short_help = true, require_equals = true, long_help)]
|
||||||
|
strip_cwd_prefix: Option<Option<StripCwdWhen>>,
|
||||||
|
|
||||||
/// By default, fd will traverse the file system tree as far as other options
|
/// 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
|
/// dictate. With this flag, fd ensures that it does not descend into a
|
||||||
|
@ -643,7 +643,7 @@ impl Opts {
|
||||||
} else if !self.search_path.is_empty() {
|
} else if !self.search_path.is_empty() {
|
||||||
&self.search_path
|
&self.search_path
|
||||||
} else {
|
} else {
|
||||||
let current_directory = Path::new(".");
|
let current_directory = Path::new("./");
|
||||||
ensure_current_directory_exists(current_directory)?;
|
ensure_current_directory_exists(current_directory)?;
|
||||||
return Ok(vec![self.normalize_path(current_directory)]);
|
return Ok(vec![self.normalize_path(current_directory)]);
|
||||||
};
|
};
|
||||||
|
@ -666,6 +666,9 @@ impl Opts {
|
||||||
fn normalize_path(&self, path: &Path) -> PathBuf {
|
fn normalize_path(&self, path: &Path) -> PathBuf {
|
||||||
if self.absolute_path {
|
if self.absolute_path {
|
||||||
filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()
|
filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()
|
||||||
|
} else if path == Path::new(".") {
|
||||||
|
// Change "." to "./" as a workaround for https://github.com/BurntSushi/ripgrep/pull/2711
|
||||||
|
PathBuf::from("./")
|
||||||
} else {
|
} else {
|
||||||
path.to_path_buf()
|
path.to_path_buf()
|
||||||
}
|
}
|
||||||
|
@ -698,6 +701,16 @@ impl Opts {
|
||||||
.or_else(|| self.max_one_result.then_some(1))
|
.or_else(|| self.max_one_result.then_some(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn strip_cwd_prefix<P: FnOnce() -> bool>(&self, auto_pred: P) -> bool {
|
||||||
|
use self::StripCwdWhen::*;
|
||||||
|
self.no_search_paths()
|
||||||
|
&& match self.strip_cwd_prefix.map_or(Auto, |o| o.unwrap_or(Always)) {
|
||||||
|
Auto => auto_pred(),
|
||||||
|
Always => true,
|
||||||
|
Never => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "completions")]
|
#[cfg(feature = "completions")]
|
||||||
pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {
|
pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {
|
||||||
self.gen_completions
|
self.gen_completions
|
||||||
|
@ -758,6 +771,16 @@ pub enum ColorWhen {
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]
|
||||||
|
pub enum StripCwdWhen {
|
||||||
|
/// Use the default behavior
|
||||||
|
Auto,
|
||||||
|
/// Always strip the ./ at the beginning of paths
|
||||||
|
Always,
|
||||||
|
/// Never strip the ./
|
||||||
|
Never,
|
||||||
|
}
|
||||||
|
|
||||||
// there isn't a derive api for getting grouped values yet,
|
// there isn't a derive api for getting grouped values yet,
|
||||||
// so we have to use hand-rolled parsing for exec and exec-batch
|
// so we have to use hand-rolled parsing for exec and exec-batch
|
||||||
pub struct Exec {
|
pub struct Exec {
|
||||||
|
|
|
@ -128,13 +128,11 @@ pub fn strip_current_dir(path: &Path) -> &Path {
|
||||||
pub fn default_path_separator() -> Option<String> {
|
pub fn default_path_separator() -> Option<String> {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
let msystem = env::var("MSYSTEM").ok()?;
|
let msystem = env::var("MSYSTEM").ok()?;
|
||||||
match msystem.as_str() {
|
if !msystem.is_empty() {
|
||||||
"MINGW64" | "MINGW32" | "MSYS" => Some("/".to_owned()),
|
return Some("/".to_owned());
|
||||||
_ => None,
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -311,8 +311,7 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
|
||||||
path_separator,
|
path_separator,
|
||||||
actual_path_separator,
|
actual_path_separator,
|
||||||
max_results: opts.max_results(),
|
max_results: opts.max_results(),
|
||||||
strip_cwd_prefix: (opts.no_search_paths()
|
strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),
|
||||||
&& (opts.strip_cwd_prefix || !(opts.null_separator || has_command))),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,10 +334,6 @@ impl WorkerState {
|
||||||
.map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;
|
.map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.read_vcsignore {
|
|
||||||
builder.add("!.git/").expect("Invalid exclude pattern");
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.build()
|
.build()
|
||||||
.map_err(|_| anyhow!("Mismatch in exclude patterns"))
|
.map_err(|_| anyhow!("Mismatch in exclude patterns"))
|
||||||
|
|
|
@ -2573,7 +2573,14 @@ fn test_git_dir() {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
te.assert_output(&["--hidden", "foo"], "");
|
te.assert_output(
|
||||||
|
&["--hidden", "foo"],
|
||||||
|
".git/one/foo.a
|
||||||
|
.git/.foo
|
||||||
|
.git/a.foo
|
||||||
|
other_dir/.git/foo1
|
||||||
|
nested/dir/.git/foo2",
|
||||||
|
);
|
||||||
te.assert_output(&["--no-ignore", "foo"], "");
|
te.assert_output(&["--no-ignore", "foo"], "");
|
||||||
te.assert_output(
|
te.assert_output(
|
||||||
&["--hidden", "--no-ignore", "foo"],
|
&["--hidden", "--no-ignore", "foo"],
|
||||||
|
@ -2592,3 +2599,16 @@ fn test_git_dir() {
|
||||||
nested/dir/.git/foo2",
|
nested/dir/.git/foo2",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_gitignore_parent() {
|
||||||
|
let te = TestEnv::new(&["sub"], &[".abc", "sub/.abc"]);
|
||||||
|
|
||||||
|
fs::File::create(te.test_root().join(".gitignore"))
|
||||||
|
.unwrap()
|
||||||
|
.write_all(b".abc\n")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
te.assert_output_subdirectory("sub", &["--hidden"], "");
|
||||||
|
te.assert_output_subdirectory("sub", &["--hidden", "--search-path", "."], "");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue