#!/bin/bash
#
# usage:  
#   latestfile  .. displays the name of the latest file in current directory
#   latest -op  .. opens file with application specified by op
#   	-o      .. use "open"
#       -v      .. use "vi"
#       -any    .. use "any"


a="$(ls -1tr | tail -1)"   #capture last name 

if [ $# -gt 1 ]; then            #check for bad or incorrect usage
  echo "too many paramters: quit"; exit -1
fi

if [ $# = 0 ]; then
	echo $a; exit
fi

if [ $1 = "-o" ]; then
	open "$a"; exit
   elif [ $1 = "-v" ]; then
	vi "$a"
   else
	${1#-} "$a"
fi
