continuer filter fuinction && start with custom_sort for user config
This commit is contained in:
parent
e16f248180
commit
80b5c23e96
@ -4,9 +4,12 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|||||||
# The script is being executed directly
|
# The script is being executed directly
|
||||||
for function in \
|
for function in \
|
||||||
_formatted_find \
|
_formatted_find \
|
||||||
|
_sort_weights \
|
||||||
|
_get_heighest \
|
||||||
|
_sort_table \
|
||||||
_filter;
|
_filter;
|
||||||
do
|
do
|
||||||
unset $function
|
unset $function || echo "failed to unset function: $function"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -15,12 +18,12 @@ function _formatted_find() {
|
|||||||
# Prevent wordsplitting
|
# Prevent wordsplitting
|
||||||
if [ "${ETOOLS_FIND_CMD}" = "fd" ]; then
|
if [ "${ETOOLS_FIND_CMD}" = "fd" ]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
fd $ETOOLS_FIND_ARGS "${1}" "${2}" && [ "${ETOOLS_DEBUG}" ] && \
|
fd $ETOOLS_FIND_ARGS "${1}" "${2}"
|
||||||
einfo fd $ETOOLS_FIND_ARGS "${1}" "${2}" >&2
|
[ "${ETOOLS_DEBUG}" ] && einfo fd "${1}" "${2}" "$ETOOLS_FIND_ARGS" >&2
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
"$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}" && [ "${ETOOLS_DEBUG}" ] && \
|
"$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}"
|
||||||
einfo "$ETOOLS_FIND_CMD" "${2}" $ETOOLS_FIND_ARGS "${1}" >&2
|
[ "${ETOOLS_DEBUG}" ] && einfo "${ETOOLS_FIND_CMD}" "${2}" "$ETOOLS_FIND_ARGS" "${1}" >&2
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo called fd 3
|
echo called fd 3
|
||||||
@ -28,7 +31,30 @@ function _formatted_find() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _filter() {
|
function _sort_weights() {
|
||||||
# TODO: continue here
|
declare -n arr=$1
|
||||||
echo "$@"
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
30
etools.sh
30
etools.sh
@ -15,10 +15,10 @@ function etools_configure() {
|
|||||||
# The find command to run
|
# The find command to run
|
||||||
[ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="fd"
|
[ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="fd"
|
||||||
# The Argyments passed to the find command
|
# The Argyments passed to the find command
|
||||||
[ -z "${ETOOLS_FIND_ARGS}" ] && ETOOLS_FIND_ARGS="
|
[ -z "${ETOOLS_FIND_ARGS}" ] && ETOOLS_FIND_ARGS='''
|
||||||
--exclude profile --exclude scripts --exclude eclass --exclude metadata \
|
--exclude profile --exclude scripts --exclude eclass --exclude metadata
|
||||||
--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 d"
|
--type directory --format '\"{}\"''''
|
||||||
|
|
||||||
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
|
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
|
||||||
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
|
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
|
||||||
@ -37,11 +37,13 @@ function etools_configure() {
|
|||||||
[ -z "${ETOOLS_REPO_PATH}" ] && ETOOLS_REPO_PATH="/var/db/repos"
|
[ -z "${ETOOLS_REPO_PATH}" ] && ETOOLS_REPO_PATH="/var/db/repos"
|
||||||
|
|
||||||
|
|
||||||
[ -z "${COLOR_INFO}" ] && COLOR_INFO='\033[1;34m'
|
[ -z "${ETOOLS_COLOR_INFO}" ] && ETOOLS_COLOR_INFO='\033[1;34m'
|
||||||
[ -z "${COLOR_WARN}" ] && COLOR_WARN='\033[1;33m'
|
[ -z "${ETOOLS_COLOR_WARN}" ] && ETOOLS_COLOR_WARN='\033[1;33m'
|
||||||
[ -z "${COLOR_ERROR}" ] && COLOR_ERROR='\033[1;31m'
|
[ -z "${ETOOLS_COLOR_ERROR}" ] && ETOOLS_COLOR_ERROR='\033[1;31m'
|
||||||
|
|
||||||
|
|
||||||
|
[ -z "${ETOOLS_GREP_CMD}" ] && ETOOLS_GREP_CMD="rg"
|
||||||
|
|
||||||
[ -z "${ETOOLS_DEBUG}" ] && ETOOLS_DEBUG=:
|
[ -z "${ETOOLS_DEBUG}" ] && ETOOLS_DEBUG=:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,14 +60,13 @@ function etools_smart_find() {
|
|||||||
eerror "no valid repository name" && return 2;
|
eerror "no valid repository name" && return 2;
|
||||||
. ./etools-helper.sh
|
. ./etools-helper.sh
|
||||||
if [[ "${2}" == /* ]]; then
|
if [[ "${2}" == /* ]]; then
|
||||||
_filer "$(_formatted_find "$@")"
|
_filter $(_formatted_find "$@")
|
||||||
else
|
else
|
||||||
_filter "$(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}")"
|
_filter $(_formatted_find "${1}" "${ETOOLS_REPO_PATH}/${2}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
. ./etools-helper.sh
|
. ./etools-helper.sh
|
||||||
_filter "$(_formatted_find "${1}" "/var/db/repos/")"
|
_filter $(_formatted_find "${1}" "/var/db/repos")
|
||||||
fi
|
fi
|
||||||
# unset helper functions
|
# unset helper functions
|
||||||
./etools-helper.sh
|
./etools-helper.sh
|
||||||
@ -91,17 +92,17 @@ function etools_unset() {
|
|||||||
|
|
||||||
# INFO: einfo function
|
# INFO: einfo function
|
||||||
einfo() {
|
einfo() {
|
||||||
echo -e " ${COLOR_INFO}*\033[0m $*"
|
echo -e " ${ETOOLS_COLOR_INFO}*\033[0m $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
# INFO: ewarn function
|
# INFO: ewarn function
|
||||||
ewarn() {
|
ewarn() {
|
||||||
echo -e " ${COLOR_WARN}* WARNING:\033[0m $*"
|
echo -e " ${ETOOLS_COLOR_WARN}* WARNING:\033[0m $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
# INFO: eerror function
|
# INFO: eerror function
|
||||||
eerror() {
|
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
|
etools_configure
|
||||||
else
|
else
|
||||||
ewarn "this is a library do not execute it, source it instead" >&2
|
ewarn "this is a library do not execute it, source it instead" >&2
|
||||||
|
return 2;
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user