#!/bin/sh
#
# txt2pdf - convert plain text to pdf
# dependencies: enscript | ps2pdf (ghostscript)

# stop on errors
set -eu

# check arguments
if [ "$#" != 1 ]; then
  printf '%s\n' "Usage: $(basename "$0") FILE.txt"
  exit 1
fi
if [ "$1" != "*.txt" ]; then
  printf '%s\n' "error: ${1} is not a .txt file"
  exit 1
fi
txtfile="$1"
pdffile="${txtfile%.txt}.pdf"

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