Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: Easily view man pages with Preview' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Easily view man pages with Preview
Authored by: pjrgois on Mar 13, '04 09:41:08PM

Here is one that checks if there is a man page.

#!/bin/sh
#
# /Users/sandokan/.bin/pman
#
# This script will save man pages in PDF format to
# ~/Documents/man_pages and open them in Preview.app.
#
if [ ! $1 ]; then
echo "Please specify a man page to preview"
exit ;
fi

MAN_CHECK=`grep -c -w "$1(" /usr/share/man/whatis.db`

if [ "$MAN_CHECK" = "0" ]; then
echo "No manual entry for $1"
exit ;
fi

MAN_PATH="$HOME/Documents/man_pages"

if [ ! $2 ]; then
MAN_PAGE=$1;

if [ ! -e "$MAN_PATH" ]; then
mkdir -p "$MAN_PATH";
fi;

MAN_FILE=$MAN_PATH/$MAN_PAGE.pdf
else
MAN_PAGE=$2;
MAN_SECTION=$1;

if [ ! -e "$MAN_PATH/$MAN_SECTION" ]; then
mkdir -p "$MAN_PATH/$MAN_SECTION";
fi;

MAN_FILE=$MAN_PATH/$MAN_SECTION/$MAN_PAGE.pdf
fi;

if [ ! -e "$MAN_FILE" ]; then
man -t $@ | pstopdf -o "$MAN_FILE" -i;
open "$MAN_FILE";
else
open "$MAN_FILE";
fi



[ Reply to This | # ]
Revised version
Authored by: pjrgois on Mar 17, '04 07:55:39PM

#!/bin/sh
#
# /Users/sandokan/.bin/pman
#
# This script will save man pages in PDF format to
# ~/Documents/man_pages and open them in Preview.app.
#

echo ""
echo "::::Sript by Paulo Jorge Gois::::"
echo ""

if [ ! $1 ]; then
echo "Please specify a man page to preview"
exit 1;
fi

man -w $1 > /dev/null

if [ "$?" -ne 0 ]; then
exit 1;
fi

man_path="$HOME/Documents/man_pages"

if [ ! $2 ]; then
man_page=$1;

if [ ! -e "$man_path" ]; then
mkdir -p "$man_path";
fi;

man_file=$man_path/$man_page.pdf
else
man_page=$2;
man_section=$1;

if [ ! -e "$man_path/$man_section" ]; then
mkdir -p "$man_path/$man_section";
fi;

man_file=$man_path/$man_section/$man_page.pdf
fi;

if [ ! -e "$man_file" ]; then
man -t $@ | pstopdf -o "$man_file" -i;
open "$man_file";
else
open "$man_file";
fi



[ Reply to This | # ]
Revised version
Authored by: rodrilea on Dec 04, '04 11:31:22PM

I am new to shell scripting and I am running into problems with our script. When I run the script it displays the "Please specify a man page to preview." followed by a command prompt. If I enter the name of the man page it tries to run the application referenced by the man page name. Below is the code as I have entered it:

# /Users/rodrilea/.bin/pman
#
# This script will save man pages in PDF format to
# ~/Documents/man_pages and open them in Preview.app

echo ""
echo "::::Script by Paulo Jorge Gois::::"
echo ""
#
if [ ! $1 ]; then
echo "Please specify a man page to preview"
exit 1;
fi

man -w $1 > /dev/null

if [ "$?" -ne 0 ]; then
exit 1;
fi

MAN_PATH="$HOME/Documentes/man_pages"

if [! $2 ]; then
MAN_PAGE=$1;

if [ ! -e "$MAN_PATH" ]; then
mkdir -p "$MAN_PATH";
fi;

MAN_FILE=$MAN_PATH/$MAN_PAGE.pdf
else
MAN_PAGE=$2;
MAN_SECTION=$1;

if [ ! -e "$MAN_PATH/$MAN_SECTION" ]; then
mkdir -p "$MAN_PATH/$MAN_SECTION";
fi;

MAN_FILE=$MAN_PATH/$MAN_SECTION/$MAN_PAGE.pdf
fi;

if [ ! -e "$MAN_FILE" ]; then
man -t $@ | pstopdf-o "$MAN_FILE" -i;
open "$MAN_FILE";
else
open "$MAN_FILE";
fi

Thanks for your help.

Rod Rilea



[ Reply to This | # ]