3
# Copyright (C) 2012, 2013, 2016-2020 Etersoft
4
# Copyright (C) 2012, 2013, 2016-2020 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
load_helper epm-check_updated_repo
21
load_helper epm-sh-warmup
29
CMD="apt-cache search --"
32
CMD="aptitude search --"
38
CMD="pkcon search name"
41
# urpmq does not support --
48
CMD="pkg search -i --"
51
CMD="emerge --search --"
69
CMD="zypper search -d --"
84
docmd npackdcl search --query="$string" --status=all
92
echo "Note: case sensitive search"
93
if [ -n "$verbose" ] ; then
94
CMD="/usr/sbin/slackpkg search"
96
LC_ALL=C docmd /usr/sbin/slackpkg search $string | grep " - " | sed -e 's|.* - ||g'
107
CMD="guix package -A"
110
CMD="pm list packages"
116
CMD="apt-cyg searchall"
125
fatal "Have no suitable search command for $PMTYPE"
129
LC_ALL=C docmd $CMD $string
130
epm play $short --list-all | sed -e 's|^ *||g' -e 's|[[:space:]]\+| |g' -e "s|\$| (use \'epm play\' to install it)|"
133
# copied from eget's filter_glob
135
__convert_glob__to_regexp()
137
# translate glob to regexp
138
echo "$1" | sed -e "s|\*|.*|g" -e "s|?|.|g"
144
sed -e "s/[?\^.*]/ /g"
150
sed -e "s/[?*].*//" -e "s/[?\^.*]/ /g"
154
# produce grep sequence
155
__epm_search_make_grep()
158
[ -z "$*" ] && return
165
# will clean from ~ later (and have the bug here with empty arg if run with one ~ only)
174
#list=$(strip_spaces $list | sed -e "s/ /|/g")
175
listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/~//g")
177
# TODO: only apt supports regexps?
182
list=$(echo "$list" | sed -e "s/[?\^.]/ /g")
183
listN=$(echo "$listN" | sed -e "s/[?\^.]/ /g")
187
list=$(__convert_glob__to_regexp "$list")
188
listN=$(__convert_glob__to_regexp "$listN")
190
if [ -n "$short" ] ; then
191
echon " | sed -e \"s| .*||g\""
194
[ -n "$listN" ] && echon " | grep -E -i -v -- \"$listN\""
196
# FIXME: The World has not idea how to do grep both string
197
# http://stackoverflow.com/questions/10110051/grep-with-two-strings-logical-and-in-regex?rq=1
199
# Need only if we have more than one word (with one word we will grep for colorify)
200
if [ "$(echo "$list" | wc -w)" -gt 1 ] ; then
203
echon " | grep -E -i -- \"$i\""
207
# FIXME: move from it
210
# TODO: sorts word by length from large to short
214
for i in $list $listN; do
215
[ -n "$COLO" ] && COLO="$COLO|"
219
# TODO: use some colorifer instead grep (check grep adove too)
220
if [ -n "$list" ] ; then
221
echon " | grep -E -i $EGREPCOLOR -- \"($COLO)\""
225
# we need internal implementation because regular epm_search uses quotes_args
226
__epm_search_internal()
228
[ -n "$1" ] || fatal "Search: search argument(s) is missed"
230
# it is useful for first time running
231
update_repo_if_needed soft
235
__epm_search_output $(get_firstarg $@) | grep "$*"
238
# copied from korinf/tools/run-script/scripts/search
242
[ -n "$1" ] || fatal "Search: search argument(s) is missed"
244
# it is useful for first time running
245
update_repo_if_needed soft
249
echo "$*" | grep -q "\.[*?]" && warning "Only glob symbols * and ? are supported. Don't use regexp here!"
251
# FIXME: do it better
253
MGS=$(eval __epm_search_make_grep $quoted_args)
254
EXTRA_SHOWDOCMD="$MGS"
255
# TODO: use search args for more optimal output
256
eval "__epm_search_output \"$(eval get_firstarg $quoted_args | __clean_from_glob)\" $MGS"