From: Matthias Kruk Date: Thu, 22 Dec 2022 05:04:54 +0000 (+0900) Subject: toolbox.sh: Add the script path to the module search paths X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=103062b3b9fab5929ac5fec8d72979c903e82d67;p=toolbox toolbox.sh: Add the script path to the module search paths 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. --- diff --git a/toolbox.sh b/toolbox.sh index 8df68ad..924b11b 100644 --- a/toolbox.sh +++ b/toolbox.sh @@ -19,17 +19,26 @@ __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" )