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.
  1. 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>
    
  2. And ran update-mime-database
  3. 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.
  4. 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?


    In reply to system wide mimetype addition by leocharre

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  5. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  6. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  7. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  8. Please read these before you post! —
  9. Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  10. You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  11. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  12. See Writeup Formatting Tips and other pages linked from there for more info.