4 ms·
nice! ~$ xdg-mime query filetype /etc/passwd text/plain
by slug 12y ago
nice!
~$ xdg-mime query filetype /etc/passwd
text/plain
- Karellen 12y agoYeah, 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?
- scrollaway 12y agoWhat 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-latest.html 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.
- Karellen 12y agoThanks 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?
- scrollaway 12y agoFor 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).