Comment by Karellen

11 years ago

Yeah, I'm not sure about that. According to the xdg-mime(1) man page:

"The query option is for use inside a desktop session only."

Why wouldn't it work from a console session? Or even a non-login session (e.g. cron job)? I'm not sure I want to trust a command-line program that only works as part of a desktop session. It sounds like the sort of fragile doodad that makes weird assumptions about its environment, which might one day no longer be true even in that environment, to me.

Can anyone shed any further light on that crazy usage restriction?

What it actually means is that it needs the various XDG basedir variables to be set, which they sometimes aren't in a non-desktop session (this is becoming less common).

http://standards.freedesktop.org/basedir-spec/basedir-spec-l...

xdg-mime merely looks at the shared-mime-info db, processes files accordingly and spits out the result.

Also, I did not actually say you should use xdg-mime; I said you should use the shared-mime-info database. xdg-mime is a (very crappy) interface for it, but using an xdg library is a lot, lot more efficient.

  • Thanks for the reply.

    If not xdg-mime(1) then, do you know of another file(1)-like command-line app which does use the shared-mime-info database?

    • For use on the command line, feel free to use xdg-mime (it does not just do mime types, it also does associations with them which means you can view and change associations between file types from it). I don't know of any other tool like it although I was working on one in python (but it's not production ready).