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