I often have files of the same type (eg: text, html, jpg) created by different programs, so if I double-click or type
open foo.jpg
the file might open in Preview, or Photoshop, or AppleWorks, or whatever. With html and text documents, depending on what I would like to do, I might want to open the file in SubEthaEdit, or in a WYSIWYG editor, or browse it in Safari.
Although it is not hard to type
open -a Preview foo.jpg
it is more annoying to remember to type
open -a "Adobe Photoshop 7.0" foo.jpg
and when I accidently invoke Photoshop, I have to sit there for 30 seconds watching it lumbering to start up, when it would be nice to have a chance to abort and open in Preview. So to learn a bit about zsh shell scripting, I wrote a zsh shell script called edit.zsh. You can make the script executable and drop it into /usr/local/bin/edit (or your favorite directory), and invoke it by typing
edit filename
to open a file in an appropriate program, or
edit -f filename
to force the file to be opened in your default editor. You can do this with any user shell as long as the file is in your path. Also, you can make it a zsh function (it will not work as a bash or ksh function because of the differing syntax.)
Mac OS X Hints
http://hints.macworld.com/article.php?story=2004012218171997