ohmyksh/lib/loader.ksh

84 lines
1.3 KiB
Bash
Raw Normal View History

2020-07-15 16:28:24 -06:00
#!/bin/ksh
_loaded() {
${DEBUG}
local _val=$1 _set
shift
for _set; do
[[ $_val == "$_set" ]] && return 0
2020-07-15 16:28:24 -06:00
done
return 1
2020-07-15 16:28:24 -06:00
}
load() {
local _e=$1
[[ -x $_e ]] && \
. $_e
}
load_extension() {
${LOAD_EXTENSION_DEBUG}
local _ext=$1 _l=${#extensions[@]} _n
if ! _loaded "$_ext" "${extensions[@]}"; then
2020-07-15 16:28:24 -06:00
${LOAD_EXTENSION_DEBUG}
((_n=_l+1))
extensions[$_n]=$_ext
2020-07-15 16:28:24 -06:00
load ${LOAD_PATH}/extensions/${_ext}.ksh
else
echo "Warning: extension '$_ext' already loaded"
2020-07-15 16:28:24 -06:00
fi
}
load_completion() {
${LOAD_COMPLETION_DEBUG}
local _comp=$1 _l=${#completions[@]} _n
if ! _loaded "$_comp" "${completions[@]}"; then
${LOAD_COMPLETION_DEBUG}
((_n=_l+1))
completions[$_n]=$_comp
load ${LOAD_PATH}/completions/${_comp}.ksh
else
echo "Warning: completion '$_comp' already loaded"
fi
2020-07-15 16:28:24 -06:00
}
set_prompt() {
${PROMPT_DEBUG}
local _prmpt=$1
load ${LOAD_PATH}/prompts/${_prmpt}.ksh
}
paths() {
${PATHS_DEBUG}
local _path_list="$@"
for p in ${_path_list[@]}; do
${PATHS_DEBUG}
[[ -d "${p}" ]] && PATH="${PATH}:$p"
done
export PATH
}
reload_completions() {
for _comp in ${completions[@]}; do
load ${LOAD_PATH}/completions/${_comp}.ksh
done
}
reload_extensions() {
for _ext in ${extensions[@]}; do
load ${LOAD_PATH}/extensions/${_ext}.ksh
done
}
reload() {
reload_completions
reload_extensions
}