From 80b5c23e968bae3686663b297c45e06a46c3ff86 Mon Sep 17 00:00:00 2001 From: fabolous005 Date: Thu, 12 Sep 2024 22:04:34 +0200 Subject: [PATCH] continuer filter fuinction && start with custom_sort for user config --- etools-helper.sh | 42 ++++++++++++++++++++++++++++++++++-------- etools.sh | 30 ++++++++++++++++-------------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/etools-helper.sh b/etools-helper.sh index 70d15a7..44dec71 100755 --- a/etools-helper.sh +++ b/etools-helper.sh @@ -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 } diff --git a/etools.sh b/etools.sh index 7acb771..11ea7e0 100644 --- a/etools.sh +++ b/etools.sh @@ -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