# SLUG Mailing List Archives

## [SLUG] Re: Associating filenames

• To: slug@xxxxxxxxxxx
• Subject: [SLUG] Re: Associating filenames
• From: Angus Lees <gusl@xxxxxxxxxxxxxxx>
• Date: Wed Oct 18 18:54:31 2000
• User-agent: Mutt/1.0.1i

\begin{Howard Lowndes}
> Is there any ability in Linux to associate filename extensions, or
> similar, with applications.  I have been fiddling with Staroffice and
> that works OK, but I am curious as to whether the ability exists in
> Linux on a broader basis, more to do with such associations in
> Netscrape.

most unix programs that need to do these sorts of things do it through
mime types. and if they don't, then they should.

extension -> mime type mapping is done by /etc/mime.types (extensible
through ~/.mime.types). web pages, email attachments, etc already have
the mime type given, so they don't need to do this step (and thus can
have any extension). alternatively magic2mime(1) or similar can be
used to be a little more robust than simple filename comparisons.

mime type -> relevant program is done by /etc/mailcap (and ~/.mailcap)

simple wrapper scripts are provided for using this from the command
line:

see	 - runs a program to view the file (like windows' "start")
edit	 - edit a file with whatever program can handle it
compose - compose a new file using an appropriate editor (or sound
recorder, video grabber or something)
print	 - print the file

use these, these are good.

mime is good.

mime types are much better than simple extensions, since it also gives
a broad type (eg: text/*, image/*) - so programs can take guesses at
how to deal with unknown types.

mime types are much better than strict associations (like the mac),
since you may want to use a different program under different
circumstances. esp on unix, where you probably want an X program, a
console program, etc.

mime separates the "encoding" from the mime type. for example, if you
gzip the data, you still have the same mime type, only a new encoding
(this is why there is no application/x-gzip type). compressing on the
fly, etc, is thus a largely transparent act.

mime types are handled in user space, and so are easily customisable
by each user. nearly all mime programs allow each user to override
particular choices. try doing that on mac or windows.

/etc/mailcap is *much* more flexible than a simple windows
association. each mime type can have a description, a program to view
the type, a program to edit the type, a program to compose new files
of a type and a program to print the type. there are flags for whether
the viewer displays inline or needs to be run in a pager, etc. each
entry can have a condition to test to see if this entry should be used
(a typical test might be "test -n \$DISPLAY"). there is no way you're
going to get that in the kernel, and no way i want to configure it on
a file-by-file basis.

did i mention that mime is good?

it irritates me that netscape seems to not read the standard
/etc/mailcap anymore - and forces you to set it all up by hand.
it used to "do the right thing" a few versions ago.

debian at least has an extremely well setup and maintained
/etc/mailcap. i hope other distributions do too.

--
- Gus