slitaz-base-files annotate 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
rev   line source
pankso@67 1 #!/bin/sh
pankso@67 2 #
pankso@67 3 # Tiny man fake using online manuals.
pascal@226 4 # Copyright (C) 2009-2014 SliTaz GNU/Linux.
pankso@67 5 #
pankso@139 6 . /lib/libtaz.sh
pankso@67 7
al@179 8 # Internationalization.
al@179 9 TEXTDOMAIN='slitaz-base'
al@179 10 . /etc/locale.conf
al@179 11 export TEXTDOMAIN LANG
al@179 12
pankso@245 13 check_retawq() {
pankso@245 14 if [ ! -x /usr/bin/retawq ]; then
pankso@245 15 echo; _ "Missing Retawq web browser..."
pankso@245 16 _ "Please run: su -c 'tazpkg get-install retawq'"
pankso@245 17 exit 0
pankso@245 18 fi
pankso@245 19 }
pankso@67 20
pankso@67 21 local i
pankso@67 22 local SECTION
mojo@266 23 local SECTIONS
pankso@67 24 local MSG
pankso@67 25 local TOPIC
pankso@67 26 local MAN_SECTION
pankso@67 27
pankso@67 28 case "$1" in
pankso@67 29 ''|-*)
al@219 30 emsg "$(_ '<b>Usage:</b> man [section] command')"
pankso@67 31 return ;;
pankso@67 32 esac
pankso@67 33
pankso@67 34 SECTION=all
pankso@67 35 MAN_SECTION='*'
pankso@67 36 MSG=""
pankso@67 37
pankso@67 38 if [ -n "$2" ]; then
pankso@67 39 SECTION=$1
pankso@67 40 MAN_SECTION=$1
al@219 41 MSG=" $(_n 'in section $SECTION')"
pankso@67 42 shift
pankso@67 43 fi
pankso@67 44
pankso@67 45 TOPIC=$1
pankso@67 46
pankso@245 47 if [ check_retawq -a -f /usr/share/doc/$TOPIC/$TOPIC.html ]; then
pankso@67 48 retawq --dump=file:///usr/share/doc/$TOPIC/$TOPIC.html | less -M
pankso@67 49 return
pankso@245 50 elif [ check_retawq -a -f /usr/share/doc/slitaz/$TOPIC.html ]; then
mojo@198 51 retawq --dump=file:///usr/share/doc/slitaz/$TOPIC.html | less -M
mojo@198 52 return
pankso@245 53 elif [ check_retawq -a -f /usr/share/doc/slitaz-tools/$TOPIC.html ]; then
mojo@101 54 retawq --dump=file:///usr/share/doc/slitaz-tools/$TOPIC.html | less -M
mojo@101 55 return
pankso@139 56 elif [ -f /usr/share/doc/slitaz/$TOPIC.txt ]; then
pankso@139 57 # SliTaz tools/libraries documentation (man a like format)
pankso@139 58 less -M /usr/share/doc/slitaz/$TOPIC.txt
pankso@139 59 return
pankso@67 60 fi
pankso@67 61
al@193 62 for i in /usr/share/man/$LC_ALL/man$MAN_SECTION /usr/share/man/man$MAN_SECTION; do
al@194 63 if [ -f $i/$TOPIC.* ]; then
al@194 64 i=$(ls $i/$TOPIC.* 2> /dev/null)
al@194 65 if [ "x$i" != "x" ]; then
al@194 66 case "$i" in
al@194 67 *gz) (zcat $i || unlzma -c $i 2> /dev/null) | less -M;;
al@194 68 *) less -M $i;;
al@194 69 esac
al@194 70 fi
pankso@67 71 return
pankso@67 72 fi
pankso@245 73 if [ check_retawq -a -f $i/$TOPIC.html ]; then
pankso@67 74 retawq --dump=file://$i/$TOPIC.html | less -M
pankso@67 75 return
pankso@67 76 fi
pankso@67 77 done
pankso@67 78
mojo@266 79 if [ "$SECTION" = all ]
mojo@266 80 then SECTIONS="1 2 3 4 5 6 7 8"
mojo@266 81 else SECTIONS=$SECTION
mojo@266 82 fi
pankso@67 83
mojo@266 84 for SECTION in $SECTIONS
mojo@266 85 do
mojo@266 86 URL=$( wget -q -O - http://man7.org/linux/man-pages/dir_all_alphabetic.html | \
mojo@266 87 sed -n -r "s%.*href=\"\./(man./.*html)\">$TOPIC\($SECTION\).*%\1%p" )
mojo@266 88 if [ -n "$URL" ]
mojo@266 89 then
mojo@266 90 wget -q -O - "http://man7.org/linux/man-pages/$URL" | \
mojo@266 91 awk "BEGIN {s=0} /headline/{s=1} /COLOPHON/{s=0} {if(s) print}" | \
mojo@266 92 sed -e 's%<span class="top-link">top</span>%%' -e 's/<[^>]*>//g' -e 's/&lt;/</g' \
mojo@266 93 -e 's/&gt;/>/g' -e 's/&amp;/\&/g' -e 's/&nbsp;//g' | less -M
mojo@266 94 exit 0
mojo@266 95 fi
mojo@266 96 done
mojo@266 97 _ 'No manual entry for $TOPIC$MSG'
pankso@67 98 exit 0