]> git.corax.cc Git - toolbox/commitdiff
toolbox.sh: Add the script path to the module search paths
authorMatthias Kruk <m@m10k.eu>
Thu, 22 Dec 2022 05:04:54 +0000 (14:04 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 22 Dec 2022 05:04:54 +0000 (14:04 +0900)
Toolbox requires modules to be located either in ~/.toolbox/include
or in /usr/share/toolbox/include. This is somewhat inconvenient when
developing scripts with modules that are not supposed to be shared
with other scripts.

This commit adds the path of the executing script to the module
search path, allowing script-private modules to be placed in a
directory called "include" next to the script.

toolbox.sh

index 8df68adaf128128236254f7ee740b9d05c1a1b16..924b11b97606b3bcad6451455ffb2c183367e33f 100644 (file)
 __toolbox_init() {
        local toolboxpath
        local toolboxroot
+       local scriptpath
+       local scriptroot
 
        if ! toolboxpath=$(realpath "${BASH_SOURCE[0]}"); then
                echo "Could not determine toolbox path" 1>&2
                return 1
        fi
 
+       if ! scriptpath=$(realpath "${BASH_SOURCE[-1]}"); then
+               echo "Could not determine script path" 1>&2
+               return 1
+       fi
+
        toolboxroot="${toolboxpath%/*}"
+       scriptroot="${scriptpath%/*}"
 
        declare -gxr TOOLBOX_PATH="$toolboxroot"
        declare -gxr TOOLBOX_HOME="$HOME/.toolbox"
        declare -axgr __TOOLBOX_MODULEPATH=(
+               "$scriptroot/include"
                "$TOOLBOX_HOME/include"
                "$toolboxroot/include"
        )