#!/bin/sh
# This script is an attempt to provide some subset of the 'open'
# command found in MacOS X for the other UNIX variants I use. The
# basic idea behind the 'open' command is that it figures out what
# application should be used to open a file based upon the file's
# type. For example, 'open foo.jpeg' would open up foo.jpeg with
# 'Preview.app' on a mac, so this script, on UNIX, would open up
# foo.jpeg with 'xv'.
# Figure out file name and 'application'
if test "$1" = "-a"
then # have -a option
file_name=$3
appl_name=$2
# Test for no application given with -a flag..
if test -z "$appl_name"
then
echo "Use: open [-a application] file"
exit
fi
# Test for extra arguments (we only work with one file argument)
if test "$4"
then
echo "Use: open [-a application] file"
exit
fi
else # no -a option
file_name="$1"
appl_name=
# Test for extra arguments (we only work with one argument)
if test "$2"
then
echo "Use: open [-a application] file"
exit
fi
fi
# Check for a file name
if test -z "$file_name"
then
echo "Use: open [-a application] file"
exit
fi
# if we have an application, then we are done
if test "$appl_name"
then
$appl_name $file_name
exit
fi
# Figure out if we have an extension
if echo $file_name | grep '\.'
then
ext=`echo $file_name | sed 's/^.*\.//'`
#echo File: $file_name
#echo Ext: $ext
else
echo "don't know how to open $file_name (no extension)"
echo "Use: open [-a application] file"
exit
fi
# Figure out what to run the file with, or give up.
case $ext in
pdf)
xpdf "$file_name" &
;;
png|gif|jpeg|jpg|xwd|fits)
pqiv "$file_name" &
;;
c|cc|cxx|cpp|h|f77|R|sh|pl|cl|el|scm|sql)
emacs "$file_name" &
;;
txt|tex)
emacs "$file_name" &
;;
dvi)
xdvi "$file_name" &
;;
ps|eps)
gv "$file_name" &
;;
gz)
gunzip "$file_name"
;;
html|htm)
lynx "$file_name"
;;
tar)
tar xvf "$file_name"
;;
*)
echo "Don't know how to open files with extension: '$ext'"
echo "Use: open [-a application] file"
exit
;;
esac