Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
xdg-utils in a desktop-less world
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
i92guboj
Moderator
Moderator


Joined: 30 Nov 2004
Posts: 10264
Location: Córdoba (Spain)

PostPosted: Thu Dec 19, 2013 8:50 am    Post subject: xdg-utils in a desktop-less world Reply with quote

Hello.

It must be me, because I can find much info on this issues around the net.

I've never been a friend of xdg. I seem to be stumping on it every now and then. Not that this is a tragedy, but it gets boring after a few years of annoyances...

Please, for the rest of the post, remember that this is aimed at non-{kde,gnome,xfce} installations. If you fit in either of these groups either read this loosely or skip it entirely :lol:

To the point. Setting file type associations have never been as difficult as it is now, you have to know or remember of whatever all the mime types, and not all of them are as obvious as image/jpeg. You usually have to guess. Plus, MIMEs have always been a pile of UN-standarized junk, where you can easily find like 20 MIMEs for a given file extension.

So, you easily end up having to google each time you need to open a file from, let's say, chromium or filezilla.

After several years of dealing with this, I grew fed up and ended up shaping a simple script that does part of the job for me. That was yesterday. The script is this:

Code:
#!/bin/bash -x
#DESKTOP_FILE=$(locate "${1}".desktop)
DESKTOP_FILE="${1}".desktop
MIME_TYPE=$(xdg-mime query filetype "${2}")
xdg-mime default $DESKTOP_FILE $MIME_TYPE


Happiness had not lasted for so long, though. Today I wanted to associate an obscure file type (erm, .png, that is :lol:), and guess what, the script didn't work. Further investigation revealed that the mime type for png is, oh surprise:

Code:
$ xdg-mime query filetype wallpapers/000008.png
image/x-apple-ios-png


Which is obviously wrong. Thus, the association did not work.

This is a consequence of what I said above: MIME as a whole being a pile of UN-standardised crap. So, again, yet once more, I had to resort to guessing (well, in this concrete case there wasn't a need to guess anything, but you get my point...).

The sad part is that this demonstrates that there's no easy automatic way to deal with this. We will have to continue to guess and search for MIMEs, and the database is only growing, and then you gotta configure each application separately in funny ways...

As an example, yesterday I had to fight yet once more with filezilla, and I finally ended configuring it to override file associations entirely, and open all the files with the editor of my choice. And then I chose "xdg-open" as editor... Simple enough, you might think. But the truth is that this stuff has never been so complicated. Even Windows 3.1 did a better job at this than the whole XDG specs do nowadays.

But, enough of a rant, I guess you got the idea. What I would like to know is if there's someone who has managed to live without xdg altogether. I have searched around but xdg seems to be the norm and no one questions that norm. A lot of people argue around about systemd vs openrc, kde vs. gnome, wayland vs. x11 and hulk vs. spiderman, but everyone seems to live so happy with this fundamentally broken thing, and now one complains. I can understand that from the users of massive DEs, where the DEs themselves take care of sanitizing the defaults and provide an easy to use MIME editor. But the fact is that this XDG thing has been pushed down the throat of non-DE users, and I have to devote my time to fix this stuff which in fist place brought me no benefit at all (even if it worked, which is does not).

So, besides watching how $(equery d xdg-utils | wc -l) packages push xdg-utils in my system, and then an undetermined number of other packages start using it without asking me permission and in a buggy way (such as filezilla, sunflower or pcmanfm), is there anything I can do? :cry:

Thanks.

EDITED: for the time being, I would be happy knowing how to go about listing all the MIMEs associated with a given file extension, something that xdg-mime doesn't seem to be able to do. It probably just picks the first coincidence.

EDITED again: I know it's ugly. I am fed up with this. I refuse to research any more about this thing. This keeps breaking every two days. For now this will work, I don't know for how long though. I know it's rough, but this is what you get when you are forced to do something with zero interest in the matter.

Code:

#!/bin/bash
# rev 0.002
DESKTOP_FILE=$(basename $(locate "${1}".desktop))
#DESKTOP_FILE="${1}".desktop
FILE_EXTENSION="${2##*.}"

if [ "${FILE_EXTENSION}" == "" ]
then
   MIME_TYPE=($(xdg-mime query filetype "${2}"))
else
   cd /usr/share/mime
   MIME_TYPE=($(find . -name *"${FILE_EXTENSION}"*))
fi

for type in "${MIME_TYPE[@]}"
do
   type="${type/.\//}"
   type="${type/.xml/}"
   xdg-mime default $DESKTOP_FILE $type
   # The following is just to verify the type is set correctly
   DE_FILE=$(xdg-mime query default $type)
   echo " * ${DE_FILE} set as viewer for MIME type ${type}"
done


Still, if there's someone xdg-less in Gentoo I'd like to hear from him or her.
_________________
Gentoo Handbook | My website
Back to top
View user's profile Send private message
rudregues
Apprentice
Apprentice


Joined: 29 Jan 2013
Posts: 216
Location: Brazil

PostPosted: Fri Dec 20, 2013 5:41 am    Post subject: Reply with quote

I see your point... must agree we need more options, another way to do this (or at least less buggy way)

It can be considered a bug having no standartization with MIME's. Probably a freedesktop's bug. You can report this here
https://bugs.launchpad.net/bugs/bugtrackers/freedesktop-bugs

EDIT: I found something interesting http://www.casual-tempest.net/projects/envoy/
_________________
Emerging en gentoo
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4324

PostPosted: Fri Dec 20, 2013 10:39 am    Post subject: Reply with quote

rudregues wrote:
EDIT: I found something interesting http://www.casual-tempest.net/projects/envoy/

Tried to build it and it fails. First "open" needs a third parameter, after fixing that it fails with lots of linking errors for "convey_motif.c". make clean and configure --without-motif still fails with the same linking errors. -> build system broken :/
That's where I stop for now...

Furthermore I don't know how usability is as envoy uses an sqlite database to store mimetypes and assosiations -> no easy way to fire up a text editor/grep/... to lookup/fix associations, you depend on the delivered tools. (which I can't test as they don't build ;))
Back to top
View user's profile Send private message
rudregues
Apprentice
Apprentice


Joined: 29 Jan 2013
Posts: 216
Location: Brazil

PostPosted: Sat Dec 21, 2013 6:02 am    Post subject: Reply with quote

franzf wrote:
Tried to build it and it fails. First "open" needs a third parameter, after fixing that it fails with lots of linking errors for "convey_motif.c". make clean and configure --without-motif still fails with the same linking errors. -> build system broken :/

Did you tried the ebuild in the site?
_________________
Emerging en gentoo
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum