Registering Rails File Extensions in GEdit

Written on 8:59:00 PM by S. Potter

I just wanted to slap a quick howto for a couple of my professional and open source associates to get going with GEdit quickly while developing Ruby on Rails applications. GEdit uses Gnome's VFS for mime-type determination. To register new file mime-types for Gnome's VF do the following:

  1. Create XML file with the following contents:
    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="">
      <mime-type type="application/x-ruby">
        <alias type="application/ruby" />
        <comment xml:lang="en">Ruby Rake Tasks</comment>
        <glob pattern="*.rake"/>
      <mime-type type="application/x-ruby">
        <comment xml:lang="en">Rakefile</comment>
        <glob pattern="Rakefile"/>
      <mime-type type="text/html">
        <comment xml:lang="en">eRB HTML Markup</comment>
        <glob pattern="*.rhtml"/>
      <mime-type type="application/x-javascript">
        <comment xml:lang="en">eRB JavaScript</comment>
        <glob pattern="*.rjs"/>
      <mime-type type="text/xml">
        <comment xml:lang="en">eRB XML</comment>
        <glob pattern="*.rxml"/>
      <mime-type type="text/x-yaml">
        <comment xml:lang="en">YAML</comment>
        <glob pattern="*.yml"/>
  2. Copy file to /usr/share/mime/packages/rails.xml
  3. Execute sudo update-mime-database /usr/share/mime
  4. Enjoy!

If you enjoyed this post Subscribe to our feed


  1. Anonymous |

    Do you know of a way to add color support for these mime types to gedit, or is that a lot harder. Thanks for the tip by the way.

  2. S. Potter |

    With the exception of YAML all the other language specs were defined on my Linux installation (Fedora Core 6). In the case of YAML, you will need to create a file at /usr/share/gtksourceview-1.0/language-specs/yaml.lang that looks something like the following (although it is far from perfect):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE language SYSTEM "language.dtd">
    <language _name="YAML" version="1.0" _section="Others" mimetypes="text/x-yaml">


    <string _name="String" style="String" end-at-line-end="FALSE">

    <string _name="Constant String" style="String" end-at-line-end="FALSE">

    <line-comment _name="Line Comment" style="Comment">

    <pattern-item _name="Scalar Value" style="Scalar Value">

    <pattern-item _name="List Item Value" style="List Item Value">
    <regex>^\- .*</regex>

    <pattern-item _name="Key" style="Key">

    <pattern-item _name="Inner Key" style="Inner Key">

    Then after the language spec is defined for gtksourceview you can customize the colors to be used for each pattern item in GEdit's Preferences (under the Syntax Highlight tab).

    HTH and let me know how I can tweak the yaml.lang file further if you play around with it.

  3. Anonymous |

    I can't seem to get it working right, your syntax looks right, but it's not matching any of my yaml. I have a simple assoc array like

    title: Cool Blogs
    blog: Snakes, Gems & Coffee
    topic: Rails with Gedit

    I set all the types to different colors in my gedit and it's still all uncolored. If I ever get free moment between my projects then I'll work on it, but right now, I'm busy working 60+ hours/week in PHP.

  4. Anonymous |

    did you go to View->Highlight Mode and then choose YAML under whichever menu you told it to be in when you created the yaml.lang file?


Post a Comment