Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

system wide mimetype addition

by leocharre (Priest)
on Apr 19, 2010 at 13:20 UTC ( #835486=perlquestion: print w/replies, xml ) Need Help??
leocharre has asked for the wisdom of the Perl Monks concerning the following question:

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="">
    <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>
      <glob pattern="*.yml"/>
         <match value="---" type="string" offset="0"/>
      <expanded-acronym>Yaml Aint Markup Language</expanded-acronym>
  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'/ to?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://835486]
Approved by Corion
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-09-19 21:21 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (229 votes). Check out past polls.