|
mac geekeryGet your geek on. |
Pretty-Print Manual Pages as PS, PDF, or HTMLApril 10, 2006 - 3:00am
You can use the First, to get a manual page that looks like the version groff -mandoc `man -w dscl` -T ascii groff -mandoc `man -w dscl` -T utf8 To get a PostScript version of a manual page, you have two choices. Either let man dscl -t > man.ps groff -mandoc `man -w dscl` -t > man.ps More fun, I think, is opening that right in Preview. The man dscl -t | open -f -a Preview groff -mandoc `man -w dscl` -t | open -f -a Preview Preview comes up, converts the file from PS to PDF for us, and we can now scroll through it and do whatever we want. It’s still a temporary file that will get cleaned on reboot, so you could alias a command to make this happen for most any manpage you wanted to see instead of being stuck in Terminal reading in We can do more, though. If you want to go straight to PDF then you can use groff -mandoc `man -w dscl` -t | pstopdf -i -o man.pdf If you’d like HTML, that can be accomplished as well as groff -mandoc `man -w dscl` -T html > man.html How to Make It UsefulThat was fun, but how can this be useful? Well, there’s a few ideas for this one. SpotlightTo be fair, there’s a manpage importer for Spotlight that does this as well, but it only indexes the files, it doesn’t open them. There’s some programs like ManOpen to view them, but, well, it looks ugly. So, if you have some space hanging around, convert all of your manual pages to PDF in a common area so Spotlight can index them and you can open and read them in a GUI. #!/bin/bash This will take a while to convert when run, and will use a large amount of disk space for the resulting files. However, once you’re done you can content-search your manual pages and open them in Preview when you’ve found them. Also, because it checks for the existence of the destination file, you can either interrupt the script and finish at a later time or you can re-run the script after installs or upgrades to get added files. It won’t check for updated files, but if you care that much just delete the old ones and start again. WebpageUsing the previous script, you can change the command and extensions using the information provided above to produce HTML files instead of PDF files. As you go along, generate the index files for the directories with the information you have and then just push this out to a webpage and you’ve got a nice documentation center. #!/bin/bash
if [[ -z $MANPATH ]] for DIR in `echo $MANPATH | sed ‘y/:/ /’`
echo “ echo “ echo “” >> man3/index.html echo “” >> man4/index.html echo “” >> man5/index.html echo “” >> man6/index.html echo “” >> man7/index.html echo “” >> man8/index.html echo “” >> man9/index.html echo “” >> index.html A nice side-effect of this is that the files are smaller than PDF and Spotlight will index them as well. It’s just that they’re nowhere near as nice as the PDF versions when it comes to printing them. Quick-View in PreviewThe following shell function (bash) can be used instead of man to get a manpage in Preview instead. Add this to your .profile or something. pdfman() { man $1 -t | open -f -a Preview; };
Now Pretty PrintingSometimes you know you just want to print the manual page. You could use pdfman above and then print, but why bother when the command line can do it for you? printman () { man $1 -t | lpr; };
Now About Adam Knight |
|
||||
If you have installed Sogudi, you can just enter
man:dsclin the Safari address bar.That “open -f” trick let me rewrite my script for this to make it absurdly simple. I had been generating my own temporary files before.
Also see pman!
http://snippets.dzone.com/posts/show/4274