#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/printers-print . ~/public_html/conf/.zsh/pdf-meta print-pdf-odd-pages () { local pdf=$1 local pages pages=$(pdf-length $pdf) for p in {1..$pages}; do (( $(( $p % 2 != 0 )) )) && lp -P $p $pdf done } # PDF and text reset-and-print () { local files=($@) reset-printer doprint $files } doprint () { local files=($@) local sleep_time=0 local type for f in $files; do if [[ ! -f $f ]]; then no-file-msg $f return fi type=$(file -b $f) if [[ $type == "ISO-8859 text" ]]; then longest-line-test $f [[ 0 != $? ]] && return lpr -P $LPDEST =(iso2utf $f) else lpr -P $LPDEST $f fi (( $sleep_time )) && sleep $sleep_time done } doprint-b () { local files=($@) lpr -o fit-to-page $files } # jpg print-jpg () { local fs=($@) for f in $fs; do reset-printer { jpegtopnm $f | pnmtops | lpr -P $LPDEST } 2> /dev/null sleep 1 done } # text # with Emacs, use these as the first line: # -*- encoding: iso-8859-1 -*- # -*- encoding: utf-8 -*- # ISO=8859-1 -> UTF-8 iso2utf () { local file=$1 iconv -f iso-8859-1 -t utf-8 $file } # ISO=8859-1 <- UTF-8 utf2iso () { local file=$1 iconv -f utf-8 -t iso-8859-1 $file } paginate-ascii () { local file=$1 pr -D "" --indent=8 -w 62 -l 68 $file } longest-line-test () { local file=$1 local longest_line=$(wc -L $file | awk '{print $1}') local max_line_chars=79 if (( $longest_line > $max_line_chars )); then echo "$0: too long line(s) in $f (${longest_line} > ${max_line_chars})" >&2 return 1 fi }