2

Using gnome terminal (Ubuntu 10.10), is there a way to execute the default application associated to a file type, only by typing its name, as it is possible with Windows ?

For example, say I create a mime type associated to every file with the pattern *.abc. Lets say I associate this file type to application 'my_app'.

If I have file 'my_file.abc' in current folder, what I want is that when I enter only 'my_file.abc' at the prompt, it executes 'my_app' feeding it with 'my_file.abc' as first argument. (assuming of course 'my_app' is in the path)

I appreciate this behaviour in Windows, wondering if Linux/Gnome could do that too. Thanks

2
  • You might have better luck on askubuntu Dec 10, 2010 at 16:21
  • Well, yes, actually, I didn't know askubuntu until now. Is there a way to "switch" this post to askubuntu ?
    – kebs
    Dec 10, 2010 at 20:55

4 Answers 4

3

You could use the binfmt_misc facility for something similar, but you're probably better off just passing it to xdg-open.

1
  • Very interesting, I'll investigate this tool, thank you.
    – kebs
    Dec 10, 2010 at 20:55
3

On Linux with zsh (http://www.zsh.org/) you could achieve it in this way:

$ alias -s abc=my_app

And after it zsh will always execute my_app youfile.abc when you just enter youfile.abc.

1

I don't know of any unix shell that allows you to execute any file in this way.

On Debian or Ubuntu, see myfile or edit myfile opens a file in the application that's associated to the file type through the mailcap mechanism. The command is from the mime-support package, which I think is installed by default on both Debian and Ubuntu (and anyway it's in many packages' dependencies, so it's probably installed already).

On many systems, you can use xdg-open myfile from the xdg-utils suite. This opens the file in the application that's associated to the file type through the Freedesktop mechanism. The Ubuntu package is xdg-utils, also probably installed already.

3
  • Yeah, xdg-open works fine, I was only trying to see if what was possible on Windows could be transposed to Linux ;-) I struggled a bit with binfmt_misc, but couldn't get it to work in a seimple way, i.e.: echo ':txt_file:E:*.txt:::/usr/bin/gedit::' > /proc/sys/fs/binfmt_misc/register but this doesn't work on my machine... I guess it wasn't designed to do such things in the beginning.
    – kebs
    Dec 14, 2010 at 13:46
  • And by the way, do you guys know if there is any difference between "see" and "xdg-open" ? They both seem to use the system's mime database...
    – kebs
    Dec 14, 2010 at 13:51
  • 1
    @kebs: see uses exactly the system's MIME database (including ~/.mailcap. I think xdg-open uses a completely different FreeDesktop-specified database, but Debian and Ubuntu packages tend to populate both these databases. Dec 14, 2010 at 22:15
1

You could use gnome-open for that. Works pretty well for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .