#!/bin/sh -
MYBIN="$HOME/binp"

pref='libreoffice ooffice soffice'

# office - system *office front-end with some extension corrections
# Steve Kinzler, steve@kinzler.com, Dec 10/Jul 11
# https://kinzler.com/me/home.html#unix

# KLUDGE to rename a single-arg .doc|xls file that's actually a .docx|xlsx
case "$1,$2" in
--,*.doc|--,*.xls)	shift;;
esac
case "$1" in
*.doc|*.xls)	case `od -c "$1" 2> /dev/null | head -1` in
		'0000000   P   K 003 004 '*)
			echo "$0: renaming $1 to $1x"
			if mv "$1" "$1"x
			then
				x="$1";			  shift
				set x -- "$x"x ${1+"$@"}; shift
			fi;;
		esac;;
esac

case "$OFFICECMD" in
'') path=${BACKPATH-`echo ":$PATH:" | sed "s:$MYBIN::g; s/^://; s/:$//"`}
    OFFICECMD=`wh -p "$path" $pref 2> /dev/null | sed 1q`; export OFFICECMD;;
esac

case "$OFFICECMD,$1" in
*libreoffice*,--)	shift;;
esac

exec "$OFFICECMD" ${1+"$@"}
