forked from pinktrink/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsman
45 lines (34 loc) · 944 Bytes
/
sman
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
#!/usr/bin/env bash
smancache=$HOME/.dotfiles/etc/cache/sman
function cache_man_txt () {
if ! [[ -f "$smancache/[email protected]" ]]; then
local tmpman="$(MANWIDTH=120 man $@)"
if [ $? -eq 0 ]; then
echo "Caching man page for $@."
echo "$tmpman" | col -b > "$smancache/[email protected]"
else
return 1
fi
fi
}
function sman () {
cache_man_txt $@
if [ $? -eq 0 ]; then
(
chflags uchg "$smancache/[email protected]" &&
subl -w "$smancache/[email protected]" &&
chflags nouchg "$smancache/[email protected]" &
) &> /dev/null
else
return 1
fi
}
function smandb () {
if ! [[ -d $smancache ]]; then
mkdir -p $smancache
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_txt "$i" 2> /dev/null
done
}