Expand description
What type a file is, which applications can open it, and which one does by default.
Nearly every question has a data file of its own, all of them freedesktop’s and all of them plain text:
| Question | File | Module |
|---|---|---|
What type is part.3mf? | mime/globs2 | globs |
| What is this file, with no name to go on? | mime/magic | magic |
| Which of those two wins? | — | lookup |
What is a model/3mf a kind of? | mime/subclasses, mime/aliases | types |
Which icon does a model/3mf have? | mime/icons, mime/generic-icons | icons |
What can open a model/3mf? | applications/mimeinfo.cache | apps |
| Which one does, normally? | mimeapps.list | defaults |
§Why this crate exists
A double-clicked STL opened in Firefox. Not because anything chose
that — because xdg-open, on a desktop it does not recognise
(Hyprland is one), asks file --mime-type, which reads bytes and not
names. An STL is application/octet-stream to it, a 3MF is a zip, a
.blend is a zstd stream; none of those has a default application,
and xdg-open answers a lookup that found nothing by walking a
built-in list of web browsers. Every .stl, .3mf, .uf2, .blend
and .sh in a real Downloads folder went that way.
The database on the machine had the right answer the whole time. So this reads it.
§What this is not
Not a launcher, and not a fourth opinion about which application
opens a file. It reads what the desktop already recorded and writes
only what a person explicitly chose; running the thing is still
gio launch with xdg-open behind it. Nothing here parses Exec=
field codes, TryExec or Terminal=true — see apps for why that
line is where it is.
§Layering
A leaf, like hyprforge-look: no iced, nothing Hyprland-shaped, two
dependencies (hyprforge-paths, for the config directory and the
atomic write; hyprforge-process, for the bounded wait
hyprforge-mimeopen puts on gio launch). The file manager
and the Settings app’s Default apps page read it today, and any
future viewer needs the same answers.
Re-exports§
pub use apps::App;pub use globs::Globs;pub use lookup::Found;pub use lookup::How;pub use lookup::Lookup;pub use magic::Magic;pub use types::Types;
Modules§
- apps
- Which applications can open a type, and what they are called.
- cli
- The argument grammar
mimetypeandmimeopenshare. - defaults
- Which application opens a type, and changing it.
- globs
- What type a file is, decided by its name.
- icons
- Which icon name a type has — the half of “draw this file’s icon”
that is the MIME database’s. Which file that name is belongs to the
icon theme, and to
hyprforge-icons. - lookup
- Putting the name and the contents together: what is this file.
- magic
- What a file is, decided by its contents.
- types
- What the database knows about a type, as opposed to about a file: its other names, what it is a kind of, and what to call it in front of a person.
Structs§
- Candidate
- One application that could open a type, and why it is offered.
- MimeDb
- Everything the machine says about types and the applications that open them, read once.
Functions§
- clear_
default - Removes
mime’s default from the user’s ownmimeapps.list. - data_
dirs $XDG_DATA_HOMEthen$XDG_DATA_DIRS, in the order the spec gives them — public because themimetypecommand needs the same list, and--databasereplaces exactly this — earlier is more specific. Flatpak puts its exported entries in here, which is how a flatpak application is offered at all.- mimeapps_
paths - Every
mimeapps.listthat applies, most specific first. Public because themimeopencommand loads the database the same way. - set_
default - Makes
appthe default formime, in the user’s ownmimeapps.list. - user_
mimeapps_ path - The one file this crate writes.