#!/bin/sh
#
# mmd2all --- MultiMarkdown convenience script
#	<http://fletcherpenney.net/multimarkdown/>
#	Fletcher T. Penney
#
# Pass arguments on to the binary to convert text to multiple
# formats and open them
#

# Be sure to include multimarkdown in our PATH
unset CDPATH
SCRIPT="$0"
while
	DIR="$(cd -P -- "$(dirname -- "$SCRIPT")" && pwd)"
	test -h "$SCRIPT"
do
	SCRIPT="$(readlink "$SCRIPT")"
	[ "$SCRIPT" = "${SCRIPT#/}" ] && SCRIPT="$DIR/$SCRIPT"
done
PATH="$DIR:/usr/local/bin:$PATH"
export PATH

if ! command -v multimarkdown >/dev/null 2>&1
then
	echo multimarkdown executable not found! >&2
	exit 1
fi

if [ $# = 0 ]
then
	echo "Can't work on stdin"
else
until [ "$*" = "" ]
do
	file_name=`echo $1| sed 's/\.[^.]*$//'`

	multimarkdown -b "$1"
#	open "$file_name.html"

	multimarkdown -b -t epub "$1"

	multimarkdown -b -t latex "$1"
#	mate "$file_name.tex"

	multimarkdown -b -t odf "$1"
#	open "$file_name.fodt"

#	multimarkdown -b -t opml "$1"
#	open "$file_name.opml"

	shift
done
fi
