-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacmanman
executable file
·56 lines (49 loc) · 1.24 KB
/
pacmanman
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
#!/bin/bash
# Retrieve a list of man pages from pacman for a package
manpages () {
# Query pacman
pacman -Ql "$1" | \
grep $'/usr/share/man/.\n/usr/man/.' | \
while IFS=' ' read _ file ; do
# Strip the path to a num and man page name
file="${file#/usr}"
file="${file#/share}"
file="${file#/man/man}"
num="${file%%/*}"
file="${file#*/}"
file="${file%%.*}"
[[ $file ]] || continue
echo "$num $file"
done
}
(( $# == 0 )) && echo "Usage: "$(basename "$0")" package [more_packages...]"
for arg ; do
# Get the list of man number and names
IFS=$'\n' list=( $(manpages "$arg" 2>&1) )
# Check if any found
if ! [[ "$list" ]] ; then
echo "$arg has no man pages."
continue
fi
p='error: package * not found'
if [[ "${list[0]}" == $p ]] ; then
list="${list[0]}"
echo "${list#error: }"
continue
fi
# Only show prompt for more than one man page
prompt=0
if (( ${#list[@]} > 1 )) ; then
echo "$arg has ${#list[@]} man pages."
prompt=1
fi
for pair in "${list[@]}" ; do
IFS=' ' read num name <<< "$pair"
if (( prompt )) ; then
# If prompting, ask and allow user to selectively skip pages
read -p "Show man $pair? [Y/n] " -n 1
[[ $REPLY == [nN] ]] && { echo ; continue ; }
fi
man "$num" "$name"
done
done