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
Expand Up @@ -7,37 +7,29 @@ http://benalman.com/
Usage: $(basename "$0") [section] name Usage: $(basename "$0") [section] name
View a manpage as PDF in the default viewer (Preview.app). Because sometimes 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. Licensed under the MIT license.
http://benalman.com/about/license/ http://benalman.com/about/license/
HELP HELP
exit; fi exit; fi


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


cache_dir=~/.dotfiles/caches/manpdf cache_dir=~/.dotfiles/caches/manpdf


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


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


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


if [ ! -e "$file" ]; then # Open PDF (if it does exist).
man -t "$@" | pstopdf -i -o "$file" > /dev/null 2>&1 [[ -e "$file" ]] && open "$file"
fi

if [ -e "$file" ]; then
open "$file"
fi

0 comments on commit 1fcd3b3

Please sign in to comment.