move configuration to different file

This commit is contained in:
fabolous005 2024-09-13 12:05:23 +02:00
parent 43414109d8
commit 674bf18d65
3 changed files with 64 additions and 42 deletions

54
config.sh Normal file
View File

@ -0,0 +1,54 @@
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# The script is being executed directly
for function in \
_configure;
do
unset $function || echo "failed to unset function: $function"
done
fi
function _configure() {
# Load config for shellcheck
# shellcheck source=/etc/etools/etools.conf
[ -f "/etc/etools/etools.conf" ] && . "/etc/etools/etools.conf"
# shellcheck source=~/.config/etools.conf
[ -f "$HOME/.config/etools.conf" ] && . "$HOME/.config/etools.conf"
# shellcheck source=~/.config/etools/etools.conf
[ -f "$HOME/.config/etools/etools.conf" ] && . "$HOME/.config/etools/etools.conf"
# The find command to run
ETOOLS_FIND_CMD=${ETOOLS_FIND_CMD:-"fd"}
# The Argyments passed to the find command
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}" ] && \
# ETOOLS_FIND_ARGS="\
# ! -path './profile*' ! -path './scripts*' -path './eclass*' ! -path './metadata*' \
# ! -path './app-emacs*' ! -path './dev-ruby*' ! -path './acct-user*' ! -path './acct-group*' \
# -type d -name"
# A full command that may be specified if FIND_CMD and FIND_ARGS cannot fulfill the needed job
# use {package} as a wildcart for the package that should be search for
# use {repo} as a wildcart for the repo to search
# use any other variable from ETOOLS inside it
# [ -z "${ETOOLS_FIND_COMMAND}" ] && ETOOLS_FIND_COMMAND="fd ${ETOOLS_FIND_ARGS} {package} {repo}"
# The default path in which to look for the repos
ETOOLS_REPO_PATH=${ETOOLS_REPO_PATH:-"/var/db/repos"}
ETOOLS_COLOR_INFO=${ETOOLS_COLOR_INFO:-'\033[1;34m'}
ETOOLS_COLOR_WARN=${ETOOLS_COLOR_WARN:-'\033[1;33m'}
ETOOLS_COLOR_ERROR=${ETOOLS_COLOR_ERROR:-'\033[1;31m'}
ETOOLS_GREP_CMD=${ETOOLS_GREP_CMD:-"rg"}
ETOOLS_DEBUG=${ETOOLS_DEBUG:-:}
}

View File

@ -73,10 +73,13 @@ function _filter() {
done
local functions=
functions="$(declare -F | "${ETOOLS_GREP_CMD}" 'etools_find_sort_' | awk '{print $3}')"
# HACK: iterating over possibly fragile output of splitted functions
# leave warning untils this is stable/fixed
for function in \
_sort_table \
${functions[@]};
do
# TODO: put loop here so not every function has to loop through the array
$function
done
_get_heighest

View File

@ -1,50 +1,12 @@
#!/usr/bin/env bash
# NOTE: parse config, gets run when sourced
function etools_configure() {
# Load config for shellcheck
# shellcheck source=/etc/etools/etools.conf
[ -f "/etc/etools/etools.conf" ] && . "/etc/etools/etools.conf"
# shellcheck source=~/.config/etools.conf
[ -f "$HOME/.config/etools.conf" ] && . "$HOME/.config/etools.conf"
# shellcheck source=~/.config/etools/etools.conf
[ -f "$HOME/.config/etools/etools.conf" ] && . "$HOME/.config/etools/etools.conf"
# 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 directory --format '\"{}\"''''
# [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find"
# [ -z "${ETOOLS_FIND_ARGS}" ] && \
# ETOOLS_FIND_ARGS="\
# ! -path './profile*' ! -path './scripts*' -path './eclass*' ! -path './metadata*' \
# ! -path './app-emacs*' ! -path './dev-ruby*' ! -path './acct-user*' ! -path './acct-group*' \
# -type d -name"
# A full command that may be specified if FIND_CMD and FIND_ARGS cannot fulfill the needed job
# use {package} as a wildcart for the package that should be search for
# use {repo} as a wildcart for the repo to search
# use any other variable from ETOOLS inside it
# [ -z "${ETOOLS_FIND_COMMAND}" ] && ETOOLS_FIND_COMMAND="fd ${ETOOLS_FIND_ARGS} {package} {repo}"
# The default path in which to look for the repos
[ -z "${ETOOLS_REPO_PATH}" ] && ETOOLS_REPO_PATH="/var/db/repos"
[ -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=:
. ./config.sh
_configure
./config.sh
}
@ -84,6 +46,9 @@ function etools_unset() {
ETOOLS_FIND_ARGS \
ETOOLS_FIND_COMMAND \
ETOOLS_REPO_PATH \
einfo \
ewarn \
eerror \
etools_configure \
etools_smart_find \
etools_unset;