continuer filter fuinction && start with custom_sort for user config

This commit is contained in:
fabolous005 2024-09-12 22:04:34 +02:00
parent e16f248180
commit 80b5c23e96
2 changed files with 50 additions and 22 deletions

View File

@ -4,9 +4,12 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# The script is being executed directly
for function in \
_formatted_find \
_sort_weights \
_get_heighest \
_sort_table \
_filter;
do
unset $function
unset $function || echo "failed to unset function: $function"
done
fi
@ -15,12 +18,12 @@ function _formatted_find() {
# Prevent wordsplitting
if [ "${ETOOLS_FIND_CMD}" = "fd" ]; then
# shellcheck disable=SC2086
fd $ETOOLS_FIND_ARGS "${1}" "${2}" && [ "${ETOOLS_DEBUG}" ] && \
einfo fd $ETOOLS_FIND_ARGS "${1}" "${2}" >&2
fd $ETOOLS_FIND_ARGS "${1}" "${2}"
[ "${ETOOLS_DEBUG}" ] && einfo fd "${1}" "${2}" "$ETOOLS_FIND_ARGS" >&2
else
# shellcheck disable=SC2086
"$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}" && [ "${ETOOLS_DEBUG}" ] && \
einfo "$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}" >&2
"$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}"
[ "${ETOOLS_DEBUG}" ] && einfo "${ETOOLS_FIND_CMD}" "${2}" "$ETOOLS_FIND_ARGS" "${1}" >&2
fi
else
echo called fd 3
@ -28,7 +31,30 @@ function _formatted_find() {
fi
}
function _filter() {
# TODO: continue here
echo "$@"
function _sort_weights() {
declare -n arr=$1
}
function _get_heighest() {
echo
}
function _sort_table() {
echo
}
function _filter() {
(( $# <= 1 )) && ewarn "No packages found, review config options" && return 1;
echo "$@"
declare -A packages
for package in "$@"; do
packages[$(echo "$package" | awk -F'/' '{print $(NF-1)"/"$NF}')]=0
done
for function in \
_sort_table \
$(declare -F | "${ETOOLS_GREP_CMD}" 'etools_find_sort_') \
_get_heighest;
do
$function packages
done
}

View File

@ -15,10 +15,10 @@ function etools_configure() {
# The find command to run
[ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="fd"
# The Argyments passed to the find command
[ -z "${ETOOLS_FIND_ARGS}" ] && ETOOLS_FIND_ARGS="
--exclude profile --exclude scripts --exclude eclass --exclude metadata \
--exclude app-emacs --exclude dev-ruby --exclude acct-user --exclude acct-group \
--type d"
[ -z "${ETOOLS_FIND_ARGS}" ] && ETOOLS_FIND_ARGS='''
--exclude profile --exclude scripts --exclude eclass --exclude metadata
--exclude app-emacs --exclude dev-ruby --exclude acct-user --exclude acct-group
--type directory --format '\"{}\"''''
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
@ -37,11 +37,13 @@ function etools_configure() {
[ -z "${ETOOLS_REPO_PATH}" ] && ETOOLS_REPO_PATH="/var/db/repos"
[ -z "${COLOR_INFO}" ] && COLOR_INFO='\033[1;34m'
[ -z "${COLOR_WARN}" ] && COLOR_WARN='\033[1;33m'
[ -z "${COLOR_ERROR}" ] && COLOR_ERROR='\033[1;31m'
[ -z "${ETOOLS_COLOR_INFO}" ] && ETOOLS_COLOR_INFO='\033[1;34m'
[ -z "${ETOOLS_COLOR_WARN}" ] && ETOOLS_COLOR_WARN='\033[1;33m'
[ -z "${ETOOLS_COLOR_ERROR}" ] && ETOOLS_COLOR_ERROR='\033[1;31m'
[ -z "${ETOOLS_GREP_CMD}" ] && ETOOLS_GREP_CMD="rg"
[ -z "${ETOOLS_DEBUG}" ] && ETOOLS_DEBUG=:
}
@ -58,14 +60,13 @@ function etools_smart_find() {
eerror "no valid repository name" && return 2;
. ./etools-helper.sh
if [[ "${2}" == /* ]]; then
_filer "$(_formatted_find "$@")"
_filter $(_formatted_find "$@")
else
_filter "$(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}")"
_filter $(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}")
fi
else
. ./etools-helper.sh
_filter "$(_formatted_find "${1}" "/var/db/repos/")"
_filter $(_formatted_find "${1}" "/var/db/repos")
fi
# unset helper functions
./etools-helper.sh
@ -91,17 +92,17 @@ function etools_unset() {
# INFO: einfo function
einfo() {
echo -e " ${COLOR_INFO}*\033[0m $*"
echo -e " ${ETOOLS_COLOR_INFO}*\033[0m $*"
}
# INFO: ewarn function
ewarn() {
echo -e " ${COLOR_WARN}* WARNING:\033[0m $*"
echo -e " ${ETOOLS_COLOR_WARN}* WARNING:\033[0m $*"
}
# INFO: eerror function
eerror() {
echo -e " ${COLOR_ERROR}* ERROR:\033[0m $*"
echo -e " ${ETOOLS_COLOR_ERROR}* ERROR:\033[0m $*"
}
@ -110,4 +111,5 @@ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
etools_configure
else
ewarn "this is a library do not execute it, source it instead" >&2
return 2;
fi