You are not logged in.
I have a tendency after installing a package to view all the man pages I just installed.
Manually? Ugh. Write a script!!
This script takes one or more package names and gets a list of the man pages part of that package using pacman -Ql
If there is only one page, it is displayed. If there are more, it prompts you for each one.
#!/bin/bash
# Retrieve a list of man pages from pacman for a package
manpages () {
# Query pacman
pacman -Ql "$1" | \
grep '/usr/share/man/.' | \
while IFS=' ' read _ file ; do
# Strip the path to a num and man page name
file="${file#/usr/share/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---
EDIT: Based on a comment by Daenyth, changed from fgrep to grep to modify the handling of the man directory.
Last edited by yitzle (2009-09-13 04:35:45)
Offline
Thanks for the script. I also like to have a glimpse at what I'm installing and this is very useful. In fact, I'm discovering new things about packages that were already installed... ![]()
Offline
you may find this simpler or more complex depending on your perspective:
basename "$(pacman -Ql zenity | grep '/usr/share/man/.*gz$')" | awk -F '.' '{print $1, $2}' | while read file num; do echo "man $num $file"; done
man 1 zenityuse it if you'd like
.
/edit: slightly different approach.
Last edited by brisbin33 (2009-09-14 18:41:34)
//github/
Offline
brisbin33: More compact, but it doesn't seem to get the same results. For example, trying with imagemagick will just result in Image::Magick(3pm) man page, whereas with the first script will display all the 18 man pages in the package.
Offline
sorry i was a bit shortsighted in testing. this version works, though a double awk is pretty awkward (pun!); the existing bashisms may be best. i'll keep thinking on this... it's a very nice script as is.
> pacman -Ql imagemagick | awk -F '/' '/usr\/share\/man\/.*gz$/ {print $NF}' | awk -F '.' '{print $1, $2}' | while read file num; do echo "man $num $file"; done
man 1 ImageMagick
man 1 Magick++-config
man 1 Magick-config
man 1 MagickCore-config
man 1 MagickWand-config
man 1 Wand-config
man 1 animate
man 1 compare
man 1 composite
man 1 conjure
man 1 convert
man 1 display
man 1 identify
man 1 import
man 1 mogrify
man 1 montage
man 1 stream
man 3pm Image::Magick/edit: fixed variables. thanks yitzle, i need to remember when i change variables b/w copy and paste i should change them both ![]()
Last edited by brisbin33 (2009-09-15 13:29:10)
//github/
Offline
sorry i was a bit shortsighted in testing. this version works, though a double awk is pretty awkward (pun!); the existing bashisms may be best. i'll keep thinking on this... it's a very nice script as is.
> pacman -Ql imagemagick | awk -F '/' '/usr\/share\/man\/.*gz$/ {print $NF}' | awk -F '.' '{print $1, $2}' | while read man file; do echo "man $num $file"; done man 1 ImageMagick ...
That last bit should be:
while read num fileLast edited by yitzle (2009-09-15 02:13:56)
Offline