slitaz-base-files view rootfs/usr/bin/man @ rev 266
man: tiny man fake update (thanks llev)
author | Richard Dunbar <mojo@slitaz.org> |
---|---|
date | Tue Mar 31 12:11:10 2015 -0400 (2015-03-31) |
parents | e970dc10e7e2 |
children | 91fcb259b3bf |
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 SECTIONS
24 local MSG
25 local TOPIC
26 local MAN_SECTION
28 case "$1" in
29 ''|-*)
30 emsg "$(_ '<b>Usage:</b> man [section] command')"
31 return ;;
32 esac
34 SECTION=all
35 MAN_SECTION='*'
36 MSG=""
38 if [ -n "$2" ]; then
39 SECTION=$1
40 MAN_SECTION=$1
41 MSG=" $(_n 'in section $SECTION')"
42 shift
43 fi
45 TOPIC=$1
47 if [ check_retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
48 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
49 return
50 elif [ check_retawq -a -f /usr/share/doc/slitaz/$TOPIC.html ]; then
51 retawq --dump=file:///usr/share/doc/slitaz/$TOPIC.html | less -M
52 return
53 elif [ check_retawq -a -f /usr/share/doc/slitaz-tools/$TOPIC.html ]; then
54 retawq --dump=file:///usr/share/doc/slitaz-tools/$TOPIC.html | less -M
55 return
56 elif [ -f /usr/share/doc/slitaz/$TOPIC.txt ]; then
57 # SliTaz tools/libraries documentation (man a like format)
58 less -M /usr/share/doc/slitaz/$TOPIC.txt
59 return
60 fi
62 for i in /usr/share/man/$LC_ALL/man$MAN_SECTION /usr/share/man/man$MAN_SECTION; do
63 if [ -f $i/$TOPIC.* ]; then
64 i=$(ls $i/$TOPIC.* 2> /dev/null)
65 if [ "x$i" != "x" ]; then
66 case "$i" in
67 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
68 *) less -M $i;;
69 esac
70 fi
71 return
72 fi
73 if [ check_retawq -a -f $i/$TOPIC.html ]; then
74 retawq --dump=file://$i/$TOPIC.html | less -M
75 return
76 fi
77 done
79 if [ "$SECTION" = all ]
80 then SECTIONS="1 2 3 4 5 6 7 8"
81 else SECTIONS=$SECTION
82 fi
84 for SECTION in $SECTIONS
85 do
86 URL=$( wget -q -O - http://man7.org/linux/man-pages/dir_all_alphabetic.html | \
87 sed -n -r "s%.*href=\"\./(man./.*html)\">$TOPIC\($SECTION\).*%\1%p" )
88 if [ -n "$URL" ]
89 then
90 wget -q -O - "http://man7.org/linux/man-pages/$URL" | \
91 awk "BEGIN {s=0} /headline/{s=1} /COLOPHON/{s=0} {if(s) print}" | \
92 sed -e 's%<span class="top-link">top</span>%%' -e 's/<[^>]*>//g' -e 's/</</g' \
93 -e 's/>/>/g' -e 's/&/\&/g' -e 's/ //g' | less -M
94 exit 0
95 fi
96 done
97 _ 'No manual entry for $TOPIC$MSG'
98 exit 0