This HOWTO describes how to set the File and MIME type of files manually and also how to associated MIME icons to specific types of files.
In this HOWTO I'm setting the MIME type 'text/x-R' which corresponds to the file extension '.R'. I'm using this file type because it is a script language recognized by Gedit and it is not automatically set when the package R is installed (R is a powerful program which is a environment and a language for statistical and graphical analysis, see http://www.r-project.org/). In the end we will also set a customized icon to the new File/MIME type. The advantage of doing this setting is that Gedit will automatically associated the correct highlighting mode for the script language and we will have a nicer looking to the R script files.
HOWTO:
1. Create or choose a customized icon for your file type. In my case I created the icon 'gnome-mime-text-R.png'.
2. Create a file to test the HOWTO. I created the file 'test.txt', in the Desktop directory, with the following content:
The actual Type and MIME type of this file are 'plain text' and 'text/plain', respectively. The icon is the default text icon used by the current icon theme. If you open the 'test.txt' file with the Gedit program you will see that the text looks like a normal text and not a highlighted language. The same would be true for a .R file.# short example of R script with vector manipulation and plotting
x <- c(2,3,4,5,6,9)
y <- c(7,5,4,3,2,1)
plot(x, y, pch=19)
a = 2*x - 2*y
a
plot(a)
3. Create the information of the new MIME type in the file that store the the MIME types:
sudo cp /usr/share/mime/packages/freedesktop.org.xml /usr/share/mime/packages/freedesktop.org.xml_backup
sudo gedit /usr/share/mime/packages/freedesktop.org.xml
In the opened file, add the following information that contains the mime-type as 'text/x-R' and the name of the file type (R code):
between the information of two other MIME files as in the example bellow:<mime-type type="text/x-R">
<sub-class-of type="text/plain"/>
<comment>R code</comment>
<comment xml:lang="az">R kodu</comment>
<comment xml:lang="bg">Код на R</comment>
<comment xml:lang="cs">Kód R</comment>
<comment xml:lang="cy">Côd R</comment>
<comment xml:lang="de">R-Befehle</comment>
<comment xml:lang="el">κώδικας R</comment>
<comment xml:lang="eo">R-kodo</comment>
<comment xml:lang="es">Código R</comment>
<comment xml:lang="eu">R kodea</comment>
<comment xml:lang="fi">R-koodi</comment>
<comment xml:lang="fr">code R</comment>
<comment xml:lang="hu">R-kód</comment>
<comment xml:lang="it">Codice R</comment>
<comment xml:lang="ja">R コード</comment>
<comment xml:lang="ko">R 코드</comment>
<comment xml:lang="ms">Kod R</comment>
<comment xml:lang="nb">R-kildekode</comment>
<comment xml:lang="nl">R-code</comment>
<comment xml:lang="nn">R-kode</comment>
<comment xml:lang="no">R-kildekode</comment>
<comment xml:lang="pl">Kod R</comment>
<comment xml:lang="pt">código R</comment>
<comment xml:lang="pt_BR">Código R</comment>
<comment xml:lang="sq">Kod R</comment>
<comment xml:lang="sr">R ко̂д</comment>
<comment xml:lang="sv">R-kod</comment>
<comment xml:lang="uk">Код R</comment>
<comment xml:lang="zh_CN">R 代码</comment>
<glob pattern="*.R"/>
</mime-type>
Save and close the file.insert here -->...</mime-type>
<glob pattern="*.py"/>
<mime-type type="text/x-readme">
<sub-class-of type="text/plain"/>
<comment>README document</comment>
...
4. Update the MIME database with the command:
sudo update-mime-database /usr/share/mime/
and now the new file and MIME types for the *.R files will be 'R code' and 'text/x-R', respectively.
4.a. If you see a error in the parsing of the .xml file, this is because you edited wrong the freedesktop.org.xml file, so go back and adjust the file or restore the back up with the command:
sudo mv -f /usr/share/mime/packages/freedesktop.org.xml_backup /usr/share/mime/packages/freedesktop.org.xml
and go back to step 3 of this HOWTO.
5. Now, let's associate the icon with the new file/MIME type. Put the icon into the directory /usr/share/icons/name_of_the_icon_theme_used/mime.types/. Please, note that this will put the icon in a place that can be used by all users of the cumputer. Important: If you keep your icons in your home directory, replace /usr/share/icons by /home/.icons/ in the next steps.
sudo mv -i path/to/file/gnome-mime-text-R.png /usr/share/icons/name_of_the_icon_theme_used/scalable/mimetypes/
Obs: if you already has a file with this name, choose 'no' and give another name to you file. If you don't have a file with the same name you will not be asked anything.
6. Edit the file with the icons' information:
UPDATED Feb 10, 2007: The "mime-support" package recommends the creation of a .mime-types in the home directory instead of editing the file present in the system installation.
sudo cp /usr/share/icons/name_of_the_icon_theme_used/mime.types /usr/share/icons/name_of_the_icon_theme_used/mime.types_backup
sudo gedit /usr/share/icons/name_of_the_icon_theme_used/mime.types
Add the following line to the mime-types file:
Save and close the file.text/x-R R
To do this with other files, just replace the file and MIME type information. To associate specific programs to open your new file and MIME types follow the nautilus instructions of "open with"...
7. Test the files and your environment to see if everything is fine:
sudo cp path/to/file/test.txt path/to/file/test.R
Now the file test.R will appear with the customized icon. If you open this file with Gedit it will appear highlighted with the R script language.
Obs: check if your Gedit is set to show syntax highlighting by using the menu EDIT -> PREFERENCES -> SYNTAX HIGHLIGHTING and see if the box 'Enable syntax highlighting' is checked. You can also customize the highlighting colors used by Gedit...
8. If there is no any problem in your system or files, you can now remove the back-up files:
sudo rm /usr/share/mime/packages/freedesktop.org.xml_backup
sudo rm /usr/share/mime/globs_backup
sudo rm /usr/share/icons/name_of_the_icon_theme_used/mime.types_backup
otherwise restore them as described in 4.a., but changing the appropriated names and paths.
and that is it.
Bookmarks