From 24b2f2d2e9fbde46ec89951fdf95af7417009eac Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Sat, 19 Dec 2020 01:44:52 +0000 Subject: [PATCH] Optimized statement with REGEX by using `case` REGEX is a great feature of BASH, but in this case it was energy needlessly spent. A `case` statement suffices. Bring in REGEX when you're going to make good use of it, otherwise it's just going to bog down your code. I also wanted to strip the ` || exit 1` on the last line, but I wasn't sure if this file is meant to be sourced or not; if not, then exiting like that is redundant because it will already exit with whichever status the last command provides, unless `popd` specifically offers unhelpful or no exit statuses. --- scripts/reloader.bash | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/reloader.bash b/scripts/reloader.bash index 9563e525..ddca30dc 100644 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -11,12 +11,15 @@ function _set-prefix-based-on-path() if [ "$1" != "skip" ] && [ -d "./enabled" ]; then _bash_it_config_type="" - if [[ "${1}" =~ ^(alias|completion|plugin)$ ]]; then - _bash_it_config_type=$1 - _log_debug "Loading enabled $1 components..." - else - _log_debug "Loading all enabled components..." - fi + + case $1 in + alias|completion|plugin) + _bash_it_config_type=$1 + _log_debug "Loading enabled $1 components..." ;; + *|'') + _log_debug "Loading all enabled components..." ;; + esac + for _bash_it_config_file in $(sort <(compgen -G "./enabled/*${_bash_it_config_type}.bash")); do if [ -e "${_bash_it_config_file}" ]; then _set-prefix-based-on-path "${_bash_it_config_file}"