I know that there are some files /etc/gnome/defaults.list
that store mime associations and are in format that should make editing them possible.
But I am looking for a way that will handle at least one of following problems
- this file is in format that is reasonable to parse. Still, using API that somebody made and hopefully tested will save some time and problems with bugs
- it would be great to have API aware about location of that file depending on OS version, OS etc. Even crashing with "this is not supported" would be preferable to script editing something that is no longer used
I want to fully automate my installation of Ubuntu - setting file associations to correct one is intended to be part of that.
Even automated/semi-automated (like documentation) way to find place storing file associations would be welcome.
how can I change file association globally? mentions /usr/share/gnome/applications/defaults.list
, /usr/share/applications/defaults.list
and /usr/share/applications/mimeapps.list
See also Which default.list should I modify for default applications and what are the differences between the two? (so I would prefer to automate at least locating the file)
xdg-mime(1) may be what you're looking for.
The man page for this command links to the MIME database specification at https://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/, and also the MIME applications associations specification at http://www.freedesktop.org/wiki/Specifications/mime-apps-spec/
Following works in some cases, but not all:
to see mimetype:
file --mime-type -b sudolightburn.sh
to see current association:
xdg-mime query default text/plain
to change association:
xdg-mime default codium.desktop text/plain
In case someone would be interested, I have an ansible role using this to setup sane default programs: https://github.com/matkoniecz/recovery-with-ansible/tree/master/roles/set_default_programs_for_file_types