44 lines
994 B
Bash
Executable File
44 lines
994 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
|
|
Manpage-as-HTML Viewer
|
|
http://benalman.com/
|
|
|
|
Usage: $(basename "$0") [section] name
|
|
|
|
View a manpage as HTML in the default viewer. Because sometimes
|
|
you don't want to view manpages in the terminal.
|
|
|
|
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?!'
|
|
exit
|
|
fi
|
|
|
|
cache_dir=$DOTFILES/caches/manh
|
|
|
|
# Figure out what the filename should be.
|
|
file="$cache_dir/${2:+$2.}$1.html"
|
|
|
|
# Create directory if it doesn't exist.
|
|
[[ -e "$cache_dir" ]] || mkdir -p "$cache_dir"
|
|
|
|
# Create HTML if it doesn't exist.
|
|
[[ ! -e "$file" ]] && man "$@" >/dev/null && cat > "$file" <<EOF
|
|
<!doctype html>
|
|
<html>
|
|
<link rel="stylesheet" href="../../conf/manh/styles.css">
|
|
<body>
|
|
$(man "$@" 2>/dev/null | man2html -bare -nodepage)
|
|
</body>
|
|
</html>
|
|
EOF
|
|
|
|
# Open HTML (if it does exist).
|
|
[[ -e "$file" ]] && open "$file"
|