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?
AFAIK you can't use
file -i
orfile --mime-type
to test the functionality of the system-wide MIME database.file
usesmagic
and its config by default, so to change the behavior offile
, you would have to change themagic
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 withtext/plain
MIME type:On my Mint laptop, it returns
For
text/css
, there's usually no default application set (you can check this usingxdg-mime query default text/css
). To change this and set GEdit as default CSS editor, you could use the following command:This will insert a line in
/home/<Username>/.local/share/applications/mimeapps.list
withtext/css=gedit.desktop
. Instead of using xdg-mime, you could modify themimeapps.list
directly.Now,
xdg-mime query
returns the application i've chosen ...... 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.