slitaz-base-files view rootfs/usr/bin/man @ rev 82

Added tag 4.1 for changeset 2f92b6818996
author Antoine Bodin <gokhlayeh@slitaz.org>
date Wed Oct 20 11:39:02 2010 +0200 (2010-10-20)
parents 08241a181a24
children 8f45abb77dc5
line source
1 #!/bin/sh
2 #
3 # Tiny man fake using online manuals.
4 # (c) 2009 SliTaz GNU/Linux.
5 #
7 if [ ! -x /usr/bin/retawq ]; then
8 echo -e "\nMissing Retawq web browser..."
9 echo -e "Please run: su -c 'tazpkg get-install retawq'\n"
10 exit 0
11 fi
13 local i
14 local SECTION
15 local MSG
16 local TOPIC
17 local MAN_SECTION
19 case "$1" in
20 ''|-*)
21 cat <<EOT
23 Usage: man [section] command
25 EOT
26 return ;;
27 esac
29 SECTION=all
30 MAN_SECTION='*'
31 MSG=""
33 if [ -n "$2" ]; then
34 SECTION=$1
35 MAN_SECTION=$1
36 MSG=" in section $SECTION"
37 shift
38 fi
40 TOPIC=$1
42 if [ -x /usr/bin/retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
43 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
44 return
45 fi
47 for i in /usr/share/$LC_ALL/man$MAN_SECTION /usr/share/man$MAN_SECTION; do
48 if [ -f $i/raw-$TOPIC.* ]; then
49 i=$(ls $i/raw-$TOPIC.*)
50 case "$i" in
51 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
52 *) less -M $i;;
53 esac
54 return
55 fi
56 if [ -x /usr/bin/retawq -a -f $i/$TOPIC.html ]; then
57 retawq --dump=file://$i/$TOPIC.html | less -M
58 return
59 fi
60 done
62 (wget -O - "http://mirror.slitaz.org/man/$SECTION/$TOPIC.html" || \
63 wget -O - "http://man.he.net/?topic=$TOPIC&section=$SECTION") 2> /dev/null | \
64 awk "BEGIN { s=0; n=0 } /<PRE>/ { s=1 } { if (s) { print; n++} } /<\/PRE>/ { s=0 } END { if (n == 0) print \"No manual entry for $TOPIC$MSG\" }" | \
65 sed -e 's/<[^>]*>//g' -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\&/g' | less -M
67 exit 0