Software > preman

preman

preman

Several months ago, I wrote a quick shell script (named preman) that converts man pages to pdf files and opens them in preview. Since then I've used it almost each time I needed to consult a man page, but it had a problem: it only worked for pages in the section 1 of the manual. Put differently, 'preman pwd' (where section 1 is assumed) worked fine, but 'preman 3 getcwd' wasn't supported.

I've often been annoyed by this limitation, but I didn't manage to find the time to fix it until today (or when I got the time I didn't think about it :). I finally ended up rewriting that script from scratch, and when I was happy with it I added a revision note in its header. And doing so, I noticed that I originally wrote it exactly one year ago (to the day)! Isn't it funny?

Now, to celebrate its anniversary, here's the script for those who are interested (updated since the original post):

#!/bin/tcsh

#######################################################################################
### preman
### © 2003/2023 Philippe Martin
###
### Open a man page as pdf in Preview (creating it if it doesn't exist).
### Call it like man:
###   ex: 'preman pwd'
###   ex: 'preman 3 getcwd'
###
### 2/10/03
###   Created
### 2/10/04
###   Rewriten from scratch to support sections > 1
### 5/10/04
###   It was assuming that the default section is always 1. But this is not the case
###   (for example 'man traceroute' actually opens traceroute(8).). This is fixed. 
#######################################################################################

set pdfManFolder = path_to_your_pdf_man_files

if ( $2 == "" ) then
	set name = $1
	set sect = 1
	set page = $1
	set flDefault = true
else
	set name = $2.$1
	set sect = $1
	set page = $2
	set flDefault = false
endif

if !( `filetest -e $pdfManFolder/$name.pdf` ) then
	if ( $flDefault == true ) then
		man -t $page > /tmp/$name.ps		# create the ps file for the default section
	else
		man -t $sect $page > /tmp/$name.ps	# create the ps file for the requested section
	endif
	if !( `filetest -e /tmp/$name.ps` ) exit 1	# the ps file doesn't exist
	if ( `head /tmp/$name.ps` == "" ) exit 1	# the ps file is empty
	echo Creating $name.pdf
	pstopdf /tmp/$name.ps -o $pdfManFolder/$name.pdf # create the pdf file
	if !( `filetest -e $pdfManFolder/$name.pdf` ) exit 1 # error creating the pdf
endif

open $pdfManFolder/$name.pdf
exit 0

Set the value of pdfManFolder, save the script as ~/bin/preman, for example, make it executable, and enjoy. :)

 Previous Comments

There are no comments yet. Be the first to post one!

Please Log in if you wish to comment.