Add a file extension to gedit in Ubuntu

December 20th, 2008 | Tags: , ,

I needed .ctp files to open with PHP syntax highlighting in gedit. After searching around online for a while I found the answer on the ubuntu forums.

Add

<glob pattern="*.ctp"/>

to the

<mime-type type="application/x-php">

declaration in the /usr/share/mime/packages/freedesktop.org.xml file and then run:

update-mime-database /usr/share/mime

in the console. Restart gedit and now everything works great!

  1. January 24th, 2009 at 11:58
    Reply | Quote | #1

    This doesn’t seem to be working 100% in Intrepid (8.10 amd64) :(

  2. January 26th, 2009 at 12:22
    Reply | Quote | #2

    @Joseph
    Just tried to edit /usr/share/gtksourceview-2.0/language-specs/php.lang. It looks like around Line #30 there is this…

    <property name="globs">*.php;*.php3;*.php4;*.phtml</property>

    I modified it to look like this…

    <property name="globs">*.php;*.php3;*.php4;*.phtml;*.ctp</property>

    but I am still having the problem.
    gnomevfs-info shows that my .ctp file has the application/x-php mime type so I’m not sure what to do here. Maybe a restart will help :-|

  3. January 26th, 2009 at 14:35
    Reply | Quote | #3

    @Joseph
    Okay I think I got it now. After doing all of the above I deleted:

    sudo rm -rf ~/.local/share/mime

    And then rebooted. Not sure if I even needed to do a full reboot or not but hey it’s working now so I’m not going to question it :-D

  4. Keerthi Bandara
    May 10th, 2009 at 09:23
    Reply | Quote | #4

    U missed

    update-mime-database /usr/share/mime

    I think here

  5. January 25th, 2010 at 06:59
    Reply | Quote | #5

    Thanks for the tip. I’m trying to use gedit as my IDE to replace Eclipse, and I needed the File Browser pane to recognize .phtml files. This tip did the trick.

TOP