-
Notifications
You must be signed in to change notification settings - Fork 0
/
manpager
61 lines (59 loc) · 1.38 KB
/
manpager
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
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env zsh
has_cmd() {
local opt
for opt; do
if command -v "$opt" >/dev/null; then
continue
else
return $?
fi
done
}
if ! has_cmd ansifilter && has_cmd col; then
ansifilter() {
col -bx
}
fi
if [ -t 0 ]; then
if [[ $# == 0 ]]; then
judge_shell() {
local shell
for shell in "$@"; do
[[ $SHELL == */$shell ]] && return
done
return 1
}
if ! has_cmd bat; then
bat() {
command cat "$*"
}
fi
self="$0"
self="'${self//\'/\'\\\'\'}'"
if judge_shell bash zsh ksh; then
echo -e "MANPAGER=$self\nexport MANPAGER" | bat --color=auto -plsh
elif judge_shell tclsh wish; then
echo -e "set env(MANPAGER) $self\nenv -export MANPAGER" | bat --color=auto -plsh
elif judge_shell csh tcsh; then
echo -e "setenv env MANPAGER $self" | bat --color=auto -plsh
elif judge_shell pwsh; then
echo -e "\$env:MANPAGER = $self\nExport-Variable -Name MANPAGER" | bat --color=auto -plsh
elif judge_shell cmd; then
echo -e "setx MANPAGER $self" | bat --color=auto -plsh
fi
exit
fi
# mandoc
if has_cmd ansifilter bat; then
ansifilter <"${!#}" | eval "bat --color=always --theme=\"Monokai Extended\" --italic-text=always -plman ${*:1:$#-1}"
else
cat "${!#}"
fi
else
# man-db
if has_cmd ansifilter bat; then
ansifilter | eval "bat --color=always --theme=\"Monokai Extended\" --italic-text=always -plman ${*//\\/\\\\}"
else
cat
fi
fi