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.
pull/1749/head
terminalforlife 2020-12-19 01:44:52 +00:00
parent e1372dd5bd
commit 24b2f2d2e9
1 changed files with 9 additions and 6 deletions

View File

@ -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}"