mirror of
https://github.com/sbopkg/sbopkg
synced 2024-11-10 03:50:33 +03:00
fixed command line search with the -s/-g flags
* search_package(): modified to return a sorted list * gen_search_package(): moved my select menu to the new function. * search_and_display(): new function which takes one or more arguments (literal or quoted globs) from the command line (-s) and uses search_package() to return an array of possible matches. If more than one app is returned, it presents the user with a menu. It displays the standard files associated with the app the user chooses. If search_package() only returns one app, it displays the associated files immediately. Despite being a new function, this merely restores old functionality (albeit somewhat improved) which had been broken. * main: moved the old code from the SEARCH test block to the new function, replacing it with a call to that function. * main: temporarily disabled pathname expansion in part of the GENSEARCH test block (and in part of the new function) so it wouldn't break if someone searched for 'fu*' with a 'fubar' file in the current directory. Also modified the man page and one comment regarding details of these flags/functions.
This commit is contained in:
parent
29c2e449e5
commit
3a92318fa8
@ -253,7 +253,8 @@ with
|
|||||||
.BI \-g " PACKAGE(s)"
|
.BI \-g " PACKAGE(s)"
|
||||||
General search for
|
General search for
|
||||||
.I PACKAGE(s)
|
.I PACKAGE(s)
|
||||||
by glob.
|
by case-insensitive glob where the argument is automatically wrapped in
|
||||||
|
.BR * s.
|
||||||
If more than one glob is specified, they must be quoted.
|
If more than one glob is specified, they must be quoted.
|
||||||
.IP
|
.IP
|
||||||
For example:
|
For example:
|
||||||
@ -361,7 +362,7 @@ This is useful when the user wants to make a final check.
|
|||||||
.BI \-s " PACKAGE(s)"
|
.BI \-s " PACKAGE(s)"
|
||||||
Specific search for
|
Specific search for
|
||||||
.I PACKAGE(s)
|
.I PACKAGE(s)
|
||||||
by name and, if found, display the
|
by case-sensitive glob and, if found, display the
|
||||||
.IR README ,
|
.IR README ,
|
||||||
.IR SlackBuild ,
|
.IR SlackBuild ,
|
||||||
.IR .info ,
|
.IR .info ,
|
||||||
@ -371,7 +372,7 @@ files in that order for each
|
|||||||
.I PACKAGE
|
.I PACKAGE
|
||||||
found, using
|
found, using
|
||||||
.IR $PAGER .
|
.IR $PAGER .
|
||||||
If more than one package is specified, they must be quoted.
|
If more than one glob is specified, they must be quoted.
|
||||||
.IP
|
.IP
|
||||||
For example:
|
For example:
|
||||||
.RS
|
.RS
|
||||||
@ -386,6 +387,17 @@ exactly
|
|||||||
.I foo
|
.I foo
|
||||||
or
|
or
|
||||||
.IR bar .
|
.IR bar .
|
||||||
|
.IP
|
||||||
|
Note that shell metacharacters may be supplied in the arguments. For
|
||||||
|
instance,
|
||||||
|
.RS
|
||||||
|
.IP
|
||||||
|
.nf
|
||||||
|
\fC# sbopkg -s '*[Oo]pen*'\fP
|
||||||
|
.fi
|
||||||
|
.RE
|
||||||
|
.IP
|
||||||
|
will return all packages with 'open' or 'Open' anywhere in the name.
|
||||||
.\"---------------------------------------------------------------------
|
.\"---------------------------------------------------------------------
|
||||||
.TP
|
.TP
|
||||||
.B \-u
|
.B \-u
|
||||||
|
@ -2390,7 +2390,7 @@ search_package() {
|
|||||||
|
|
||||||
cd $REPO_DIR
|
cd $REPO_DIR
|
||||||
PKG="$1"
|
PKG="$1"
|
||||||
PKGPATH=( $(find -type d -mindepth 2 -name "$PKG") )
|
PKGPATH=( $(find -type d -mindepth 2 -name "$PKG" | sort) )
|
||||||
|
|
||||||
if [[ -z $PKGPATH ]]; then
|
if [[ -z $PKGPATH ]]; then
|
||||||
return 1
|
return 1
|
||||||
@ -2400,8 +2400,9 @@ search_package() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gen_search_package() {
|
gen_search_package() {
|
||||||
# Search for package name glob generally using grep. In dialog interface,
|
# Search for package name glob generally using the '-iwholename' argument
|
||||||
# jump to selected package.
|
# to find, with values wrapped in '*'. In dialog interface, jump to
|
||||||
|
# selected package.
|
||||||
# Returns 0 unless the user asked to jump back to the main menu.
|
# Returns 0 unless the user asked to jump back to the main menu.
|
||||||
|
|
||||||
cd $REPO_DIR
|
cd $REPO_DIR
|
||||||
@ -3422,25 +3423,9 @@ pick_file() {
|
|||||||
local PKGPATH=$2
|
local PKGPATH=$2
|
||||||
local PKG=$3
|
local PKG=$3
|
||||||
PICKFILE=original
|
PICKFILE=original
|
||||||
local ITEM ANS REPLY
|
local ANS REPLY
|
||||||
|
|
||||||
rm -f $SBOPKGTMP/sbopkg_file_selection $SBOPKGTMP/sbopkg_diff
|
rm -f $SBOPKGTMP/sbopkg_file_selection $SBOPKGTMP/sbopkg_diff
|
||||||
# FIXME slakmagik, what's going on here?
|
|
||||||
# (this was added in r446)
|
|
||||||
if (( ${#PKGPATH[*]} > 1 )); then
|
|
||||||
select ITEM in ${PKGPATH[*]#*/} Quit; do
|
|
||||||
if [[ $ITEM == Quit ]]; then
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
PKGPATH=$ITEM
|
|
||||||
if [[ -z $ITEM ]]; then
|
|
||||||
echo "$SCRIPT: invalid choice."
|
|
||||||
continue
|
|
||||||
else
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build the diff, if there are 2 files to choose between
|
# Build the diff, if there are 2 files to choose between
|
||||||
if [[ -f $PKGPATH/$PKG.$FILE.sbopkg ]]; then
|
if [[ -f $PKGPATH/$PKG.$FILE.sbopkg ]]; then
|
||||||
@ -4148,6 +4133,48 @@ control_c() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
search_and_display() {
|
||||||
|
# This function takes one or more arguments from the command line (-s):
|
||||||
|
# the pattern(s) the user provides as the app to search for.
|
||||||
|
#
|
||||||
|
# This uses search_package() to return an array of possible matches. If
|
||||||
|
# more than one app is returned, it presents the user with a menu. It
|
||||||
|
# displays the default files associated with the app the user chooses. If
|
||||||
|
# search_package() only returns one app, it displays the associated files
|
||||||
|
# immediately.
|
||||||
|
|
||||||
|
# global SCRIPT SEARCH
|
||||||
|
local PKGSEARCH PKGPATH ITEM
|
||||||
|
|
||||||
|
check_if_repo_exists
|
||||||
|
# We temporarily turn globbing off and turn it back on before we get to
|
||||||
|
# pick_file()/show_readme(). There, we need to expand globs and will be
|
||||||
|
# using full paths or be in the right directory to do so.
|
||||||
|
set -f
|
||||||
|
for PKGSEARCH in $SEARCH; do
|
||||||
|
echo "Searching for $PKGSEARCH"
|
||||||
|
if search_package $PKGSEARCH; then
|
||||||
|
if (( ${#PKGPATH[*]} > 1 )); then
|
||||||
|
select PKGPATH in ${PKGPATH[*]#*/} Quit; do
|
||||||
|
case $PKGPATH in
|
||||||
|
Quit) exit ;;
|
||||||
|
'') echo "$SCRIPT: invalid choice."; continue ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
set +f
|
||||||
|
# the only reason we need to go through pick_file() is that it
|
||||||
|
# provides the .build copies of the files that show_readme()
|
||||||
|
# insists upon. Otherwise, I'd just show the default files.
|
||||||
|
pick_file info $PKGPATH $PKGSEARCH
|
||||||
|
show_readme $PKGPATH $PKGSEARCH
|
||||||
|
else
|
||||||
|
echo "$SCRIPT: package \"$PKGSEARCH\" not found." >&2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
main_search() {
|
main_search() {
|
||||||
# This is the main package search gateway, showing the search box dialog
|
# This is the main package search gateway, showing the search box dialog
|
||||||
# and calling the appropriate search function after validating the user
|
# and calling the appropriate search function after validating the user
|
||||||
@ -4708,16 +4735,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n $SEARCH ]]; then
|
if [[ -n $SEARCH ]]; then
|
||||||
check_if_repo_exists
|
search_and_display "$SEARCH"
|
||||||
for PKGSEARCH in "$SEARCH"; do
|
|
||||||
echo "Searching for $PKGSEARCH"
|
|
||||||
if search_package $PKGSEARCH; then
|
|
||||||
pick_file info $PKGPATH $PKGSEARCH
|
|
||||||
show_readme $PKGPATH $PKGSEARCH
|
|
||||||
else
|
|
||||||
echo "ERROR: Package \"$PKGSEARCH\" not found." >&2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $UPDATE ]]; then
|
if [[ $UPDATE ]]; then
|
||||||
@ -4726,10 +4744,12 @@ else
|
|||||||
|
|
||||||
if [[ -n $GENSEARCH ]]; then
|
if [[ -n $GENSEARCH ]]; then
|
||||||
check_if_repo_exists
|
check_if_repo_exists
|
||||||
|
set -f
|
||||||
for PKGSEARCH in $GENSEARCH; do
|
for PKGSEARCH in $GENSEARCH; do
|
||||||
echo "Searching for $PKGSEARCH"
|
echo "Searching for $PKGSEARCH"
|
||||||
gen_search_package $PKGSEARCH
|
gen_search_package $PKGSEARCH
|
||||||
done
|
done
|
||||||
|
set +f
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user