From 9e5519229af961ad0fba20264c301a658f839b32 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 12 Aug 2021 13:09:00 -0700 Subject: [PATCH] Appease `shellcheck` # Conflicts: # lib/log.bash # themes/base.theme.bash --- lib/helpers.bash | 78 ++++++++++++++++++------------------ scripts/reloader.bash | 2 +- themes/githelpers.theme.bash | 4 +- 3 files changed, 43 insertions(+), 41 deletions(-) mode change 100644 => 100755 scripts/reloader.bash mode change 100644 => 100755 themes/githelpers.theme.bash diff --git a/lib/helpers.bash b/lib/helpers.bash index e0e1f17ee4..26562998c6 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -340,9 +340,9 @@ _bash-it-migrate() { typeset ff="${f##*/}" # Get the type of component from the extension - typeset single_type="$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')" + typeset single_type="$(echo "$ff" | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')" # Cut off the optional "250---" prefix and the suffix - typeset component_name="$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g')" + typeset component_name="$(echo "$ff" | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g')" migrated_something=true @@ -419,21 +419,21 @@ _bash-it-doctor-all() { _about 'reloads a profile file with error, warning and debug logs' _group 'lib' - _bash-it-doctor $BASH_IT_LOG_LEVEL_ALL + _bash-it-doctor "$BASH_IT_LOG_LEVEL_ALL" } _bash-it-doctor-warnings() { _about 'reloads a profile file with error and warning logs' _group 'lib' - _bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING + _bash-it-doctor "$BASH_IT_LOG_LEVEL_WARNING" } _bash-it-doctor-errors() { _about 'reloads a profile file with error logs' _group 'lib' - _bash-it-doctor $BASH_IT_LOG_LEVEL_ERROR + _bash-it-doctor "$BASH_IT_LOG_LEVEL_ERROR" } _bash-it-doctor-() { @@ -464,18 +464,20 @@ _bash-it-reload() { _about 'reloads a profile file' _group 'lib' - pushd "${BASH_IT}" &> /dev/null || return + pushd "${BASH_IT}" && { case $OSTYPE in darwin*) + # shellcheck disable=SC1090 source ~/.bash_profile ;; *) + # shellcheck disable=SC1090 source ~/.bashrc ;; esac - popd &> /dev/null || return + popd; } } _bash-it-describe () @@ -507,7 +509,7 @@ _bash-it-describe () else enabled=' ' fi - printf "%-20s%-10s%s\n" "$(basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(cat $f | metafor about-$file_type)" + printf "%-20s%-10s%s\n" "$(basename "$f" | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(metafor "about-$file_type" < "$f")" done printf '\n%s\n' "to enable $preposition $file_type, do:" printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all" @@ -522,8 +524,8 @@ _on-disable-callback() _example '$ _on-disable-callback gitstatus' _group 'lib' - callback=$1_on_disable - _command_exists $callback && $callback + callback="$1_on_disable" + _command_exists "$callback" && "$callback" } _disable-plugin () @@ -533,8 +535,8 @@ _disable-plugin () _example '$ disable-plugin rvm' _group 'lib' - _disable-thing "plugins" "plugin" $1 - _on-disable-callback $1 + _disable-thing "plugins" "plugin" "$1" + _on-disable-callback "$1" } _disable-alias () @@ -544,7 +546,7 @@ _disable-alias () _example '$ disable-alias git' _group 'lib' - _disable-thing "aliases" "alias" $1 + _disable-thing "aliases" "alias" "$1" } _disable-completion () @@ -554,7 +556,7 @@ _disable-completion () _example '$ disable-completion git' _group 'lib' - _disable-thing "completion" "completion" $1 + _disable-thing "completion" "completion" "$1" } _disable-thing () @@ -575,7 +577,7 @@ _disable-thing () fi typeset f suffix _bash_it_config_files - suffix="$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')" + suffix="${subdirectory/plugins/plugin}" if [ "$file_entity" = "all" ]; then # Disable everything that's using the old structure @@ -598,13 +600,13 @@ _disable-thing () done unset _bash_it_config_files else - typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1) + typeset plugin_global="$(command ls $ "${BASH_IT}/enabled"/[0-9]*"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash" 2>/dev/null | head -1)" if [ -z "$plugin_global" ]; then # Use a glob to search for both possible patterns # 250---node.plugin.bash # node.plugin.bash # Either one will be matched by this glob - typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1) + typeset plugin="$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash","${file_entity}.${suffix}.bash"} 2>/dev/null | head -1)" if [ -z "$plugin" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return @@ -627,7 +629,7 @@ _enable-plugin () _example '$ enable-plugin rvm' _group 'lib' - _enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN + _enable-thing "plugins" "plugin" "$1" "$BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN" } _enable-alias () @@ -637,7 +639,7 @@ _enable-alias () _example '$ enable-alias git' _group 'lib' - _enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS + _enable-thing "aliases" "alias" "$1" "$BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS" } _enable-completion () @@ -647,7 +649,7 @@ _enable-completion () _example '$ enable-completion git' _group 'lib' - _enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION + _enable-thing "completion" "completion" "$1" "$BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION" } _enable-thing () @@ -671,17 +673,17 @@ _enable-thing () fi if [ "$file_entity" = "all" ]; then - typeset f $file_type + typeset f file_type for f in "${BASH_IT}/$subdirectory/available"/*.bash do to_enable="$(basename "$f" ".$file_type.bash")" if [ "$file_type" = "alias" ]; then to_enable="$(basename "$f" ".aliases.bash")" fi - _enable-thing "$subdirectory" "$file_type" "$to_enable" $load_priority + _enable-thing "$subdirectory" "$file_type" "$to_enable" "$load_priority" done else - typeset to_enable="$(command ls "${BASH_IT}/$subdirectory/available"/$file_entity.*bash 2>/dev/null | head -1)" + typeset to_enable="$(command ls "${BASH_IT}/$subdirectory/available/$file_entity".*.bash 2>/dev/null | head -1)" if [ -z "$to_enable" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." return @@ -689,14 +691,14 @@ _enable-thing () to_enable="${to_enable##*/}" # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. - typeset enabled_plugin="$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)" - if [ ! -z "$enabled_plugin" ] ; then + typeset enabled_plugin="$(command ls "${BASH_IT}/$subdirectory/enabled"/{[0-9][0-9][0-9]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}","${to_enable}"} 2>/dev/null | head -1)" + if [ -n "$enabled_plugin" ] ; then printf '%s\n' "$file_entity is already enabled." return fi - typeset enabled_plugin_global="$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)" - if [ ! -z "$enabled_plugin_global" ] ; then + typeset enabled_plugin_global="$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" 2>/dev/null | head -1)" + if [ -n "$enabled_plugin_global" ] ; then printf '%s\n' "$file_entity is already enabled." return fi @@ -740,13 +742,13 @@ _help-aliases() alias_path="available/$1.aliases.bash" ;; esac - cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" + metafor alias < "${BASH_IT}/aliases/$alias_path" | sed "s/$/'/" else typeset f - for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")` + for f in $(sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")) do - _help-list-aliases $f + _help-list-aliases "$f" done if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then @@ -757,10 +759,10 @@ _help-aliases() _help-list-aliases () { - typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g') + typeset file="$(basename "$1" | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g')" printf '\n\n%s:\n' "${file}" # metafor() strips trailing quotes, restore them with sed.. - cat $1 | metafor alias | sed "s/$/'/" + metafor alias < "$1" | sed "s/$/'/" } _help-plugins() @@ -786,14 +788,14 @@ _help-plugins() printf '\r%s\n' ' ' typeset group typeset gfile - for gfile in $(cat $grouplist | sort | uniq) + for gfile in $(sort -u "$grouplist") do printf '%s\n' "${gfile##*.}:" - cat $gfile + cat "$gfile" printf '\n' - rm $gfile 2> /dev/null + rm "$gfile" 2> /dev/null done | less - rm $grouplist 2> /dev/null + rm "$grouplist" 2> /dev/null } _help-update () { @@ -822,8 +824,8 @@ all_groups () do typeset -f $func | metafor group >> $file done - cat $file | sort | uniq - rm $file + sort -u "$file" + rm "$file" } if ! type pathmunge > /dev/null 2>&1 diff --git a/scripts/reloader.bash b/scripts/reloader.bash old mode 100644 new mode 100755 index f22de67e81..ea16a353aa --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -15,7 +15,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then alias|completion|plugin) _bash_it_config_type=$1 _log_debug "Loading enabled $1 components..." ;; - *|'') + ''|*) _log_debug "Loading all enabled components..." ;; esac diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash old mode 100644 new mode 100755 index ba089392a3..39d6acaf60 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -30,7 +30,7 @@ function _git-commit-description { function _git-short-sha { if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then - echo ${VCS_STATUS_COMMIT:0:7} + echo "${VCS_STATUS_COMMIT:0:7}" else git rev-parse --short HEAD fi @@ -88,7 +88,7 @@ function _git-hide-status { function _git-status { local git_status_flags= - [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true + [[ "${SCM_GIT_IGNORE_UNTRACKED}" == "true" ]] && git_status_flags='-uno' git status --porcelain ${git_status_flags} 2> /dev/null }