r/linux4noobs • • 21d ago

[KDE Plasma 6 & XDG-mime] How to have two default apps for text/plain, one for *.txt, one for everything else?

Hi,

I'm running OpenSuse Tumbleweed, kernel 7.3.1 (if that matters), I live withing Wayland, my DE is Plasma 6, and it seems to me Plasma / or Dolphin rely on XDG to attribute apps to "file categories" at large, and to mime types in particular.

Although, a *.txt file (which I would name explicitly as such, to mark it as 'notepad' filetype, you see?), is just a text file as much as any source code file is, I'm fighting to make xdg-open (and thus, everything else thanks to that) be aware that I'd like to specifically ask it to attribute the Default App my_lightweight_notepad to any files ending in".txt", and let Kate (org.kde.kate.desktop) handle every other text/plain files (cause besides *.txt files, I'm ok with kate opening text/plain files by default, I explicitely want files I'll name *.txt to open in the lightweight editor I chose separetely).

That is, either a more specialized choice of Default App within the text/plain mime category, or (idk if it's possible) simply setup a filename filter, not caring about the mime type but only for the presence of ".txt" at the end and, default the opening app to `my_lightweight_notepad`.

I've done search on my side, and it led to nothing working. Most are ancient posts on forums, and my attempt to writee in ~/.config/mimeapps.list and ~/.local/share/applications/mimeapps.list and ~/.local/share/mime/packages/text-plain-txt.xml then updat[ing]-mime-database and update-mime-desktop, the regular behavior still shows up: The same 'new' (chosen) text editor app (for *.txt only...) becomes the default app that opens every other text/plain files anyway (source files, etc...) Exactly NOT what I wanted x)

Has someone any clue about this? I thought that was not something uncommon to do, but I can't seem to find relevant threads about it...

Thanks for reading :)

4 Upvotes

3 comments sorted by

2

u/GiggleSamurai 21d ago

text/plain already claims *.txt at the default glob weight (50), and on a tie it falls back to content sniffing, which says text/plain. Give your custom type <glob pattern="*.txt" weight="60"/> plus <sub-class-of type="text/plain"/>, run update-mime-database ~/.local/share/mime, confirm with xdg-mime query filetype foo.txt, then set the default for that new type (not text/plain).

1

u/DamsLcs4421 21d ago

Oh thank you it clicked immediately!

Thanks of lot, case solved :)