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

New function unboldify(); I think, they will be handy
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon May 21 11:34:18 2012 +0300 (2012-05-21)
parents bffd6c0e7c5b
children d4df77afbed6
line source
1 #!/bin/sh
2 #
3 # Tiny man fake using online manuals.
4 # Copyright (C) 2009-2012 SliTaz GNU/Linux.
5 #
6 . /lib/libtaz.sh
8 # Internationalization.
9 . /usr/bin/gettext.sh
10 TEXTDOMAIN='slitaz-base'
11 . /etc/locale.conf
12 export TEXTDOMAIN LANG
14 if [ ! -x /usr/bin/retawq ]; then
15 echo; gettext "Missing Retawq web browser..."; echo
16 gettext "Please run: su -c 'tazpkg get-install retawq'"; echo -e "\n"
17 exit 0
18 fi
20 local i
21 local SECTION
22 local MSG
23 local TOPIC
24 local MAN_SECTION
26 case "$1" in
27 ''|-*)
28 cat <<EOT
30 unboldify "$(gettext '<b>Usage:</b> man [section] command')"
32 EOT
33 return ;;
34 esac
36 SECTION=all
37 MAN_SECTION='*'
38 MSG=""
40 if [ -n "$2" ]; then
41 SECTION=$1
42 MAN_SECTION=$1
43 MSG=" in section $SECTION"
44 shift
45 fi
47 TOPIC=$1
49 if [ -x /usr/bin/retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
50 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
51 return
52 elif [ -x /usr/bin/retawq -a -f /usr/share/doc/slitaz-tools/$TOPIC.html ]; then
53 retawq --dump=file:///usr/share/doc/slitaz-tools/$TOPIC.html | less -M
54 return
55 elif [ -f /usr/share/doc/slitaz/$TOPIC.txt ]; then
56 # SliTaz tools/libraries documentation (man a like format)
57 less -M /usr/share/doc/slitaz/$TOPIC.txt
58 return
59 fi
61 for i in /usr/share/$LC_ALL/man$MAN_SECTION /usr/share/man$MAN_SECTION; do
62 if [ -f $i/raw-$TOPIC.* ]; then
63 i=$(ls $i/raw-$TOPIC.*)
64 case "$i" in
65 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
66 *) less -M $i;;
67 esac
68 return
69 fi
70 if [ -x /usr/bin/retawq -a -f $i/$TOPIC.html ]; then
71 retawq --dump=file://$i/$TOPIC.html | less -M
72 return
73 fi
74 done
76 (wget -O - "http://mirror.slitaz.org/man/$SECTION/$TOPIC.html" || \
77 wget -O - "http://man.he.net/?topic=$TOPIC&section=$SECTION") 2> /dev/null | \
78 awk "BEGIN { s=0; n=0 } /<PRE>/ { s=1 } { if (s) { print; n++} } /<\/PRE>/ { s=0 } END { if (n == 0) print \"$(eval_gettext 'No manual entry for $TOPIC$MSG')\" }" | \
79 sed -e 's/<[^>]*>//g' -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\&/g' | less -M
81 exit 0