tmux-catppuccin-coal/utils/module_utils.sh
vdbe ff6dacb12f
feat: warning when trying to load a missing module (#244)
print/echo a warning when a `catppuccin_status_modules_right/left` is
trying to load a none existing module.
This does only work when reloading (`tmux source ~/.tmux.conf` /
`tmux source ~/.config/tmux/tmux.conf`)
2024-07-12 07:04:07 +00:00

41 lines
1 KiB
Bash

#!/bin/sh
load_modules() {
local modules_list=$1
shift
local module_directories=("$@")
local -i module_index=0;
local module_name
local module_path
local loaded_modules
local IN=$modules_list
# https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash#15988793
while [ "$IN" != "$iter" ] ;do
# extract the substring from start of string up to delimiter.
iter=${IN%% *}
# delete this first "element" AND next separator, from $IN.
IN="${IN#"$iter "}"
# Print (or doing anything with) the first "element".
module_name=$iter
for module_dir in "${module_directories[@]}" ; do
module_path="$module_dir/$module_name.sh"
if [ -r "$module_path" ]; then
# shellcheck source=/dev/null
source "$module_path"
loaded_modules="$loaded_modules$( "show_$module_name" "$module_index" )"
module_index+=1
continue 2
fi
done
tmux_echo "catppuccin warning: module $module_name not found"
done
echo "$loaded_modules"
}