-
Notifications
You must be signed in to change notification settings - Fork 1
/
pman
50 lines (39 loc) · 1021 Bytes
/
pman
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
45
46
47
48
49
50
#!/usr/bin/env bash
pmancache=$HOME/.dotfiles/etc/cache/pman
function cache_man_pdf () {
if ! [[ -f "$pmancache/[email protected]" ]]; then
man -t "$@" > "$pmancache/[email protected]"
if [ $? -eq 0 ]; then
echo "Caching man page for $@."
pstopdf "$pmancache/[email protected]" -o "$pmancache/[email protected]" &> /dev/null
else
return 1
fi
rm "$pmancache/[email protected]"
fi
}
function pman () {
cache_man_pdf "$@"
if [ $? -eq 0 ]; then
open -a Preview "$pmancache/[email protected]"
else
return 1
fi
}
function qman () {
cache_man_pdf "$@"
if [ $? -eq 0 ]; then
( qlmanage -p "$pmancache/[email protected]" & ) &> /dev/null
else
return 1
fi
}
function pmandb () {
if ! [[ -d $pmancache ]]; then
mkdir -p $pmancache
fi
local manpages=$(man -k . | perl -pe 's/(.+) - .+/\1/' | perl -pe 's/\(.*?\)(?:, )?/\1\n/g' | egrep -v "^[[:space:]]*$")
for i in $manpages; do
cache_man_pdf "$i" 2> /dev/null
done
}