The xmhprint Shell Script

[return-to Explanation of xmhprint] [table of contents] [index]
#! /bin/sh
# $Id: xmhprint,v 1.6 92/07/25 07:12:47 jerry book2 $
### xmhprint - print command for xmh
### Usage (in X resource): xmh*PrintCommand: xmhprint [-cmd_num]
##
##  THE PRINTER SUPPORT WITH xmh ISN'T VERY GOOD.
##  IT HANDS ALL YOUR MESSAGE FILES TO A PRINTER COMMAND AT ONCE.
##  IT DOESN'T FILTER THEM TO REMOVE UNINTERESTING HEADER LINES.
##  YOU CAN'T USE A PIPE AS PART OF THE PRINTER COMMAND BECAUSE xmh 
##  PUTS THE MESSAGE FILENAMES AT THE END OF THE PRINTER COMMAND LINE.
##  
##  THIS PROGRAM, xmhprint, TAKES MESSAGE FILENAMES(S) FROM THE
##  COMMAND LINE, AS WELL AS (MAYBE) ONE OPTION.
##  THE SHELL SCRIPT GETS THE MESSAGE FILENAMES FROM xmh, AND IT CAN
##  PROCESS THEM ANY WAY YOU WANT IT TO.
##  THE OPTIONS LET YOU CHANGE YOUR PRINT SETUP EASILY--INSTEAD OF
##  STORING A COMPLICATED xmh*PrintCommand IN THE RESOURCE MANAGER,
##  JUST CHANGE THE OPTION ON THE xmhprint COMMAND LINE LIKE THIS:
##      xmh*PrintCommand: xmhprint -p2
##  
##  YOU CAN CUSTOMIZE THIS SCRIPT TO FIT YOUR NEEDS.
##  ADD mhl(1) TO CLEAN UP THE MESSAGE HEADERS, USE OTHER PRINTERS,
##  USE A POSTSCRIPT FILTER... GO WILD!
##
##  SET YOUR SYSTEM PRINTER IN THE printcmd VARIABLE.  STORE ANY
##  $printcmd OPTIONS THERE, TOO -- OR SET AN ENVIRONMENT VARIABLE LIKE
##  $PRINTER (IF YOUR SYSTEM HAS THAT) BEFORE STARTING xmh.
##  
##  lpr AND lp PRINT ERROR MESSAGES TO THE STANDARD OUTPUT INSTEAD
##  OF THE STANDARD ERROR ON SOME VERSIONS OF UNIX!  xmh R4 AND R5
##  WILL SHOW YOU stderr MESSAGES IN A DIALOG BOX.  SO, TO MAKE THAT
##  WORK RIGHT WITH $printcmd, THE SCRIPT USES $printcmd 1>&2
##  TO MERGE ALL PRINTER stdout ONTO stderr.
##
##  NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE

errsubj="xmh*PrintCommand print ERROR" # FOR MAILED ERRORS
printcmd="/usr/ucb/lpr"     # CAN ADD OPTIONS INSIDE QUOTES

# IN xmh RELEASE 3, MUST REDIRECT ALL OUTPUT AWAY FROM xmh.
# IN RELEASE 4 AND 5, STDERR (FD 2) GOES TO ERROR DIALOG BOX.
# UNCOMMENT THIS TO APPEND ALL OUTPUT TO FILE:
# errfile=$HOME/.xmh_printerrs
# exec >> $errfile 2>&1

# GET OPTION (xmh ALWAYS PUTS FILENAMES LAST):
case "$1" in
-p1) # JUST pr; PUTS PATHNAME IN HEADER.  NOTHING FANCY:
    shift
    pr "$@" | $printcmd 1>&2
    ;;
-p2) # SHOW SUBJECT IN pr HEADER OF EACH MESSAGE:
    shift
    for f
    do
        pr -h "`sed -n '/^[sS]ubject: / {
            s///p
            q
        }' $f`" $f
    done | $printcmd 1>&2
    ;;
"") echo "No filenames or command line arguments!?!" |
    mail -s "$errsubj" $USER
    exit 1      # xmh IGNORES THIS :-(
    ;;
*)  # DEFAULT: SEND ALL OPTIONS AND FILENAMES TO lpr:
    $printcmd "$@" 1>&2
    ;;
esac

[Table of Contents] [Index] [Return to Explanation of xmhprint]


Last change $Date: 1996/06/06 15:13:56 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>