1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/sh
#
# Copyright (C) 2012, 2013, 2016-2020 Etersoft
# Copyright (C) 2012, 2013, 2016-2020 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-check_updated_repo
load_helper epm-sh-warmup
__epm_search_output()
{
local CMD
local string="$1"
case $PMTYPE in
apt-rpm|apt-dpkg)
CMD="apt-cache search --"
;;
aptitude-dpkg)
CMD="aptitude search --"
;;
deepsolver-rpm)
CMD="ds-require --"
;;
packagekit)
CMD="pkcon search name"
;;
urpm-rpm)
# urpmq does not support --
CMD="urpmq -y"
;;
pkgsrc)
CMD="pkg_info -x --"
;;
pkgng)
CMD="pkg search -i --"
;;
emerge)
CMD="emerge --search --"
;;
pacman)
CMD="pacman -Ss --"
;;
aura)
CMD="aura -As --"
;;
yum-rpm)
CMD="yum search --"
;;
dnf-rpm)
CMD="dnf search --"
;;
zypper-rpm)
CMD="zypper search -d --"
;;
mpkg)
CMD="mpkg search"
;;
apk)
CMD="apk search"
;;
tce)
CMD="tce-ab"
;;
conary)
CMD="conary repquery"
;;
npackd)
docmd npackdcl search --query="$string" --status=all
return
;;
chocolatey)
CMD="chocolatey list"
;;
slackpkg)
# FIXME
echo "Note: case sensitive search"
if [ -n "$verbose" ] ; then
CMD="/usr/sbin/slackpkg search"
else
LANG=C docmd /usr/sbin/slackpkg search $string | grep " - " | sed -e 's|.* - ||g'
return
fi
;;
opkg)
CMD="opkg find"
;;
homebrew)
CMD="brew search"
;;
guix)
CMD="guix package -A"
;;
android)
CMD="pm list packages"
;;
aptcyg)
CMD="apt-cyg searchall"
;;
xbps)
CMD="xbps-query -s"
;;
appget|winget)
CMD="$PMTYPE search"
;;
*)
fatal "Have no suitable search command for $PMTYPE"
;;
esac
LANG=C docmd $CMD $string
}
# produce grep sequence
__epm_search_make_grep()
{
local i
[ -z "$*" ] && return
local list=
local listN=
for i in $@ ; do
case "$i" in
~*)
# will clean from ~ later (and have the bug here with empty arg if run with one ~ only)
listN="$listN $i"
;;
*)
list="$list $i"
;;
esac
done
#list=$(strip_spaces $list | sed -e "s/ /|/g")
listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/~//g")
if [ -n "$short" ] ; then
echon " | sed -e \"s| .*||g\""
fi
[ -n "$listN" ] && echon " | egrep -i -v -- \"$listN\""
# FIXME: The World has not idea how to do grep both string
# http://stackoverflow.com/questions/10110051/grep-with-two-strings-logical-and-in-regex?rq=1
# Need only if we have more than one word (with one word we will grep for colorify)
if [ "$(echo "$list" | wc -w)" -gt 1 ] ; then
for i in $list ; do
# FIXME -n on MacOS?
echon " | egrep -i -- \"$i\""
done
fi
# FIXME: move from it
#isatty || return
# TODO: sorts word by length from large to short
local COLO=""
# rule for colorife
for i in $list $listN; do
[ -n "$COLO" ] && COLO="$COLO|"
COLO="$COLO$i"
done
# TODO: use some colorifer instead grep (check grep adove too)
if [ -n "$list" ] ; then
echon " | egrep -i $EGREPCOLOR -- \"($COLO)\""
fi
}
__epm_search_internal()
{
[ -n "$pkg_filenames" ] || fatal "Search: missing search argument(s)"
# it is useful for first time running
update_repo_if_needed soft
warmup_bases
__epm_search_output $(get_firstarg $pkg_filenames) | grep "$pkg_filenames"
}
# copied from korinf/tools/run-script/scripts/search
epm_search()
{
[ -n "$pkg_filenames" ] || fatal "Search: missing search argument(s)"
# it is useful for first time running
update_repo_if_needed soft
warmup_bases
# FIXME: do it better
local MGS
MGS=$(eval __epm_search_make_grep $quoted_args)
EXTRA_SHOWDOCMD="$MGS"
eval "__epm_search_output \"$(eval get_firstarg $quoted_args)\" $MGS"
}