#!/bin/sh
#
# txt2open - convert plain text to pdf in a tmpdir and open it
# dependencies: enscript(1)

set -eu

if [ "$#" != 1 ]; then
  printf '%s\n' "Usage: $(basename "$0") [FILE]"
  exit 1
fi

txtfile="$1"

# create tempfile for pdf
tmpfile="$(mktemp "${TMPDIR:-/tmp}"/"$(basename "$0")".pdf)"

# echo commands
set -x

# convert
enscript --quiet "${txtfile}" -o - | ps2pdf - "${tmpfile}"

# open
open "${tmpfile-}"
