Search patterns: support negation (`-searchterm`, logical ¬)
Following on from #28 (closed), now that we have recursive search, things have changed a bit. Search now produces a result set, on which normal file operations and UCAs can run. Filtering with globs on a result set like this can still happen with Select by Pattern
at present. However, sometimes it's nice to have a bit more control over what's in the results set.
I think that the most useful pattern to support would be negation, or a logical NOT. It's also quite easy to implement!
Thunar's current state
Currently, the search string is split on whitespace, and each such term must match in every target file's basename. This is a little like Nautilus's implementation.
Other implementations
Nautilus does not support negation, so implementing this will make Thunar's recursive search more useful than Nautilus's.
Internet search engines use a -
at the front of a search term to indicate that results should not include that term. Something like this should work well when searching trees with lots of false positives.
This would make the Thunar search something like fzf's --exact
mode. That uses !
as its prefix for NOT-terms, but the concept is very similar.
Expected behaviour
I definitely prefer the -
prefix to !
, and there are probably more people using Google or DuckDuckGo than there are using fzf. That said, it does mean you can't search for specific file names with a search term beginning with a -
(searching for -min
wouldn't match hyphen-minus.txt
). !
has the advantage of being terminal punctuation in most languages, so it is less likely to appear in a file or directory name at the start of a string (some exceptions: RISC OS application directories, old systems where !readme.txt
sorts earlier etc.)
Should we go with -
due to user familiarity, I would expect the search string pear -apple -tag
to match 'pear juice.txt' but not any of APPLE AND PEAR PRICE COMPARISON.DOCX
, pineapple.jpg
, or pear and pomegranate tagine recipe.md
.
Future ideas and scope
Perhaps one day we we could unify the syntax for Search
and Select by Pattern
so that Thunar doesn't have to support two different search/select syntaxes. I think that's outside the scope of this feature request. It's best keep things simple at first and test!
The limitation mentioned above would disappear if one could search for *-min*
. One day, perhaps.