slitaz-base-files view rootfs/usr/bin/man @ rev 226
2014
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jan 04 13:59:19 2014 +0000 (2014-01-04) |
parents | b2311939ad7e |
children | e970dc10e7e2 |
line source
1 #!/bin/sh
2 #
3 # Tiny man fake using online manuals.
4 # Copyright (C) 2009-2014 SliTaz GNU/Linux.
5 #
6 . /lib/libtaz.sh
8 # Internationalization.
9 TEXTDOMAIN='slitaz-base'
10 . /etc/locale.conf
11 export TEXTDOMAIN LANG
13 if [ ! -x /usr/bin/retawq ]; then
14 echo; _ "Missing Retawq web browser..."
15 _ "Please run: su -c 'tazpkg get-install retawq'"
16 exit 0
17 fi
19 local i
20 local SECTION
21 local MSG
22 local TOPIC
23 local MAN_SECTION
25 case "$1" in
26 ''|-*)
27 emsg "$(_ '<b>Usage:</b> man [section] command')"
28 return ;;
29 esac
31 SECTION=all
32 MAN_SECTION='*'
33 MSG=""
35 if [ -n "$2" ]; then
36 SECTION=$1
37 MAN_SECTION=$1
38 MSG=" $(_n 'in section $SECTION')"
39 shift
40 fi
42 TOPIC=$1
44 if [ -x /usr/bin/retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
45 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
46 return
47 elif [ -x /usr/bin/retawq -a -f /usr/share/doc/slitaz/$TOPIC.html ]; then
48 retawq --dump=file:///usr/share/doc/slitaz/$TOPIC.html | less -M
49 return
50 elif [ -x /usr/bin/retawq -a -f /usr/share/doc/slitaz-tools/$TOPIC.html ]; then
51 retawq --dump=file:///usr/share/doc/slitaz-tools/$TOPIC.html | less -M
52 return
53 elif [ -f /usr/share/doc/slitaz/$TOPIC.txt ]; then
54 # SliTaz tools/libraries documentation (man a like format)
55 less -M /usr/share/doc/slitaz/$TOPIC.txt
56 return
57 fi
59 for i in /usr/share/man/$LC_ALL/man$MAN_SECTION /usr/share/man/man$MAN_SECTION; do
60 if [ -f $i/$TOPIC.* ]; then
61 i=$(ls $i/$TOPIC.* 2> /dev/null)
62 if [ "x$i" != "x" ]; then
63 case "$i" in
64 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
65 *) less -M $i;;
66 esac
67 fi
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 [ "x$SECTION" = "x" ] && SECTION="all"
77 (wget -O - "http://mirror.slitaz.org/man/$SECTION/$TOPIC.html" || \
78 wget -O - "http://man.he.net/?topic=$TOPIC§ion=$SECTION") 2> /dev/null | \
79 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')\" }" | \
80 sed -e 's/<[^>]*>//g' -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' | less -M
82 exit 0