Anomalocaridid / handlr-regex

Fork of handlr with support for regex
MIT License
114 stars 4 forks source link

Wildcards do not appear to work with GUI file managers #75

Closed uwidev closed 1 month ago

uwidev commented 1 month ago

I'm having some issues getting files to open properly using GUI file managers. They do not open files with the correct program.

Tested GUI file managers:

Here's my barebones mimeapps.list

[Default Applications]
image/*=org.nomacs.ImageLounge.desktop;
text/*=nvim.desktop;

I have tried touching handlr.toml, however I was not able to get anything to work. I gave up messing with it and am just using defaults.

enable_selector = false
selector = "rofi -dmenu -i -p 'Open With: '"
term_exec_args = '-e'

I tried to add nomacs as my default image viewer on handlr.toml as follows, but it isn't recognized when running handlr get image/png. This is when unsetting the image/* assignment under mimeapps.list. So I'm not too sure if this is the problem, as I followed a similar formatting to the readme.

[[handlers]]
exec = "nomacs %f"
terminal = false
regexes = ['image/.+']

For reference, this is what the .desktop for nomacs is.

[Desktop Entry]
Name=nomacs
GenericName=Image Viewer
Comment=nomacs is a free, open source image viewer.
Exec=nomacs %f
Terminal=false
Icon=org.nomacs.ImageLounge
Type=Application
Categories=Graphics;RasterGraphics;Viewer;2DGraphics;
MimeType=image/avif;image/bmp;image/gif;image/heic;image/heif;image/jpeg;image/jxl;image/png;image/tiff;image/webp;image/x-eps;image/x-ico;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xbitmap;image/x-xpixmap;
GenericName[de]=Bildbetrachter
Comment[de]=Ressourcenschonender, plattformübergreifender Bildbetrachter mit Unterstützung für verschiedenste Formate
Name[pt]=nomacs
GenericName[pt]=Visualizador de imagens
Comment[pt]=Um visualizador de imagens desenvolvido em Qt

Running xdg-mime with debug image/png yields the following.

> env XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default image/png
Checking /home/timmy/.config/mimeapps.list
Checking /home/timmy/.local/share/applications/mimeapps.list
Checking /home/timmy/.local/share/applications/defaults.list and /home/timmy/.local/share/applications/mimeinfo.cache
Checking /home/timmy/.local/share/applications/defaults.list and /home/timmy/.local/share/applications/mimeinfo.cache
Checking /home/timmy/.local/share/flatpak/exports/share/applications/defaults.list and /home/timmy/.local/share/flatpak/exports/share/applications/mimeinfo.cache
Checking /home/timmy/.local/share/flatpak/exports/share/applications/defaults.list and /home/timmy/.local/share/flatpak/exports/share/applications/mimeinfo.cache
Checking /var/lib/flatpak/exports/share/applications/defaults.list and /var/lib/flatpak/exports/share/applications/mimeinfo.cache
Checking /var/lib/flatpak/exports/share/applications/defaults.list and /var/lib/flatpak/exports/share/applications/mimeinfo.cache
Checking /usr/local/share//applications/defaults.list and /usr/local/share//applications/mimeinfo.cache
Checking /usr/local/share//applications/defaults.list and /usr/local/share//applications/mimeinfo.cache
Checking /usr/share//applications/defaults.list and /usr/share//applications/mimeinfo.cache
chromium.desktop

Running handlr get image/png yields what I expect: org.nomacs.ImageLounge.desktop.

I have xdg-open shadowed as seen in the readme.

> xdg-open
error: the following required arguments were not provided:
  <PATHS>...

Usage: handlr open <PATHS>...

For more information, try '--help'.

Using a TUI file manager like yazi has the file open correctly. I have only tested yazi.

No, I do not have any other *-mimeapps.list files under ~/.config.

I have gotten this to work when I use image/png. It will work on my GUI file explorers, and when using built-in xdg-open. However, this does seem to defeat the purpose of handlr-regex and wildcard support.

I don't know what I'm doing wrong or if it just straight up isn't supported for GUI file handlers. Any help in troubleshooting this, etc., would be appreciated.

Anomalocaridid commented 1 month ago

GUI file managers are technically supported. However it's more of an issue of whether the file manager can support handlr-regex, not the other way around. More specifically, shadowing xdg-open only works if the program you want to use handlr uses xdg-open to open files.

I am not very familiar with Thunar or PCManFM, but according to the Arch Linux Wiki, Thunar and PCManFM do not use xdg-open. Instead, they use the GIO library to determine which program should open a given file.

Unfortunately, I am not aware of any workaround for this.

I tried to add nomacs as my default image viewer on handlr.toml as follows, but it isn't recognized when running handlr get image/png.

This is expected. handlr get does not support regex handlers in handlr.toml.

Using a TUI file manager like yazi has the file open correctly. I have only tested yazi.

This works because yazi uses xdg-open by default to open programs.

uwidev commented 1 month ago

That's what I was speculating, darn. Because the only way it wouldn't work is if it straight up did not use xdg-open, or directly referenced the binary on the system rather than looking up $PATH, or some other weird shenanigans.

Do you have any recommendations on what does work? Perhaps we could have a small documentation of known GUI file managers that utilize xdg-open? Or maybe I'm not looking at the right places on the arch wiki.

Anomalocaridid commented 1 month ago

Do you have any recommendations on what does work?

Unfortunately, I do not. It has been years since I last regularly used a GUI file manager.

I know nnn, yazi, xplr, superfile, and possibly ranger use xdg-open at least as a fallback, but those are all TUI file managers.

Perhaps we could have a small documentation of known GUI file managers that utilize xdg-open?

That's a good idea. I'd be up for documenting that as soon I know of any examples. I'm sure there's got to be some program that fits that description.

Or maybe I'm not looking at the right places on the arch wiki.

I haven't been able to find much information there regarding GUI file managers that use xdg-open. Unfortunately, I haven't had much luck elsewhere either.

uwidev commented 1 month ago

I see. I needed a way to manage pictures, hence my usage of thumbnails in GUI file managers. I wonder if there's a TUI that can display like a grid of images but still as TUI. That's something I guess I'd have to do research on my own.

But that said, as a workaround, earlier I mentioned that using image/gif works as expected. What are your thoughts on having image/* insert all known mime types of image/ into mimeapps.list? I could see it as potentially troublesome to manage, however.

Anomalocaridid commented 1 month ago

I see. I needed a way to manage pictures, hence my usage of thumbnails in GUI file managers. I wonder if there's a TUI that can display like a grid of images but still as TUI. That's something I guess I'd have to do research on my own.

I know nnn has something like that with its imgview plugin.

You probably already know this, but other TUI file managers like yazi, xplr, and I think maybe ranger support image previews, but only for the currently selected file.

But that said, as a workaround, earlier I mentioned that using image/gif works as expected. What are your thoughts on having image/* insert all known mime types of image/ into mimeapps.list? I could see it as potentially troublesome to manage, however.

I might consider adding an option that enables that behaviour, but I can't promise I'll be able to get around to implementing it anytime soon.

You might want to check out mimeo. It works that way and it even has a feature that's similar to handlr-regex's regex handlers. In fact, it inspired this fork.

uwidev commented 1 month ago

Thank you. I will take a look at mimeo, but I'll take a look around at handlr's code when I get the chance to see how feasible it would be to do something like that. I really like handlr's user logic and would like to continue using it.