From cb8f034f7683132dcdfe044a2b77750e78ce97dd Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Sat, 19 Dec 2020 01:57:24 +0000 Subject: [PATCH] Optimize as before but with 2nd REGEX instance This time is much like the last commit, so I won't repeat, but I will say that you're using a double- or even triple-negative, which obfuscates your goal. Where you were doing... [ ! -n VAR ] && You were basically saying this convolution: If it's true that it's not true that VAR is not empty. Very confusing. Instead, I've opted for: If it's true that Var is empty. Makes immediate sense and is easier to parse, visually speaking. --- scripts/reloader.bash | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/reloader.bash b/scripts/reloader.bash index ddca30dc..e5fb4e39 100644 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -32,19 +32,21 @@ if [ "$1" != "skip" ] && [ -d "./enabled" ]; then done fi - -if [ ! -z "${2}" ] && [[ "${2}" =~ ^(aliases|completion|plugins)$ ]] && [ -d "${2}/enabled" ]; then - _log_warning "Using legacy enabling for $2, please update your bash-it version and migrate" - for _bash_it_config_file in $(sort <(compgen -G "./${2}/enabled/*.bash")); do - if [ -e "$_bash_it_config_file" ]; then - _set-prefix-based-on-path "${_bash_it_config_file}" - _log_debug "Loading component..." - # shellcheck source=/dev/null - source "$_bash_it_config_file" - else - echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr - fi - done +if [ -n "${2}" ] && [ -d "${2}/enabled" ]; then + case $2 in + aliases|completion|plugins) + _log_warning "Using legacy enabling for $2, please update your bash-it version and migrate" + for _bash_it_config_file in $(sort <(compgen -G "./${2}/enabled/*.bash")); do + if [ -e "$_bash_it_config_file" ]; then + _set-prefix-based-on-path "${_bash_it_config_file}" + _log_debug "Loading component..." + # shellcheck source=/dev/null + source "$_bash_it_config_file" + else + echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr + fi + done ;; + esac fi unset _bash_it_config_file