I wanted my gnu system to recognize mimetypes for some metaformat filetypes, such as yaml. (Ideally I want system wide recognition- but it seems many different (
file/)
mimetype(?) like calls have varying sources of resource to refer to.)
Here's what I tried with some satisfying level of success.
- I created a file to help describe the content:
# cat /usr/share/mime/packages/yaml.xml
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="text/yaml">
<comment>YAML document</comment>
<comment xml:lang="bg">Документ — YAML</comment>
<comment xml:lang="ca">document YAML</comment>
<comment xml:lang="cs">Dokument YAML</comment>
<comment xml:lang="de">YAML-Dokument</comment>
<comment xml:lang="en_GB">YAML document</comment>
<comment xml:lang="es">documento YAML</comment>
<comment xml:lang="eu">YAML dokumentua</comment>
<comment xml:lang="fi">YAML-asiakirja</comment>
<comment xml:lang="fr">document YAML</comment>
<comment xml:lang="hu">YAML dokumentum</comment>
<comment xml:lang="it">Documento YAML</comment>
<comment xml:lang="ja">YAML ドキュメント</comment>
<comment xml:lang="ko">YAML 문서</comment>
<comment xml:lang="nb">YAML-dokument</comment>
<comment xml:lang="nl">YAML-document</comment>
<comment xml:lang="nn">YAML-dokument</comment>
<comment xml:lang="pl">Dokument YAML</comment>
<comment xml:lang="pt_BR">Documento YAML</comment>
<comment xml:lang="sv">YAML-dokument</comment>
<comment xml:lang="uk">Документ YAML</comment>
<comment xml:lang="vi">Tài liệu YAML</comment>
<acronym>YAML</acronym>
<glob pattern="*.yml"/>
<magic>
<match value="---" type="string" offset="0"/>
</magic>
<expanded-acronym>Yaml Aint Markup Language</expanded-acronym>
</mime-type>
</mime-info>
- And ran update-mime-database
- What works now..
- Now the command mimetype can recognize some yaml:
# mimetype t/files-yaml/*
t/files-yaml/CVS: inode/directory
t/files-yaml/data.yml: text/yaml
t/files-yaml/head.var: text/plain
t/files-yaml/head.yml: text/yaml
t/files-yaml/yaml.dat: text/yaml
- cli 'file' cannot recognize.. (must need to be pointed to some magic file created by update-mime-database ? or such
)
# file t/files-yaml/*
t/files-yaml/CVS: application/x-not-regular-file
t/files-yaml/data.yml: text/plain; charset=us-ascii
t/files-yaml/head.var: text/plain; charset=us-ascii
t/files-yaml/head.yml: text/plain; charset=us-ascii
t/files-yaml/yaml.dat: text/plain; charset=us-ascii
- File::MMagic cannot recognize the yaml type at this point.
-
- (Various 1 2 places suggest that File::MimeInfo should work at this point. I tried that and later noticed it's File::MimeInfo::Magic that will make use of the magic database info instead of globs (filename extension).
(seems like it's meant to recognize blobs (filename extensions) only. However, various places suggest that it should work- these places should be pointing instead to File::MimeInfo::Magic))
- File::MimeInfo::Magic can now recognize yaml.
Questions..
Is there a more posixy accepted method of registering mimetypes that I'm missing (which is surely staring me in the face)?
Does registering types via the mime database seem like a good way to do this? And if so- how do I configure 'file' command to work as 'mimetype' (no, please.. no symlinks, i mean, like.. serioulsy, like..)
Should I perhaps be investigating how to get 'file' to recognize a new mimetype, before I try to get 'mimetype'/freedesktop.org to?