add _get_high function and trailing match logic
This commit is contained in:
parent
c11f6cd396
commit
035ef798f6
@ -24,8 +24,9 @@ function _configure() {
|
|||||||
# The Argyments passed to the find command
|
# The Argyments passed to the find command
|
||||||
ETOOLS_FIND_ARGS=${ETOOLS_FIND_ARGS:-'''
|
ETOOLS_FIND_ARGS=${ETOOLS_FIND_ARGS:-'''
|
||||||
--exclude profiles --exclude scripts --exclude eclass --exclude metadata
|
--exclude profiles --exclude scripts --exclude eclass --exclude metadata
|
||||||
|
--exclude dev-perl --exclude dev-ml
|
||||||
--exclude app-emacs --exclude dev-ruby --exclude acct-user --exclude acct-group
|
--exclude app-emacs --exclude dev-ruby --exclude acct-user --exclude acct-group
|
||||||
--type directory --format '"\"{}\""' --max-depth 3'''}
|
--type directory --format '"\"{}\""' --max-depth 3 --case-sensitive'''}
|
||||||
|
|
||||||
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
|
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
|
||||||
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
|
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
|
||||||
|
|||||||
6
etools
6
etools
@ -23,15 +23,15 @@ function etools_smart_find() {
|
|||||||
. ./helper.sh
|
. ./helper.sh
|
||||||
if [[ "${2}" == /* ]]; then
|
if [[ "${2}" == /* ]]; then
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
_filter $(_formatted_find "$@")
|
_most_probable "$1" $(_filter $(_formatted_find "$@"))
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
_filter $(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}")
|
_most_probable "$1" $(_filter $(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}"))
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
. ./helper.sh
|
. ./helper.sh
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
_filter $(_formatted_find "${1}" "/var/db/repos")
|
_most_probable "$1" $(_filter $(_formatted_find "${1}" "/var/db/repos"))
|
||||||
fi
|
fi
|
||||||
# unset helper functions
|
# unset helper functions
|
||||||
./helper.sh
|
./helper.sh
|
||||||
|
|||||||
41
helper.sh
41
helper.sh
@ -5,10 +5,12 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|||||||
for function in \
|
for function in \
|
||||||
_formatted_find \
|
_formatted_find \
|
||||||
_set_weights \
|
_set_weights \
|
||||||
_get_heighest \
|
_get_highest \
|
||||||
|
_get_high \
|
||||||
_default_sort \
|
_default_sort \
|
||||||
_etools_print_assoc_array \
|
_etools_print_assoc_array \
|
||||||
_debug_time \
|
_debug_time \
|
||||||
|
_most_probable \
|
||||||
_filter;
|
_filter;
|
||||||
do
|
do
|
||||||
unset $function || echo "failed to unset function: $function"
|
unset $function || echo "failed to unset function: $function"
|
||||||
@ -37,16 +39,16 @@ function _set_weights() {
|
|||||||
# allow reference to sourced value
|
# allow reference to sourced value
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
for regex in "${!package_weights[@]}"; do
|
for regex in "${!package_weights[@]}"; do
|
||||||
if [[ $package =~ ^*${regex}*$ ]]; then
|
if [[ $package =~ ${regex} ]]; then
|
||||||
_etools_packages[$package]=${package_weights[$regex]}
|
_etools_packages[$package]=${package_weights[$regex]}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_heighest() {
|
function _get_highest() {
|
||||||
local max_key=""
|
local max_key=""
|
||||||
local max_value=-100
|
local max_value=-100000
|
||||||
|
|
||||||
for key in "${!_etools_packages[@]}"; do
|
for key in "${!_etools_packages[@]}"; do
|
||||||
if (( _etools_packages["$key"] > max_value )); then
|
if (( _etools_packages["$key"] > max_value )); then
|
||||||
@ -57,6 +59,35 @@ function _get_heighest() {
|
|||||||
echo "$max_key"
|
echo "$max_key"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _get_high() {
|
||||||
|
local packages=()
|
||||||
|
local max_value=-100000
|
||||||
|
|
||||||
|
for key in "${!_etools_packages[@]}"; do
|
||||||
|
if (( _etools_packages["$key"] > max_value )); then
|
||||||
|
packages=("\"$key\"")
|
||||||
|
max_value=${_etools_packages[$key]}
|
||||||
|
elif (( _etools_packages[$key] == max_value )); then
|
||||||
|
packages+=("\"$key\"")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "${packages[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _most_probable() {
|
||||||
|
# echo $*
|
||||||
|
# echo $#
|
||||||
|
# echo $1
|
||||||
|
# echo $2
|
||||||
|
(( $# == 2 )) && echo "$2" && return 0;
|
||||||
|
for package in "${@:2}"; do
|
||||||
|
# echo "$package"
|
||||||
|
if [[ ${package//\"/} == *"$1" ]]; then
|
||||||
|
echo "${package//\"/}" && return 0;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
function _default_sort() {
|
function _default_sort() {
|
||||||
for package in "${!_etools_packages[@]}"; do
|
for package in "${!_etools_packages[@]}"; do
|
||||||
case $package in
|
case $package in
|
||||||
@ -103,5 +134,5 @@ function _filter() {
|
|||||||
$function
|
$function
|
||||||
done
|
done
|
||||||
# _etools_print_assoc_array
|
# _etools_print_assoc_array
|
||||||
_get_heighest
|
_get_high
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user