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


Click here to return to the 'For the shell-scripting challenged...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
For the shell-scripting challenged...
Authored by: aranor on Nov 02, '03 06:39:05PM
Here's a shell script based on yours, but actually does everything. It checks to make sure the manpage exists, it opens the page if it's already been cached (I didn't try yours but I don't see where yours would do that), and it uses /tmp/ManCache/ as the cache directory. It's also done in shell script format instead of function format. Here it is:
#!/bin/sh
if [ ! $1 ]; then
	echo "What man page do you want?";
	exit;
fi;

if [ ! $2 ]; then
	MAN_PAGE=$1;
	MAN_SECTION="1";
else
	MAN_PAGE=$2;
	MAN_SECTION=$1;
fi;

CACHE_PATH="/tmp/ManCache"
CACHE_FILENAME=$CACHE_PATH/$MAN_PAGE.$MAN_SECTION.pdf

if [[ ! -d "$CACHE_PATH" ]]; then
	mkdir -p $CACHE_PATH;
fi;

if [[ -r $CACHE_FILENAME ]]; then
	open $CACHE_FILENAME;
elif [[ `man -w "$@"` != "" ]]; then
	man -t $@ | pstopdf -i -o $CACHE_FILENAME; open $CACHE_FILENAME;
fi;


[ Reply to This | # ]
For the shell-scripting challenged...
Authored by: superfly on Nov 13, '03 09:36:14AM
this version gets the section right if it's not given.

#!/bin/sh
CACHE=/tmp/preman

if [ ! $1 ]; then
    # give man's wtf error
    man
    exit
fi

# get manpage name
MANPAGE=`man -w $@`
if [ ! $? = 0 ]; then  # not found
    # man will have printed an error
    exit
fi

MANPAGE=`basename $MANPAGE`
PDF=$CACHE/$MANPAGE.pdf

# create cache if it doesn't exist
if [[ ! -d $CACHE ]]; then
    mkdir -p $CACHE
fi

# if there's no cached pdf, make one
if [[ ! -r $PDF ]]; then
    man -t $@ | pstopdf -i -o $PDF
fi

open $PDF


[ Reply to This | # ]