mirror of
https://github.com/sbopkg/sbopkg
synced 2024-11-10 03:50:33 +03:00
Search: apply slakmagik's search_string patch
This patch adds the ability to search applications' READMEs for specific words, also using regular expressions. Many thanks to slakmagik for implementing this in the first place and for his efforts in addressing the minor problems affecting earlier versions of the code. Signed-off-by: slakmagik Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
parent
232921deb5
commit
5a7e20a146
@ -1493,7 +1493,7 @@ gen_search_package () {
|
||||
else
|
||||
if [ "$DIAG" = 1 ]; then
|
||||
dialog --title "ERROR" --msgbox "No match for $PKG found" 8 30
|
||||
main_search
|
||||
return
|
||||
else
|
||||
echo "$SCRIPT: No match for $PKG found." 1>&2
|
||||
continue
|
||||
@ -1501,6 +1501,73 @@ gen_search_package () {
|
||||
fi
|
||||
}
|
||||
|
||||
string_search() {
|
||||
local SEARCH_TERM="$1"
|
||||
local REPO="$LOCALREPO/$SLACKVER"
|
||||
local MENU_FILE=$TMP/sbopkg_menu-file
|
||||
local PICKED_FILE=$TMP/sbopkg_picked-file
|
||||
local PICKED
|
||||
|
||||
# the sed expression processes find's output into data usable for the menu
|
||||
# file but the first two parts are needed to sanitize the input - which
|
||||
# raises the question of true general sanitizing of this input
|
||||
( find $REPO -iname 'README' -exec egrep -iwm1 "$SEARCH_TERM" {} + |
|
||||
sed "
|
||||
s,\",\',g
|
||||
s/\\\/\\\\\\\\/g
|
||||
s,$REPO/,,
|
||||
s/^/\"/
|
||||
s,/README:,\" \",
|
||||
s/$/\"/
|
||||
" | sort > $MENU_FILE
|
||||
) 2>/dev/null
|
||||
|
||||
if ! [ -s $MENU_FILE ]; then
|
||||
dialog --title "ERROR" --msgbox "No match for $SEARCH_TERM found" 8 30
|
||||
return
|
||||
fi
|
||||
|
||||
cd $REPO
|
||||
|
||||
while :; do
|
||||
dialog --title "String Search Results" --default-item "$PICKED" \
|
||||
--extra-button --extra-label "Add to Queue" \
|
||||
--cancel-label "Back" \
|
||||
--menu "$(crunch "Please select an item you wish to view or \
|
||||
press <Add to Queue> to add it to the build queue or \
|
||||
press <Back> to go back.")" 0 0 0 \
|
||||
--file $MENU_FILE 2> $PICKED_FILE
|
||||
|
||||
BUTTON=$?
|
||||
PICKED=$(cat $PICKED_FILE)
|
||||
|
||||
# duplicate (except slightly modified) code from gen_package_search()
|
||||
SRCHCAT=${PICKED%%/*}
|
||||
echo $SRCHCAT >$TMP/sbopkg_category_selection
|
||||
SRCHPKG=${PICKED##*/}
|
||||
|
||||
case $BUTTON in
|
||||
0)
|
||||
echo $SRCHPKG > $TMP/sbopkg_item_selection
|
||||
info_item
|
||||
;;
|
||||
3)
|
||||
SHORTPATH=$REPO/$SRCHCAT/$SRCHPKG
|
||||
RVERSION=$(grep VERSION $SHORTPATH/$SRCHPKG.info |
|
||||
cut -d= -f2 | sed s/\"//g)
|
||||
RBUILD=$(egrep -m1 "^BUILD" $SHORTPATH/$SRCHPKG.SlackBuild |
|
||||
sed -e 's/^.*[=-]//;s/\"//;s/[ #}\t].*$//g;s/\"//g')
|
||||
add_item_to_queue $SRCHPKG $RVERSION-$RBUILD ON
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
rm -f $PICKED_FILE
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
show_readme () {
|
||||
# Show the package's text files.
|
||||
cd $LOCALREPO/$SLACKVER
|
||||
@ -2401,17 +2468,59 @@ control_c () {
|
||||
}
|
||||
|
||||
main_search() {
|
||||
local TERM_FILE=$TMP/sbopkg_search_request
|
||||
local PKG STRING SEARCH_TERM
|
||||
local REPO="$LOCALREPO/$SLACKVER"
|
||||
|
||||
check_if_repo_exists
|
||||
dialog --inputbox \
|
||||
"Enter the name of a package you would like to search for:" \
|
||||
9 40 2>/$TMP/sbopkg_search_request
|
||||
if [ $? != 0 ]; then
|
||||
continue
|
||||
fi
|
||||
SRCH="$(cat $TMP/sbopkg_search_request)"
|
||||
if [ ! "$SRCH" = "" ]; then
|
||||
gen_search_package $SRCH
|
||||
fi
|
||||
while :; do
|
||||
unset PKG STRING
|
||||
|
||||
dialog --title "Search" --ok-label "PKG" \
|
||||
--extra-button --extra-label "String" \
|
||||
--help-button --inputbox \
|
||||
"Enter your search term..." 8 39 2> $TERM_FILE
|
||||
case $? in # 0=PKG 3=String 1=Cancel 2=Help
|
||||
3) STRING=yes ;;
|
||||
2) dialog --title "Search Help" --msgbox \
|
||||
"$(crunch "This widget provides the choice of a package \
|
||||
<PKG> search or a string <String> search.\n\nThe package \
|
||||
search executes a glob search on package names in \
|
||||
$REPO.\n\nThe string search executes 'grep -iwm1 \
|
||||
\"<your_string>\"' on the README files in the repo. This \
|
||||
means it returns the first matching line from the README \
|
||||
files, where the line contains a case-insensitive word \
|
||||
that matches your string, where a 'word' is a sequence of \
|
||||
alphanumeric characters and underscores. For details, see \
|
||||
the egrep(1) manual page.")" 0 0
|
||||
continue
|
||||
;;
|
||||
0) PKG=yes ;;
|
||||
*) return ;;
|
||||
esac
|
||||
|
||||
if [ -s $TERM_FILE ]; then
|
||||
SEARCH_TERM="$(cat $TERM_FILE)"
|
||||
# I can't make sure every input makes sense, but I can at least
|
||||
# clear out this area of (fairly improbable) glitches
|
||||
if [[ $SEARCH_TERM =~ "^[\\\.\*\^\$\[\{\(\)\+\?\|]$" ]]; then
|
||||
dialog --msgbox "$(crunch "If you are searching for the \
|
||||
literal character '$SEARCH_TERM', then you will need to \
|
||||
escape it with a backslash like '\\\\$SEARCH_TERM'.\n\nIf you \
|
||||
are still not getting the expected results, remember that \
|
||||
this is a word match - try adding '.*'")" 0 0
|
||||
continue
|
||||
fi
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $PKG == yes ]]; then
|
||||
gen_search_package "$SEARCH_TERM"
|
||||
elif [[ $STRING == yes ]]; then
|
||||
string_search "$SEARCH_TERM"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
main_updates () {
|
||||
|
Loading…
Reference in New Issue
Block a user