-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2055 from gaelicWizard/lib/reloader
lib/reloader: lint and modernize
- Loading branch information
Showing
2 changed files
with
46 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
# | ||
docs/ | ||
hooks/ | ||
scripts/ | ||
|
||
# root files | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
#!/bin/bash | ||
BASH_IT_LOG_PREFIX="core: reloader: " | ||
|
||
function _set-prefix-based-on-path() | ||
{ | ||
filename=$(_bash-it-get-component-name-from-path "$1") | ||
extension=$(_bash-it-get-component-type-from-path "$1") | ||
# shellcheck disable=SC2034 | ||
BASH_IT_LOG_PREFIX="$extension: $filename: " | ||
} | ||
# shellcheck shell=bash | ||
# | ||
# The core component loader. | ||
|
||
if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then | ||
_bash_it_config_type="" | ||
# shellcheck disable=SC2034 | ||
BASH_IT_LOG_PREFIX="core: reloader: " | ||
_bash_it_reloader_type="" | ||
|
||
case $1 in | ||
alias|completion|plugin) | ||
_bash_it_config_type=$1 | ||
_log_debug "Loading enabled $1 components..." ;; | ||
''|*) | ||
_log_debug "Loading all enabled components..." ;; | ||
esac | ||
if [[ "${1:-}" != "skip" ]] && [[ -d "${BASH_IT?}/enabled" ]]; then | ||
case $1 in | ||
alias | completion | plugin) | ||
_bash_it_reloader_type=$1 | ||
_log_debug "Loading enabled $1 components..." | ||
;; | ||
'' | *) | ||
_log_debug "Loading all enabled components..." | ||
;; | ||
esac | ||
|
||
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.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 read ${_bash_it_config_file}" > /dev/stderr | ||
fi | ||
done | ||
for _bash_it_reloader_file in "$BASH_IT/enabled"/*"${_bash_it_reloader_type}.bash"; do | ||
if [[ -e "${_bash_it_reloader_file}" ]]; then | ||
_bash-it-log-prefix-by-path "${_bash_it_reloader_file}" | ||
_log_debug "Loading component..." | ||
# shellcheck source=/dev/null | ||
source "$_bash_it_reloader_file" | ||
_log_debug "Loaded." | ||
else | ||
_log_error "Unable to read ${_bash_it_reloader_file}" | ||
fi | ||
done | ||
fi | ||
|
||
if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${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 "$BASH_IT/${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 | ||
if [[ -n "${2:-}" ]] && [[ -d "$BASH_IT/${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_reloader_file in "$BASH_IT/${2}/enabled"/*.bash; do | ||
if [[ -e "$_bash_it_reloader_file" ]]; then | ||
_bash-it-log-prefix-by-path "${_bash_it_reloader_file}" | ||
_log_debug "Loading component..." | ||
# shellcheck source=/dev/null | ||
source "$_bash_it_reloader_file" | ||
_log_debug "Loaded." | ||
else | ||
_log_error "Unable to locate ${_bash_it_reloader_file}" | ||
fi | ||
done | ||
;; | ||
esac | ||
fi | ||
|
||
unset _bash_it_config_file | ||
unset _bash_it_config_type | ||
unset "${!_bash_it_reloader_@}" |