Permalink
Browse files

Tweaks to bin/manp to make it.. better?

  • Loading branch information...
1 parent 12e24e6 commit 1fcd3b3c537e04a85100f99501103bc5ef2f92ec @cowboy committed Jan 5, 2012
Showing with 11 additions and 19 deletions.
  1. +11 −19 bin/manp
View
@@ -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.