[conspire] myopen(1)

Eric De Mund ead-conspire at ixian.com
Thu Mar 26 02:40:48 PDT 2009


Rick,

Well, I've given your words regarding exo-open(1) and freedesktop.org's
use of the shared mime-info cache (mimeinfo.cache) a whole bunch of
thought, and I have to agree with you.

I've determined that my problem was that, with my use of exo-open(1), I
crossed the line from laziness (the first virtue of a programmer [1]) to
out-and-out delegation. Or maybe delegation to a program that doesn't
share my values.

My problems with freedesktop.org's exo-open(1) and D-Bus [2] were:

1.  D-Bus, which exo-open(1) uses, is entirely too complex a solution
    for such a simple problem as opening a file.

2.  The documentation for both stinks. I shouldn't have to spend days
    crawling web sites and then through C code to determine how each
    works. All I want to do, after all, is open a file.

3.  The real rub: I don't get full control of applications with the
    XDG_DATA_DIRS environment variable. Full control means I'm able to
    specify the full search path for mimeinfo.cache, beyond which NO
    additional searching takes place. Unfortunately, I don't get that.
    Instead, I get "search my path and then (unconditionally) proceed on
    to your hard-coded system path" behavior. No thank you. I want full
    control. (And come on people, this is not hard to implement. Where's
    the softness? Software is supposed to be soft, flexible, *rich* in
    its support of usage patterns, not just providing one mode of usage.)

4.  Also, it seems that the design of mimeinfo.cache, or rather of how
    it's managed (touched) by developers, is flawed. "Design" may not be
    the right word, but the problems appear to be:

4a. There doesn't appear to be any agreement on how developers (of GIMP,
    of evince, of xpdf, to speak of PDF-capable programs, for example)
    should be touching mimeinfo.cache. Is it a complete free-for-all? Is
    any program allowed to edit mimeinfo.cache, and put itself first in
    line, as the preferred handler for a particular type of file?

    Refreshing people's memory, what touched off this whole trip down
    the rabbit hole for me was the fact that one day I found that, at
    the command line, "o myfile.pdf" (alias o=exo-open) was invoking
    GIMP (hello!), while the previous day my preferred evince(1) was
    being invoked.

4b. Even if there are freedesktop.org project guidelines for applica-
    tions on how and when they're to touch mimeinfo.cache, there doesn't
    appear to be any way for me, the user, to weigh in with a standing
    declaration of "If an entry (i.e. an application or a list of appli-
    cations) for file type 'application/foo' appears in the file, please
    append rather than prepend yourself to that entry/list." Again, not
    rocket science.

But they didn't write the software this way, and so I went and wrote my
own Bourne shell script, called myopen(1) [3], to do this. It takes the
entries in a text file called $HOME/.myopen, e.g.

    # begin .myopen ---------------------------------------------
    #
    DEFAULT:    less -FiMX
    iso:        isoinfo -l -R -i FILE | less -FiMX
    log:        -                   # DEFAULT
    odt:        openoffice
    ogg:        xmms
    pdf:        evince
    png:        display             # ImageMagick(1)'s display(1)
    txt:        -                   # DEFAULT
    zip:        unzip -l FILE | less -FiMX
    #
    # end .myopen -----------------------------------------------

and causes the specified program to be invoked (for instance, evince(1))
when for instance "myopen myfile.pdf" is issued.

Here's its manual page, in case anyone is having trouble sleeping this
evening.

    -----------------------------------------------------------------
    NAME
         myopen - open a file with associated handler

    SYNOPSIS
         myopen [-f <handler-file>] [-n] [-v] <file>
         myopen --help
         myopen --manual
         myopen --version

    DESCRIPTION
         myopen  opens  a  file  with its  handler  application,  the
         program associated with that particular type of file.

    OPTIONS
         --help
              Print usage message.

         -f <handler-file>
              The  handler  file,  that  contains  the file type <-->
              application mapping. If not specified, this defaults to
              $HOME/.myopen.

              This  file   contains  a  list  of   file  types  (file
              extensions)  and their associated applications (be they
              executable binaries or scripts).  Each line consists of
              a file extension,  followed by a colon  (":"), followed
              by whitespace  (any non-zero combination  of spaces and
              tabs), followed by a string to execute. In its simplest
              form,   that    string   is   an    application   name.
              Alternatively,  it  may  be  an application  name  with
              options.  Finally, it may be a pipeline  of such simple
              commands,  with  the  reserved  word  FILE representing
              <file>.

              The  special  file  type of NOEXT represents files with
              either no extension or with a trailing dot (".").

              If no application is associated with a file type, or if
              an application of DEFAULT  (or NONE or -) is associated
              with a file type,  then the application associated with
              the  special file  type  of DEFAULT  is  used. If  that
              special DEFAULT  type isn't found,  or if it's found to
              have  an  associated  application of NONE or -, then no
              action is taken.

              If  the  special application of STOP or ! is associated
              with a file type, then myopen exits immediately without
              taking any action.

              Lines  may  be blank,  or  may  contain comments  (i.e.
              strings beginning with "#" and continuing to the end of
              the  line).  Blank  lines  are  ignored.  Comments  are
              removed. Trailing whitespace is ignored.

              This is best described with an example:

              ##---------------------------------------------------##
              ##    .myopen                                        ##
              ##---------------------------------------------------##

              # DEFAULT type values:
              #     An application, NONE, or -.
              # File type values:
              #     An application, DEFAULT, NONE, -, STOP, or !.

              # file type name
              # |       file type value (typically an application)
              # |       |
              # v       v

              DEFAULT:  less -FiMX    # if no other file handler

              NOEXT:    -             # no file ext, or ending in "."
              avi:      vlc
              bmp:      display       # ImageMagick(1)'s display(1)
              bin:      !             # STOP (do nothing and exit)
              doc:      openoffice
              flac:     xmms
              gif:      display
              jpeg:     display
              jpg:      display
              iso:      isoinfo -l -R -i FILE | less -FiMX
              log:      -             # DEFAULT
              m3u:      xmms
              mp3:      xmms
              odt:      openoffice
              ogg:      xmms
              pdf:      evince
              png:      display
              ps:       evince
              rm:       mplayer       # RealMedia
              sh:       -             # DEFAULT
              tif:      display
              tiff:     display
              torrent:  deluge
              txt:      -             # DEFAULT
              zip:      unzip -l FILE | less -FiMX

              ##---------------------------------------------------##
              ##    end .myopen                                    ##
              ##---------------------------------------------------##

         --manual
              Print this manual page.

         -n   Don't open <file> with handler,  but instead just print
              the command that would be invoked.

         -v   Verbose. Print the command that will be invoked.  Also,
              print a note if no  associated  handler  is  found  for
              <file>.

         --version
              Print version number.

    BUGS
         This  is  a  quick  hack and not the proper approach to this
         problem.  A  proper  approach  is to have the file type <-->
         application  mapping  be  determined  by  the file's  actual
         contents (e.g. as reported by file(1))  rather  than  by its
         filename extension.  Look for that capability in an upcoming
         release.

    COPYRIGHT
         Copyright 2009 Eric De Mund.  This program is free software:
         you can redistribute it  and/or modify it under the terms of
         the  GNU  General  Public  License  as published by the Free
         Software Foundation, either version 3 of the License, or (at
         your option) any later version.

         This  program  is  distributed  in  the hope that it will be
         useful, but WITHOUT ANY WARRANTY;  without  even the implied
         warranty of MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR
         PURPOSE.  See  the  GNU  General  Public  License  for  more
         details.

         You  should  have received  a copy of the GNU General Public
         License   along    with   this   program.    If   not,   see
         <http://www.gnu.org/licenses/>.

    SEE ALSO
         echo(1), cat(1), egrep(1), fgrep(1), more(1), sed(1), sh(1),
         tail(1), tty(1).

    AUTHOR
         Eric De Mund <ead-myopen at ixian.com>

    DATE
         17 March 2009

    VERSION
         $Ixian: myopen,v 1.7 2009-03-26 00:42:35 ead Exp $

    -----------------------------------------------------------------
    *****************************************************************

Regards,
Eric

notes:

1. Virtues of a programmer
   http://en.wikipedia.org/wiki/Larry_Wall#Virtues_of_a_programmer

2. D-Bus
   http://www.freedesktop.org/wiki/Software/dbus

3. myopen(1)
   http://ixian.com/ead/tmp/myopen
--
"That destructive siren, sloth, is ever to be avoided." --Horace

Eric De Mund   | Ixian Systems           | Jab: eadixian at jabber.org/main
ead at ixian.com  | 650 Castro St, #120-210 | Y!M: ead0002
ixian.com/ead/ | Mountain View, CA 94041 | ICQ: 811788




More information about the conspire mailing list