prettify README

This commit is contained in:
fabolous005 2024-09-15 20:30:45 +02:00
parent 5a0f4dbba5
commit d019ca15df
4 changed files with 81 additions and 9 deletions

View File

@ -4,22 +4,16 @@ bash library for gentoo utils
## How to use ## How to use
Just source it!
```bash ```bash
source etools 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 ## What it does
provided function are the following: provided function are the following:
```bash ```bash
einfo <info> einfo <info>
ewarn <warning> ewarn <warning>
@ -27,5 +21,52 @@ eerror <error>
etools_configure etools_configure
etools_unset etools_unset
etools_smart_find <package name> [repo] etools_smart_find <package name> [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
);
``` ```

BIN
assets/motivation.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@ -32,6 +32,7 @@ function _configure() {
--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 directory --format '"\"{}\""' --max-depth 3 --case-sensitive'''} --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_CMD}" ] && ETOOLS_FIND_CMD="find"
# [ -z "${ETOOLS_FIND_ARGS}" ] && \ # [ -z "${ETOOLS_FIND_ARGS}" ] && \
# ETOOLS_FIND_ARGS="\ # ETOOLS_FIND_ARGS="\

View File

@ -1,6 +1,33 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2034 # 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 declare -Ag package_weights
package_weights["-bin"]=-10 package_weights["-bin"]=-10
package_weights["dev-cpp"]=-3 package_weights["dev-cpp"]=-3
@ -8,9 +35,12 @@ package_weights["dev-python"]=-5
package_weights["dev-haskell"]=-15 package_weights["dev-haskell"]=-15
package_weights["gnustep-base"]=-5 package_weights["gnustep-base"]=-5
ETOOLS_DEBUG=false 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() { # function etools_find_sort_custom() {
# for package in "${!_etools_packages[@]}"; do # for package in "${!_etools_packages[@]}"; do
# if [[ $package =~ -bin ]]; then # if [[ $package =~ -bin ]]; then