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

man: we dont need retawq for slitaz doc and read online man
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 01 08:32:54 2014 +0200 (2014-05-01)
parents 793c2b7ed97f
children 27287c7c55c9
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 check_retawq() {
14 if [ ! -x /usr/bin/retawq ]; then
15 echo; _ "Missing Retawq web browser..."
16 _ "Please run: su -c 'tazpkg get-install retawq'"
17 exit 0
18 fi
19 }
21 local i
22 local SECTION
23 local MSG
24 local TOPIC
25 local MAN_SECTION
27 case "$1" in
28 ''|-*)
29 emsg "$(_ '<b>Usage:</b> man [section] command')"
30 return ;;
31 esac
33 SECTION=all
34 MAN_SECTION='*'
35 MSG=""
37 if [ -n "$2" ]; then
38 SECTION=$1
39 MAN_SECTION=$1
40 MSG=" $(_n 'in section $SECTION')"
41 shift
42 fi
44 TOPIC=$1
46 if [ check_retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
47 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
48 return
49 elif [ check_retawq -a -f /usr/share/doc/slitaz/$TOPIC.html ]; then
50 retawq --dump=file:///usr/share/doc/slitaz/$TOPIC.html | less -M
51 return
52 elif [ check_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/man/$LC_ALL/man$MAN_SECTION /usr/share/man/man$MAN_SECTION; do
62 if [ -f $i/$TOPIC.* ]; then
63 i=$(ls $i/$TOPIC.* 2> /dev/null)
64 if [ "x$i" != "x" ]; then
65 case "$i" in
66 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
67 *) less -M $i;;
68 esac
69 fi
70 return
71 fi
72 if [ check_retawq -a -f $i/$TOPIC.html ]; then
73 retawq --dump=file://$i/$TOPIC.html | less -M
74 return
75 fi
76 done
78 [ "x$SECTION" = "x" ] && SECTION="all"
79 (wget -O - "http://mirror.slitaz.org/man/$SECTION/$TOPIC.html" || \
80 wget -O - "http://man.he.net/?topic=$TOPIC&section=$SECTION") 2> /dev/null | \
81 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')\" }" | \
82 sed -e 's/<[^>]*>//g' -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\&/g' | less -M
84 exit 0