git.iko.soy/typeable/pandoc
on 229b310 help sign in
43 lines 878 B history raw
1THIS=${0##*/}
3NEWLINE='
4'
6err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
7errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
9usage () {
10 err "$1 - $2" # short description
11 err "See the $1(1) man page for usage."
14# Portable which(1).
15pathfind () {
16 oldifs="$IFS"; IFS=':'
17 for _p in $PATH; do
18 if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
19 IFS="$oldifs"
20 return 0
21 fi
22 done
23 IFS="$oldifs"
24 return 1
27for p in pandoc $REQUIRED; do
28 pathfind $p || {
29 err "You need '$p' to use this program!"
30 exit 1
31 }
32done
34CONF=$(pandoc --dump-args "$@" 2>&1) || {
35 errcode=$?
36 echo "$CONF" | sed -e '/^pandoc \[OPTIONS\] \[FILES\]/,$d' >&2
37 [ $errcode -eq 2 ] && usage "$THIS" "$SYNOPSIS"
38 exit $errcode
41OUTPUT=$(echo "$CONF" | sed -ne '1p')
42ARGS=$(echo "$CONF" | sed -e '1d')