From 6e0571866e6e5e648bd7b29ceb429bb2c2331972 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 17 Jul 2020 07:12:22 -0600 Subject: [PATCH] fix "loaded" logic - add loaded logic to completions - add reload for completions and extensions --- lib/loader.ksh | 57 +++++++++++++++++++++++++++++++++++++------------- ohmy.ksh | 1 + 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/loader.ksh b/lib/loader.ksh index a1dd730..e8e79cf 100644 --- a/lib/loader.ksh +++ b/lib/loader.ksh @@ -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 +} + diff --git a/ohmy.ksh b/ohmy.ksh index 8c60208..2fdf869 100755 --- a/ohmy.ksh +++ b/ohmy.ksh @@ -6,4 +6,5 @@ LOAD_PATH="$OHMYKSH_DIR" . ${LOAD_PATH}/lib/loader.ksh +set -A completions -- set -A extensions --