Index: en_US.ISO8859-1/books/handbook/printing/chapter.xml =================================================================== --- en_US.ISO8859-1/books/handbook/printing/chapter.xml +++ en_US.ISO8859-1/books/handbook/printing/chapter.xml @@ -775,11 +775,10 @@ A filter that detects the type of input and automatically converts it to the correct format for the - printer can be very convenient. The first two characters of - a &postscript; file are usually %!. A - filter can detect those two characters. &postscript; files - can be sent on to a &postscript; printer unchanged. Text - files can be converted to &postscript; with + printer can be very convenient. The &man.file.1; + command can be leveraged to recognize &postscript; files. + &postscript; files can be sent on to a &postscript; printer + unchanged. Text files can be converted to &postscript; with Enscript as shown earlier. Create /usr/local/libexec/psif with these contents: @@ -789,20 +788,22 @@ # psif - Print PostScript or plain text on a PostScript printer # IFS="" read -r first_line -first_two_chars=`expr "$first_line" : '\(..\)'` -case "$first_two_chars" in -%!) - # %! : PostScript job, print it. +# Pass $first_line to file(1) and extract the mime type it found +mime=`echo "$first_line" | file -bi - | cut -f 1 -d ";"` + +if [ "$mime" = "application/postscript" ]; then + # PostScript job, print it. echo "$first_line" && cat && exit 0 exit 2 - ;; -*) - # otherwise, format with enscript +elif [ "${mime%%/*}" = "text" ]; then + # Text file, format with enscript ( echo "$first_line"; cat ) | /usr/local/bin/enscript -o - && exit 0 exit 2 - ;; -esac +fi + +# Unsupported MIME type, exit with error state +exit 2 Set the permissions and make it executable: