fix "loaded" logic

- add loaded logic to completions
- add reload for completions and extensions
This commit is contained in:
Aaron Bieber 2020-07-17 07:12:22 -06:00
parent 6bbdc662fc
commit 6e0571866e
2 changed files with 44 additions and 14 deletions

View File

@ -1,15 +1,14 @@
#!/bin/ksh
extension_loaded() {
#${DEBUG}
local _ext=$1
_loaded() {
${DEBUG}
local _val=$1 _set
for c in ${extensions[@]}; do
if [ "${c}" == "${_ext}" ]; then
return 1
fi
shift
for _set; do
[[ $_val == "$_set" ]] && return 0
done
return 0
return 1
}
load() {
@ -20,20 +19,32 @@ load() {
load_extension() {
${LOAD_EXTENSION_DEBUG}
local _ext=$1
if [ ! $(extension_loaded $_ext) ]; then
local _ext=$1 _l=${#extensions[@]} _n
if ! _loaded "$_ext" "${extensions[@]}"; then
${LOAD_EXTENSION_DEBUG}
extensions[${#extensions[@]}]=$_ext
((_n=_l+1))
extensions[$_n]=$_ext
load ${LOAD_PATH}/extensions/${_ext}.ksh
else
echo "Warning: extension already loaded"
echo "Warning: extension '$_ext' already loaded"
fi
}
load_completion() {
${LOAD_COMPLETION_DEBUG}
local _comp=$1
load ${LOAD_PATH}/completions/${_comp}.ksh
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
}
set_prompt() {
@ -52,3 +63,21 @@ paths() {
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
}

View File

@ -6,4 +6,5 @@ LOAD_PATH="$OHMYKSH_DIR"
. ${LOAD_PATH}/lib/loader.ksh
set -A completions --
set -A extensions --