-
Notifications
You must be signed in to change notification settings - Fork 494
/
manh
executable file
·44 lines (34 loc) · 1.05 KB
/
manh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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>
$(MANWIDTH=120 man "$@" 2>/dev/null | man2html -bare -nodepage)
</body>
</html>
EOF
# Open HTML (if it does exist).
for cmd in xdg-open open; do [[ "$(which $cmd)" ]] && break; done
[[ -e "$file" ]] && $cmd "$file"