Skip to content

Commit

Permalink
Tweaks to bin/manp to make it.. better?
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Jan 5, 2012
1 parent 12e24e6 commit 1fcd3b3
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions bin/manp
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,29 @@ http://benalman.com/
Usage: $(basename "$0") [section] name
View a manpage as PDF in the default viewer (Preview.app). Because sometimes
you don't want to view manpages in the terminal. Tested in OS X 10.7.
you don't want to view manpages in the terminal.
Copyright (c) 2011 "Cowboy" Ben Alman
Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license.
http://benalman.com/about/license/
HELP
exit; fi

if [ ! "$1" ]; then
echo "What manual page do you want?!"
echo 'What manual page do you want?!'
exit
fi

cache_dir=~/.dotfiles/caches/manpdf

if [ "$2" ]; then
name="$2.$1"
else
name="$1"
fi
# Figure out what the filename should be.
file="$cache_dir/${2:+$2.}$1.pdf"

file="$cache_dir/$name.pdf"
# Create directory if it doesn't exist.
[[ -e "$cache_dir" ]] || mkdir -p "$cache_dir"

if [ ! -e "$cache_dir" ]; then
mkdir -p $cache_dir;
fi
# Create PDF if it doesn't exist.
[[ -e "$file" ]] || man -t "$@" | pstopdf -i -o "$file" >/dev/null 2>&1

if [ ! -e "$file" ]; then
man -t "$@" | pstopdf -i -o "$file" > /dev/null 2>&1
fi

if [ -e "$file" ]; then
open "$file"
fi
# Open PDF (if it does exist).
[[ -e "$file" ]] && open "$file"

0 comments on commit 1fcd3b3

Please sign in to comment.