Skip to content

Add --filter and --reject options#1890

Open
veeceey wants to merge 2 commits intosharkdp:masterfrom
veeceey:feat/issue-400-filter-option
Open

Add --filter and --reject options#1890
veeceey wants to merge 2 commits intosharkdp:masterfrom
veeceey:feat/issue-400-filter-option

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 23, 2026

Adds two new flags for command-based result filtering:

  • --filter <cmd> ; - runs a command for each match, keeps the result only if it exits 0
  • --reject <cmd> ; - inverse of --filter, excludes results where the command exits 0

These use the same placeholder syntax as --exec ({}, {/}, {//}, {.}, {/.}).

Example usage:

# Find files containing "TODO"
fd -t f --filter grep -q TODO {} \;

# Find files that are NOT symlinks
fd --reject test -L {} \;

The commands run with stdout/stderr suppressed so they don't pollute the output. Filter/reject runs in the walker threads alongside the other built-in filters (size, time, type, etc.) so it integrates naturally with the existing pipeline.

Closes #400

@veeceey
Copy link
Author

veeceey commented Feb 23, 2026

Test results (macOS, local build):

cargo test
test result: ok. 103 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Manual testing:

# Setup: src/exec/ has 3 files: command.rs, job.rs, mod.rs
# Only job.rs and mod.rs contain "CommandSet"

# --filter: keep files containing "CommandSet"
$ fd . src/exec/ -t f --filter grep -q 'CommandSet' \;
src/exec/job.rs
src/exec/mod.rs
# ✓ Correct - command.rs excluded

# --reject: exclude files containing "CommandSet"  
$ fd . src/exec/ -t f --reject grep -q 'CommandSet' \;
src/exec/command.rs
# ✓ Correct - only command.rs (which doesn't have CommandSet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: add --filter <cmd> option

1 participant