tazpkg view modules/help @ rev 955

modules/search: allow search file with dash at start: tazpkg -sf "-spi"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 22 00:02:54 2017 +0200 (2017-12-22)
parents 9575613271cf
children
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # help - TazPkg module
4 # TazPkg help system
7 . /lib/libtaz.sh
9 # Determine the help language
11 BASE='/usr/share/doc/tazpkg'
13 for i in $(echo $LANGUAGE | tr ':' ' ') ${LANG%.*} ${LANG%_*} en; do
14 if [ -f "$BASE/tazpkg.$i.html" ]; then
15 DOC="$BASE/tazpkg.$i.html"
16 break
17 fi
18 done
23 # Print the usage.
25 usage () {
26 cat <<EOT
28 $(_ 'SliTaz package manager - Version: %s' $(colorize 34 $VERSION))
30 $(boldify "$(_ 'Usage:')")
31 $(_ 'tazpkg [command] [package|dir|pattern|list|cat|--opt] [dir|--opt]')
33 $(boldify "$(_ 'SHell:')") tazpkg shell
35 $(boldify "$(_ 'Commands:')")
36 $(optlist "\
37 usage $(_ 'Print this short usage')
38 -h help $(_ 'Show help on the TazPkg commands')
39 -a activity $(_ 'Show TazPkg activity log')
40 -cc clean-cache $(_ 'Clean all packages downloaded in cache directory')
41 list-cache $(_ 'List *.tazpkg packages downloaded to the cache')
42 shell $(_ 'Run interactive TazPkg shell')
44 -l list $(_ 'List installed packages on the system')
45 -lm list-mirror $(_ 'List all available packages on the mirror')
46 list-config $(_ 'List the configuration files')
48 -s search $(_ 'Search for a package by pattern or name')
49 -sp search-pkgname $(_ 'Search on mirror for package having a particular file')
50 -sf search-file $(_ 'Search for file in all installed packages files')
52 -g get $(_ 'Download a package into the current directory')
53 -i install $(_ 'Install a local package')
54 -gi get-install $(_ 'Download and install a package from the mirror')
55 install-list $(_ 'Install all packages from a list of packages')
56 get-install-list $(_ 'Download and install a list of packages from the mirror')
57 -r remove $(_ 'Remove the specified package and all installed files')
58 reconfigure $(_ 'Replay post install script from package')
59 link $(_ 'Link a package from another SliTaz installation')
60 set-release $(_ 'Change release and update packages')
61 add-flavor $(_ 'Install the flavor list of packages')
62 install-flavor $(_ 'Install the flavor list of packages and remove other ones')
64 info $(_ 'Print information about a package')
65 -d desc $(_ 'Print description of a package')
66 -lf list-files $(_ 'List the files installed with a package')
67 -b|u block|unblock $(_ 'Block an installed package version or unblock it for upgrade')
68 check $(_ 'Verify consistency of installed packages')
69 bugs $(_ 'Show known bugs in packages')
70 depends $(_ 'Display dependencies tree')
71 rdepends $(_ 'Display reverse dependencies tree')
72 -e extract $(_ 'Extract a (*.tazpkg) package into a directory')
73 pack $(_ 'Pack an unpacked or prepared package tree')
74 repack $(_ 'Create a package archive from an installed package')
75 repack-config $(_ 'Create a package archive with configuration files')
76 recompress $(_ 'Rebuild a package with a better compression ratio')
77 convert $(_ 'Convert alien package to tazpkg')
78 list-suggested $(_ 'Print list of suggested packages')
80 recharge $(_ 'Recharge your packages.list from the mirror')
81 up $(_ 'Check packages %s to list and install latest upgrades' $CHECKSUM)
82 -sm setup-mirror $(_ 'Change the mirror URL configuration')
83 setup-undigest $(_ 'Update an undigest mirror')
84 list-undigest $(_ 'List undigest mirrors')
85 add-undigest $(_ 'Add an undigest mirror')
86 remove-undigest $(_ 'Remove an undigest mirror')
87 mkdb $(_ 'Make a TazPkg database for a folder with *.tazpkg packages')
88 ")
89 EOT
90 }
95 T="${1#-}"
96 QUERY="$T"
98 if [ -z "$T" ]; then
99 usage; exit 0
100 fi
102 commands="\
103 :usage::help,h::activity,log,a::clean-cache,cc::shell::list,l::list-mirror,lm:\
104 :list-config::search,s::search-pkgname,sp::search-file,sf::get,g::install,i:\
105 :get-install,gi::install-list,get-install-list::remove,r::reconfigure::link:\
106 :set-release::add-flavor,install-flavor::info::desc,d::list-files,lf:\
107 :block,b,unblock,u,chblock::check::bugs::depends,rdepends::extract,e::pack:\
108 :repack::repack-config::recompress::convert,c::list-suggested::recharge:\
109 :upgrade,up::setup-mirror,sm::add-undigest,setup-undigest::list-undigest:\
110 :remove-undigest:"
112 if [ ! $(echo $commands | grep -e "[:,]$T[:,]") ]; then
113 try1=$(echo $commands | grep -oe ":[^:]*$T[^:]*:")
114 if [ -z "$try1" ]; then
115 _ 'Sorry, no help for "%s"' "$QUERY"; newline; exit 0
116 fi
118 try2=$(echo "$try1" | tr -d : )
120 trynum=$(echo "$try2" | wc -l)
121 if [ "$trynum" -ne 1 ]; then
122 _p '%d help topic available:' '%d help topics available:' "$trynum" \
123 "$trynum"; newline
124 echo "$try2" | sed 's|^| * &|; s| ,| |; s|,|, |g'
125 exit 0
126 else
127 T="${try2%%,*}"
128 fi
129 else
130 try3=$(echo $commands | grep -oe "[:,]$T[:,]")
131 case $try3 in
132 :*) try4="$try3";;
133 ,*) try4=$(echo $commands | grep -oe ":[^:]*$try3" | cut -d, -f1);;
134 esac
136 T=$(echo $try4 | tr -d ':,')
137 fi
139 title=$(echo $commands | grep -oe ":$T\(,[^:]*\)*:" | tr -d : | sed 's|,|, |g')
142 # style: <article id="TOPIC">
143 HLP=$(sed "/article id=\"$T\"/,/<\/article/!d; s|</*article[^>]*>||; s|<h3>.*</h3>||" $DOC)
145 if [ -z "$HLP" ]; then
146 _ 'Sorry, no help for "%s"' "$QUERY"
147 exit 0
148 fi
150 PRE=$(echo "$HLP" | sed "/^$/d; /<pre>/,/<\/pre\>/{s|.*|  &|; s| |·|g}; \
151 s|^  </*pre>$||; s|<pre>||; s|</pre>||; s|  ·#|  #|;" | tr '\n' ' ' | \
152 sed 's|[ ][ ]*| |g;' | \
153 sed 's|[ ]*<dl>|O\n|g; s|[ ]*</dl>|L\n|g; s|[ ]*</*dt>||g;' | \
154 sed 's|[ ]*<dd>| |g; s|</dd>|\n|g;' | \
155 sed 's|[ ]*<ul>|O\n|g; s|[ ]*</ul>|L\n|g; s|[ ]*<li>|* |g; s|</li>|\n|g;' | \
156 sed 's|<h4>|<b>|g; s|</h4>|</b>\n|g' | \
157 sed 's|[ ]*<p>[ ]*||g; s|[ ]*</p>|\n \n|g; s|  |\n  |g' | \
158 sed 's|<a [^>]*>||g; s|</a>||g; s|·| |g' | \
159 sed 's|</*nobr>||g; s|&shy;||g; s|^[ ]*||' | \
160 sed '/^$/d' | \
161 sed 's|<tt>|A|g; s|<code>|A|g; s|<em>|B|g; s|<strong>|B|g; \
162 s|</tt>|D|g; s|</code>|D|g; s|</em>|D|g; s|</strong>|C|g; \
163 s|DD|D|g;')
165 OPT=$(echo "$PRE" | sed '/O/,/L/!d; /[OL]/d')
166 OPTLIST=$(optlist "$OPT")
168 OPT0=$(echo "$PRE" | tr '\n' '@')
169 OPTA=$(echo "$OPT" | tr '\n' '@' | sed 's|\*|\\*|g;')
170 OPTB=$(echo "$OPTLIST" | tr '\n' '@' | sed 's|\*|\\*|g;')
172 PRE2=$(echo "$OPT0" | sed "s|$OPTA|$OPTB|" | tr '@' '\n' | sed '/O/d; s|L||')
174 [ ! -z "$TA" ] && T="$T, $TA"
176 title '%s' "$title"
177 emsg "$(longline "$PRE2" | sed 's|A|<c 33>|g; s|B|<c 36>|g; s|C|</b>|g; s|D|</c>|g; ')"
178 newline