-
-
Notifications
You must be signed in to change notification settings - Fork 51
FastMagic
Moira1 identifies file formats using fast, custom binary inspection and assigns MIME types so downstream systems (preview generation, file handling, and application dispatch) can route files correctly.
Its primary goal is to speed up detection speed of many common file formats (PDF, PNG, MP4, etc). When Moira cannot identify a file type, it falls back to libmagic, which itself falls back to the Shared MIME-info database if necessary.2
Moira often outperforms libmagic on speed and can also recognize additional, older formats (for example, legacy image files) that libmagic may miss — useful when previewing archival file collections.
Moira is enabled by default. To disable it, set FastMagic to false in the main configuration file.
1 The name Moira comes from the Greek word moira, related to destiny. In Greek mythology, the Moirai (Clotho, Lachesis, and Atropos) weave human fate. By assigning a MIME type, Moira likewise determines a file's “destiny” — for example, how it will be opened or how a preview will be generated.
2 The Shared MIME-info database is consulted via mimetype(1) or xdg-mime(1), in that order. If neither tool is available on the system, this check is skipped.
The remainder of this document outlines the principles guiding MIME type assignments.
Before assigning a custom MIME type to an identified format, consult existing standards in this order:
- IANA Media Types Registry (https://www.iana.org/assignments/media-types/)
- file(1) magic database and its MIME type assignments
- Shared MIME-info database (https://gitlab.freedesktop.org/xdg/shared-mime-info/)
Use the first match found. Only create a custom type if none of these sources define one for the format.
For formats with IANA-registered MIME types, use them exactly as registered:
| Format | MIME Type | Source |
|---|---|---|
| GZIP | application/gzip |
IANA |
| ZIP | application/zip |
IANA |
application/pdf |
IANA | |
| MP4 Video | video/mp4 |
IANA |
| JPEG Image | image/jpeg |
IANA |
For formats recognized by file(1) or Shared MIME-info but not IANA-registered, use the established type:
| Format | MIME Type | Source |
|---|---|---|
| bzip2 | application/x-bzip2 |
file(1) |
| XZ compressed | application/x-xz |
file(1) |
| 7-Zip | application/x-7z-compressed |
Shared MIME-info |
| FLAC Audio | audio/x-flac |
Shared MIME-info |
For formats identified by fast-magic but not found in any of the above sources, assign a custom type using the x- prefix following these guidelines:
Choose the primary category based on the format's fundamental nature:
-
video/x-*: Video formats (containers, codecs, proprietary video) -
audio/x-*: Audio formats (containers, codecs, proprietary audio) -
image/x-*: Image formats (bitmaps, vectors, proprietary graphics) -
text/x-*: Text-based formats (markup, code, documents) -
application/x-*: Everything else (compressed archives, executables, data formats, mixed-media)
Type names should be:
- Descriptive: Clearly identify the format or source application
- Lowercase with hyphens: Follow MIME type conventions
-
Concise: Avoid redundancy (e.g., use
video/x-binknotvideo/x-bink-video-format)
| Format | Identification | MIME Type | Rationale |
|---|---|---|---|
| 3D Movie Maker video | Proprietary video format from Microsoft | video/x-3d-movie-maker |
Primary purpose is video; format is proprietary to a specific application |
| Bink video | RAD Game Tools video codec | video/x-bink |
Video container/codec; widely used in games |
| Custom game data | Proprietary binary game asset format | application/x-game-assets |
Mixed-media; not primarily video/audio/image |
| Uncommon text markup | Domain-specific markup language | text/x-mydsl |
Text-based; specific to a domain |
The x- prefix (per RFC 6838) indicates:
- Non-standard: The type is not IANA-registered
- Real identification: The format has been genuinely identified, not guessed
- Future-ready: If the format gains adoption, this type is a natural candidate for standardization without renaming
Do not use x- as a catch-all for "unknown" formats. Assign custom types only when you've positively identified the format through magic signatures or structural analysis.
MIME types assigned by fast-magic are semantic labels designed for flexible routing. Consuming systems (like preview handlers) can:
- Use regex patterns to group related types (
video/.*) - Define fallback chains per type (
video/x-bink=ffmpeg;mplayer) - Extend mappings without modifying
fast-magic
Example from clifm preview config:
video/.*=ffmpeg;mpv;mplayer
audio/.*=ffmpeg;sox
image/.*=convert;imagemagick
When submitting new magic signatures or formats to fast-magic:
- Verify the format identification: Ensure your magic signature correctly identifies the target format with minimal false positives
- Research existing MIME types: Check IANA, file(1), and Shared MIME-info before proposing a custom type
- Follow the naming convention: Use the appropriate category and describe the format clearly
- Document your choice: Include a comment explaining why you selected that specific MIME type
-
Consider alignment: If your proposed type differs from
file(1)or Shared MIME-info for the same format, discuss the rationale in your contribution
Custom x- prefixed types may eventually become standardized. If a format you've identified gains wider adoption:
- The type remains stable (no renaming needed)
- Consider submitting the format and proposed MIME type to the Shared MIME-info database
- Document any standardization changes for users
- RFC 6838: Media Type Specifications and Registration Procedures
- IANA Media Types Registry: https://www.iana.org/assignments/media-types/
- file(1) Manual: https://man7.org/linux/man-pages/man1/file.1.html
- Shared MIME-info Database: https://gitlab.freedesktop.org/xdg/shared-mime-info/
This is a first sketch—you'd want to refine it based on your actual fast-magic codebase, add any specific quirks or edge cases you've encountered, and potentially expand sections based on how developers actually use the module. Does this capture the philosophy you're working with?
⬆ Top
📌 Wiki Home
⚡ CliFM Home
What is clifm?
Is it for me?
Main design and goals
Dependencies
Installation
Interface
Getting help
Configuration file
Command-line options
Command-line expansions
Commands
Keybindings
FAQ
ELN (entry list number)
Navigation
Basic file operations
Opening files
Sorting files
Filtering files
Selection
Search
Bookmarks
Trash
Archives
File details/Long view
Basic usage examples
Workspaces
Directory jumper
File opener
Actions (plugins)
Autocommands
Profiles
Aliases
The prompt
Tab completion (with fzf integration)
Auto-suggestions
Syntax highlighting
File tags
File names cleaner
Fastback and backdir
Remote file systems management
Light mode
Read-only mode
Stealth mode (incognito)
Disk usage analyzer mode
Desktop notifications
Environment
Files
Security
Tiling WM's and terminal multiplexers
Fzf mode for tab completion
File/image previews
Bulk operations
Archiving
Virtual directories
cp/mv progress bar
Send files to Android device
Git integration
Wildcards and REGEX
Multiple instances
Icons
Plugins
Customization
Custom MIME types
CD on quit
Files picker
Files lister (ls-mode)
stat(1) replacement
Subshell notification