diff --git a/README.md b/README.md index 1cb8609..25ec54b 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,16 @@ bash library for gentoo utils ## How to use +Just source it! + ```bash source etools ``` -## Configuration - -etools searches for a configuration file at the following locations: -```shell -/etc/etools/etools.conf -$HOME/.config/etools.conf -$HOME/.config/etools/etools.conf -``` - ## What it does provided function are the following: + ```bash einfo ewarn @@ -27,5 +21,52 @@ eerror etools_configure etools_unset etools_smart_find [repo] +# repo can be a path relative to /var/db/repos/ or a full path +# default will be /var/db/repos/ so all repos will be searched +# btw feel free to time it ;) +``` + +## Configuration + +etools searches for a configuration file at the following locations: + +```shell +/etc/etools/etools.conf +$HOME/.config/etools.conf +$HOME/.config/etools/etools.conf +``` + +Look at [the exmaple configuration file](etools.conf) for an example with all configuration options. +For the default values take a look at [config.sh](config.sh). + +> **_NOTE:_** Letting already set options fallback to defaults will not work, as defaults only get set when the relative variables are undefined. To force reload: + +```bash +etools_unset +source etools +``` + +## Motivation + +They say "A picture is worth a thousand words", so here ya go: +![](https://github.com/fabolous005/etools/blob/main/assets/motivation.png?raw=true) + +## Test it + +This script reads all packages in your world file and runs etools_smart_find with the name of the package + +```bash +while IFS= read -r line; do + if [[ ${line%% *} == ${line##* } ]]; then + echo -e "${line%% *} \e[32mpassed\e[0m"; + else + echo -e "${line%% *} \e[31mFAILED\e[0m"; + fi; +done <<< $( + for pkg in $(cat /var/lib/portage/world); do + echo -n "$pkg "; + etools_smart_find $(echo $pkg | awk -F'/' '{print $2}'); + done +); ``` diff --git a/assets/motivation.png b/assets/motivation.png new file mode 100644 index 0000000..7594ae0 Binary files /dev/null and b/assets/motivation.png differ diff --git a/config.sh b/config.sh index 31e9f89..03ad7c8 100755 --- a/config.sh +++ b/config.sh @@ -32,6 +32,7 @@ function _configure() { --exclude app-emacs --exclude dev-ruby --exclude acct-user --exclude acct-group --type directory --format '"\"{}\""' --max-depth 3 --case-sensitive'''} + # WARN: this section is not tested # [ -z "${ETOOLS_FIND_CMD}" ] && ETOOLS_FIND_CMD="find" # [ -z "${ETOOLS_FIND_ARGS}" ] && \ # ETOOLS_FIND_ARGS="\ diff --git a/etools.conf b/etools.conf index d77db4b..73917f1 100755 --- a/etools.conf +++ b/etools.conf @@ -1,6 +1,33 @@ #!/bin/bash # shellcheck disable=SC2034 +# INFO: the default flags can be founc in config.sh + +# 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 example"} + +# 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 +# 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"} + + +# This declares an associative array with a regex as key and relative numbers as weights declare -Ag package_weights package_weights["-bin"]=-10 package_weights["dev-cpp"]=-3 @@ -8,9 +35,12 @@ package_weights["dev-python"]=-5 package_weights["dev-haskell"]=-15 package_weights["gnustep-base"]=-5 + ETOOLS_DEBUG=false +# define custom function that will be called to set package weights +# note that function names must start with `etools_find_sort` # function etools_find_sort_custom() { # for package in "${!_etools_packages[@]}"; do # if [[ $package =~ -bin ]]; then