From: Redjard <eselect.patches.gen...@redjard.org>

Add Hooks to Eselect

For example for "eselect kernel list" the script /etc/eselect/hooks/kernel/list/pre is called before the eselect acts, and /etc/eselect/hooks/kernel/list/post afterwards.
In the functions you can use and modify $params, the value of which the
do_<action> function of the respective select module is then called with.
  by Redjard 2023-08-18 (eselect.patches.gen...@redjard.org)

https://discord.com/channels/249111029668249601/1140975737168478279

--- a/libs/core.bash.in
+++ b/libs/core.bash.in
@@ -20,10 +20,22 @@
-check_do() {
+check_do() {
        local function=$1
-       shift
+       shift; params="$@"
        if is_function "${function}" ; then
-               ${function} "$@"
+               run_hook "${ESELECT_MODULE_NAME}" "${function##do_}" pre
+               ${function} "${params}"
+               run_hook "${ESELECT_MODULE_NAME}" "${function##do_}" post
        else
                die "No function ${function}"
        fi
 }

+# Redjard patch: call hooks
+run_hook() {
+       local action=$1
+       local subaction=$2
+       local script=$3
+       if [[ -e "/etc/eselect/hooks/${action}/${subaction}/${script}" ]];then
+               source "/etc/eselect/hooks/${action}/${subaction}/${script}"
+       fi
+}
+

Reply via email to