This is a proposal to add a --filter <cmd>/-f <cmd> command-line option that would work very similar to the filter option in (functional) programming languages. It would be implemented in a similar way like --exec <cmd> and execute the given command for every path. Instead of showing the output of the command, it would filter the search results based on the exit status of the command (i.e. only include the ones which succeed with exit code 0).
In addition, we could also add a --reject <cmd>/-r <cmd> option that would do the opposite.
This would allow us to do things like:
# Show all C++ source files that contain the word TODO
fd -e cpp -e h -f grep TODO
# Show all entries that are NOT directories (this can not be done with `--type`)
fd -r test -d
# Only show files which exist and the current user has write permission
fd … test -w
# Only show files that are newer than 'reference.txt'
fd … -f test {} -nt reference.txt
# Only show files which have a diff with respect to the Git index
fd … -f git diff --exit-code
# Show all *.jpg files with a mime type that does NOT match image/jpeg
fd -e jpg -f sh -c '[ $(file -b --mime-type "{}") != "image/jpeg" ]'
I'd be happy to get some feedback on this idea or hear about other ways on how this could be used.
This is a proposal to add a
--filter <cmd>/-f <cmd>command-line option that would work very similar to thefilteroption in (functional) programming languages. It would be implemented in a similar way like--exec <cmd>and execute the given command for every path. Instead of showing the output of the command, it would filter the search results based on the exit status of the command (i.e. only include the ones which succeed with exit code 0).In addition, we could also add a
--reject <cmd>/-r <cmd>option that would do the opposite.This would allow us to do things like:
I'd be happy to get some feedback on this idea or hear about other ways on how this could be used.