Sunday, March 10, 2013

An lp for cygwin

Windows NT (i.e. all MS Windows distros in recent years) has a System V Unix kernel, badly mangled but still POSIX. Cygwin, from cygwin.com, is a free Linux-style superstructure that one can download and run on top of Windows NT, creating a complete Unix environment as solid as any Linux or Apple distro. With one thing missing: lp.
 
lp (originally short for line printer) is the original Unix print sink. Many commands in the Unix/Cygwin toolkit are meant to send plain text, or postscript, into lp:
 
$ man -t anycommand | lp
 
$ ls -l | pr | lp
 
and so on. And one can copy any text on the screen, and print it by pasting it into the standard input of  lp. Cygwin is incomplete without lp. (Cygwin has a rudimentary lpr command that can send postscript to some postscript printers, but it's not the same thing.) And so...
 
Cygwin does have enscript. Enscript, if properly configured, can accept text or postscript as input, and send its output to a (configurable) postscript spooling command. And a perfect spooling command for Windows NT is available: 'gsprint -', installed as part of ghostview for windows NT. Gsprint, in turn, uses ghostscript (gswin32c.exe) to convert the postscript that gsprint accepts into its standard input, into the appropriate printer format, and spools it to the default Windows NT printer. Note that gsprint uses the regular Windows NT ghostscript, not the cygwin version. The steps are:
 
(1) Download and install
 
http://downloads.ghostscript.com/public/gs907w32.exe
 
(2) Add the ghostscript bin and lib directories (';C:\Program Files\gs\gs9.07\bin;C:\Program Files\gs\gs9.07\lib' on Windows XP) to the Path variable of your Windows NT distro. Reboot.
 
(3) Download and install
 
http://pages.cs.wisc.edu/~ghost/gsview/download/gsv50w32.exe
 
(4) Add the gsview directory (';C:\Program Files\Ghostgum\gsview' on Windows XP) to the Path variable of your Windows NT distro. Reboot.
 
(5) Place
 
GeneratePageSize: false
Spooler: gsprint
 
in ~/.enscriptrc
 
and
 
export ENSCRIPT='-MLetter'
export GROFF_TYPESETTER='latin1'
alias lp='/usr/bin/enscript -zZlf Courier-Bold@10.9/10.2 --printer-options=-'
 
(or a different font if you prefer) in ~/.bashrc. Reboot. Enjoy lp in cygwin!