marvinkreis / rofi-file-browser-extended

Use rofi to quickly open files
MIT License
240 stars 15 forks source link

Show only files of certain MIME types (or generic file/directory filtering) #27

Open jluttine opened 4 years ago

jluttine commented 4 years ago

In many "normal" applications, they open some file dialog to select a file of a certain type. For instance, "choose an image". Magically, the dialog indeed lists only image files.

I think rofi file browser would be perfect for similar usecases. For this to work, the file browser would need to be able to filter the files somehow. Would it make sense to add a flag like -file-browser-filter-mime-type=image/jpeg,image/png, which accpets, for instance, a comma separated list of MIME types? At least file --mime-type somefile can be used to get the MIME type of a file, but there are certainly many other tools for that. Also, filtering based on extension might be useful.

Another more general option would be to add an option like -file-browser-filter=some_executable for which some filtering executable is given. This filter is run for the list of files (and directories?) that would be in the current view. I don't know what would be the best way to implement it, but one simple solution would be that the executable is assumed to read stdin and print to stdout those paths it wants to keep. This would of course allow arbitrary manipulation of the file names (heck, it can print any number of lines containing whatever to stdout), and that most likely doesn't make sense in many cases, but maybe that can have some unpredictable powerful usecases. But at least it would allow relatively easy implementation of various filters such as the mime type and extension filters I had in mind.

What do you think?