2

I'm trying to get xdg-open to open css files with correct editor, but can't get file to report correct mimetype for a file.css file. There is an entry both in /etc/mime.types and a file already exist as /usr/share/mime/text/css.xml but this always happens:

➜  ~  echo ". {}" > file.css
➜  ~  file --mime-type file.css
file.css: text/plain
➜  ~  

When I trace the code, I see that it uses magic instead of /usr/share/mime/text mime db. How can I get file to report this as text/css instead of text/plain?

1

AFAIK you can't use file -i or file --mime-type to test the functionality of the system-wide MIME database. file uses magic and its config by default, so to change the behavior of file, you would have to change the magic config.

To check and modify the xdg-open behavior instead, you should use the XDG-Utilities. For example, you can check the current settings how to handle files with text/plain MIME type:

~ $ xdg-mime query default text/plain

On my Mint laptop, it returns

gedit.desktop

For text/css, there's usually no default application set (you can check this using xdg-mime query default text/css). To change this and set GEdit as default CSS editor, you could use the following command:

~ $ xdg-mime default gedit.desktop text/css

This will insert a line in /home/<Username>/.local/share/applications/mimeapps.list with text/css=gedit.desktop. Instead of using xdg-mime, you could modify the mimeapps.list directly.

Now, xdg-mime query returns the application i've chosen ...

~ $ xdg-mime query default text/css
gedit.desktop

... and xdg-open /tmp/file.css will start GEdit and load the CSS fiile.

See also this page on xdg-open from the Arch Linux Wiki.

1
  • Thanks, saved the day! My error was that I thought xdg-open got info from file. – grm Sep 5 '13 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.