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_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"
)