Skip to content

Add -mime GLOB: media-type predicate by extension (#90) - #219

Merged
helly25 merged 2 commits into
mainfrom
feat/mime-predicate
Jul 3, 2026
Merged

Add -mime GLOB: media-type predicate by extension (#90)#219
helly25 merged 2 commits into
mainfrom
feat/mime-predicate

Conversation

@helly25

@helly25 helly25 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

#90. -mime GLOB matches the entry's media (MIME) type - derived from its extension - against a shell glob.

$ xff assets -type f -mime 'image/*'      # every image, any extension
assets/logo.png
assets/hero.jpg
$ xff . -mime application/pdf
  • New xff/mime module: TypeForName(name) over a constexpr LimitedMap of ~44 common IANA-registered types (image/audio/video/text/application/font). Extension-based, no libmagic dependency (per the no-heavyweight-native-deps rule). Unknown/absent extension -> application/octet-stream (the file(1) fallback). Source-code extensions are deliberately omitted (language classification is feat(config): .xffrc grammar parser (config phase B1) #89).
  • EvalMime globs the type with fnmatch (like -type/-name). Name-based and cheap (no content read, no -type gate) - combine with -type f for regular files. xff extension (--config=find rejects it).

Self-doc: registry descriptor + kHelpText + design.md. Tests: mime_test (known / case-insensitive / compound / unknown / dotfile), evaluate_test (glob + octet-stream fallback), run_test e2e. bazel test //... green (40); both clang-format versions clean.

A content-sniffing backend can layer on later; for now the extension map is the fast, dependency-free first cut.

-mime GLOB matches the entry's media (MIME) type -- derived from its extension via
a curated static table in the new xff/mime module -- against a shell glob, so
-mime 'image/*' selects png/jpeg/gif/... at once, and -mime image/png the exact
type. Extension-based, no libmagic dependency (per the no-heavyweight-native-deps
rule); an unknown or absent extension is application/octet-stream (the file(1)
fallback). Name-based and cheap (no content read, no -type gate) -- combine with
-type f for regular files only. xff extension (find style rejects it).

xff/mime: TypeForName(name) over a constexpr LimitedMap of ~44 common
IANA-registered types (image/audio/video/text/application/font); source-code
extensions are left out (language classification is #89). EvalMime globs it with
fnmatch, like -type/-name. Self-doc: registry descriptor + kHelpText + design.md.
Tests: mime_test (table: known/case-insensitive/compound/unknown/dotfile),
evaluate_test (glob + octet-stream fallback), run_test e2e. bazel test //... green
(40); both clang-format versions clean.
@helly25
helly25 enabled auto-merge (squash) July 3, 2026 00:33
@helly25
helly25 merged commit 1a1cf73 into main Jul 3, 2026
8 checks passed
@helly25
helly25 deleted the feat/mime-predicate branch July 3, 2026 00:59
helly25 added a commit that referenced this pull request Jul 6, 2026
Remove five stale 'to do' bullets that describe already-implemented work,
so TODO.md stops listing done features as open:
- Right align numbers in summary  -> shipped (#202, #235)
- More output control for summary  -> shipped (#86, #203, #275)
- Align outputs like -ls           -> shipped (#205, #206, #207)
- Mimetype support                 -> shipped (#219 -mime)
- File type support                -> shipped (#262 -lang, #89)

Fix the 'Color support' cross-reference that pointed at the removed
'File type support' bullet to name -lang / {lang} / languages.yml directly.
Genuinely-open items (Line count {lines} field, per-file hashes, --sort/-j
CLI test, histograms #81) are untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant