Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I regularly work with a few sorts of plain text files, some of these are code files that I want to open in a programmer's text editor, others are large (gigabyte or more) data files that I only want to see in gedit. Nautilus' file association system considers all of these to be plain text files though, based on its determination of mime type, and saves only one preferred application for all of them.

Editing code in gedit is not fantastic, but accidentally opening a large data file in my relatively heavyweight code editor brings my system to a crawl for tens of minutes.

Is there any way to set up the file association system to use file extensions rather than mime type? Or some other solution that will let me set different preferences by file extension?

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can use mimeopen to set what application to use to open a file based upon it's extension.

Run mimeopen followed by the file extension you want to change. For example, if I wanted to open .py (python) files in Geany instead of Gedit I would run:

mimeopen .py  

Which returns (on my system, this will depend slightly based on what software you have installed on your computer):

Please choose a default application for files of type text/x-python

1) Geany  (geany)
2) notepad  (wine-extension-txt)
3) gedit  (gedit)
4) LibreOffice 4.0 Writer  (libreoffice4.0-writer)
5) Other...

use application #  

Inputting 1 and pressing Enter will open a blank .py file in Geany and set all further .py files to open in that editor.

If I put in 5 and press Enter I get the prompt:

use command:  

In which case I can use a program's command to open whatever file type I am currently changing.

So I could have done:

mimeopen .py  

Used 5 and put geany as the command to get the same result:

You might notice that if you run mimeopen .py again it will open a new .py file in Geany (or whatever app you chose) instead of asking you what application to use. In that case you need to use the -a handle, like this:

mimeopen -a .py
share|improve this answer
    
One final note, to complete the fix for Nautilus! Setting mimeopen as the default application for the file in the usual way (right click > open with > other application > 'use a custom command' > mimeopen) results in mimeopen's behaviour being used on double click in the file browser. Thanks! –  Pathogen Mar 28 '13 at 16:23
    
One final final note. Immediately after posting this, the 'open with other' steps I described above stopped working in Nautilus for reasons unknown. The solution is to change the default application in the file's properties, as described here –  Pathogen Mar 28 '13 at 16:31
    
I have an answer that describes that with screenshots here as well: askubuntu.com/a/256724/44179 –  Seth Mar 28 '13 at 16:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.