+++ /dev/null
-#!/bin/bash
-
-#########################################################################
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the version 3 of the GNU General Public License #
-# as published by the Free Software Foundation. #
-# #
-# This program is distributed in the hope that it will be useful, but #
-# WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
-# General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #
-# #
-# Written by and Copyright (C) Francois Fleuret #
-# Contact <francois@fleuret.org> for comments & bug reports #
-#########################################################################
-
-set -e
-
-# $Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $
-
-if [ ! "$*" ]; then
- echo "Need filenames to print!"
- exit 1
-fi
-
-tmp=$(mktemp /tmp/print.ps.XXXXXX)
-opts=""
-printing_cmd="lpr"
-
-function cleanup-before-exit () {
- rm ${tmp}
-}
-
-trap cleanup-before-exit EXIT
-
-for arg in "$@"; do
-
- if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then
-
- # The help option
-
- echo $(basename $0)" [<opt> ... <opt>] <file1> [[<opt> ... <opt>] <file2> ... ]"
- echo
- echo "A dumb printing utility. Options:"
- echo
- echo "-2pp two pages per page"
- echo "-4pp four pages per page"
- echo "-8pp eight pages per page"
- echo "-gv displays the result with gv instead of printing"
- echo "-stdout send the result to the standard output"
- echo "-P<printer> uses <printer> instead of $PRINTER"
- echo
- echo "Contact <francois.fleuret@epfl.ch>"
- echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $"
-
- exit 0
-
- elif [[ ${arg} == "-"* ]]; then
-
- # else, if it starts with '-' it is an option
-
- opts="${opts} ${arg}"
-
- else
-
- # else, it is a filename to print
-
- if [ -e "${arg}" ]; then
-
- TYPE=$(file -L "${arg}")
-
- noprint=""
-
- case $TYPE in
-
- *"image data"*)
- convert "${arg}" ps:${tmp}
- ;;
-
- *"TeX DVI"*)
- dvips -o ${tmp} "${arg}"
- ;;
-
- *"FIG image"*)
- fig2dev -L ps "${arg}" > ${tmp}
- ;;
-
- *"PostScript"*)
- cp "${arg}" ${tmp}
- ;;
-
- *"PDF"*)
- pdf2ps "${arg}" ${tmp}
- ;;
-
- *" text"*)
- # a2ps -B -R --columns=1 -f 8 -o ${tmp} "${arg}"
- # if isutf8 -q ${tmp}; then
- # echo "Can not print uf8 text."
- # exit 1
- # else
- a2ps --media=A4 --user-option=lp -o ${tmp} "${arg}"
- # fi
- ;;
-
- *"gzip compressed"*)
- echo "Unzipping "
- zcat "${arg}" > ${tmp}
- noprint=1
- $0 ${opts} ${tmp}
- ;;
-
- *)
- echo "Unable to handle type \"$TYPE\""; noprint=1
- ;;
-
-
- esac
-
- if [ ! "$noprint" ]; then
-
- # We apply all the filters seen up to now
-
- for f in ${opts}; do
- case $f in
- -2pp)
- tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
- psnup -d0 -m5 -2 < ${tmp} > ${tmp2}
- mv ${tmp2} ${tmp}
- ;;
- -4pp)
- tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
- psnup -d0 -m5 -4 < ${tmp} > ${tmp2}
- mv ${tmp2} ${tmp}
- ;;
- -8pp)
- tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
- psnup -d0 -m5 -8 < ${tmp} > ${tmp2}
- mv ${tmp2} ${tmp}
- ;;
- -gv)
- printing_cmd="gv"
- ;;
-
- -stdout)
- printing_cmd="cat"
- ;;
-
- -P*)
- printing_cmd="lpr"
- PRINTER=$(echo $f | sed -e s/^-P//)
- if [[ -z "$PRINTER" ]]; then
- echo "Error in the printer name. Use -P<printer> with no space."
- lpstat -a
- exit 1
- else
- echo "Using printer \"$PRINTER\""
- fi
- ;;
- *)
- echo "Unknown option $f"
- exit 1;;
- esac
- done
-
- if [[ "$printing_cmd" == "lpr" ]]; then
- echo "Printing on printer '$PRINTER'"
- show_queue=1
- fi
-
- ${printing_cmd} ${tmp}
-
- fi
-
- else
-
- echo "Can not find file ${arg}"
-
- fi
-
- fi
-
-done
-
-if [[ ${show_queue} ]]; then
- lpq
-fi
-
-exit 0