From 75d22d865f6f8559f53acb56e95e00fb038ebb18 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 12 Oct 2021 23:21:30 -0700 Subject: [PATCH 1/3] lib/reloader: adopt `_bash-it-log-prefix-by-path()` --- scripts/reloader.bash | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/reloader.bash b/scripts/reloader.bash index 4bc2494132..5871b7cf71 100755 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -1,14 +1,6 @@ #!/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: " -} - if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then _bash_it_config_type="" @@ -22,7 +14,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then 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}" + _bash-it-log-prefix-by-path "${_bash_it_config_file}" _log_debug "Loading component..." # shellcheck source=/dev/null source $_bash_it_config_file @@ -38,7 +30,7 @@ if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${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 "$BASH_IT/${2}/enabled/*.bash")); do if [[ -e "$_bash_it_config_file" ]]; then - _set-prefix-based-on-path "${_bash_it_config_file}" + _bash-it-log-prefix-by-path "${_bash_it_config_file}" _log_debug "Loading component..." # shellcheck source=/dev/null source "$_bash_it_config_file" From fd7b20b8d711c682b0e731a21d87593dc6333df2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 12 Oct 2021 22:02:09 -0700 Subject: [PATCH 2/3] reloader: `shellcheck` && `shfmt` Rewrite globbing per `shellcheck`'s SC2013 recommendations, and standardize whitespace. --- clean_files.txt | 1 + scripts/reloader.bash | 79 ++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 35 deletions(-) mode change 100755 => 100644 scripts/reloader.bash diff --git a/clean_files.txt b/clean_files.txt index 06b19f5d42..ced8ec58a8 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -18,6 +18,7 @@ # docs/ hooks/ +scripts/ # root files # diff --git a/scripts/reloader.bash b/scripts/reloader.bash old mode 100755 new mode 100644 index 5871b7cf71..9299a4e441 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -1,44 +1,53 @@ -#!/bin/bash +# shellcheck shell=bash +# +# The core component loader. + +# shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="core: reloader: " -if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then - _bash_it_config_type="" +if [[ "${1:-}" != "skip" ]] && [[ -d "${BASH_IT?}/enabled" ]]; then + _bash_it_config_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 + 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 "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do - if [ -e "${_bash_it_config_file}" ]; then - _bash-it-log-prefix-by-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_config_file in "$BASH_IT/enabled"/*"${_bash_it_config_type}.bash"; do + if [[ -e "${_bash_it_config_file}" ]]; then + _bash-it-log-prefix-by-path "${_bash_it_config_file}" + _log_debug "Loading component..." + # shellcheck source=/dev/null + source "$_bash_it_config_file" + _log_debug "Loaded." + else + _log_error "Unable to read ${_bash_it_config_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 - _bash-it-log-prefix-by-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_config_file in "$BASH_IT/${2}/enabled"/*.bash; do + if [[ -e "$_bash_it_config_file" ]]; then + _bash-it-log-prefix-by-path "${_bash_it_config_file}" + _log_debug "Loading component..." + # shellcheck source=/dev/null + source "$_bash_it_config_file" + _log_debug "Loaded." + else + _log_error "Unable to locate ${_bash_it_config_file}" + fi + done + ;; + esac fi unset _bash_it_config_file From 26b402e254a0fbe1b4af11f6460645de1368dfec Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 13:58:00 -0800 Subject: [PATCH 3/3] lib/reloader: unset "${!_bash_it_reloader_@}" --- scripts/reloader.bash | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/reloader.bash b/scripts/reloader.bash index 9299a4e441..846bbf75ee 100644 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -4,13 +4,12 @@ # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="core: reloader: " +_bash_it_reloader_type="" if [[ "${1:-}" != "skip" ]] && [[ -d "${BASH_IT?}/enabled" ]]; then - _bash_it_config_type="" - case $1 in alias | completion | plugin) - _bash_it_config_type=$1 + _bash_it_reloader_type=$1 _log_debug "Loading enabled $1 components..." ;; '' | *) @@ -18,15 +17,15 @@ if [[ "${1:-}" != "skip" ]] && [[ -d "${BASH_IT?}/enabled" ]]; then ;; esac - for _bash_it_config_file in "$BASH_IT/enabled"/*"${_bash_it_config_type}.bash"; do - if [[ -e "${_bash_it_config_file}" ]]; then - _bash-it-log-prefix-by-path "${_bash_it_config_file}" + 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_config_file" + source "$_bash_it_reloader_file" _log_debug "Loaded." else - _log_error "Unable to read ${_bash_it_config_file}" + _log_error "Unable to read ${_bash_it_reloader_file}" fi done fi @@ -35,20 +34,19 @@ 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 "$BASH_IT/${2}/enabled"/*.bash; do - if [[ -e "$_bash_it_config_file" ]]; then - _bash-it-log-prefix-by-path "${_bash_it_config_file}" + 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_config_file" + source "$_bash_it_reloader_file" _log_debug "Loaded." else - _log_error "Unable to locate ${_bash_it_config_file}" + _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_@}"