My Current Shell Script Input Filter

[Linux]

#!/usr/bin/bash

# Get the environment set up to access everything
PS_TO_PRINTER="gs -q -sDEVICE=ljet4 -sPAPERSIZE=letter -dNOPAUSE -dSAFER \
 -sOutputFile=- -"

MAGIC=$(file -)

# Rewindstdin comes in Red Hat's rhs-printfilters package.
/usr/local/bin/rewindstdin

case `echo $MAGIC | tr 'A-Z' 'a-z'` in
  *postscript* )
    $PS_TO_PRINTER ;;
  *ascii* | *text* | *english* | *script* )
    a2ps - -q -o - | $PS_TO_PRINTER ;;
  *"tex dvi file"* )
    dvips -f | $PS_TO_PRINTER ;;
  *)
    echo -e "Don't know how to print that type of file.\r"
    printf '\014' ;;
esac