sharkdp/fd

Filter files based on command output

TheBicPen opened this issue · 1 comments

Currently, the set of files output can be tweaked with simple predicates such as the -t and -e options. It would be nice to use an arbitrary command to filter the output. So the set of files output is set of files matched by the other criteria minus the set of files for which the given filter returns a non-zero exit code.

A use case for this is filtering files based on their MIME type - something like bash -c '[[ "$(xdg-mime query filetype $1)" == audio* ]]' (Note - this is untested. There is probably a syntax error in there somewhere).
I would expect to invoke it with something like fd -t f --filter "bash -c '[[ \"$(xdg-mime query filetype $1)" == audio* ]]'" ., which would find all files in the current directory whose MIME type is some kind of audio.
The current workaround for this is to stuff this command into the -x part of the fd invocation, only running the "real" part of the -x command on files that match the predicate. This works, but is a bit clunky, hence the feature request.

This is a duplicate of #400