Skip to content

Commit

Permalink
Appease shellcheck
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/log.bash
#	themes/base.theme.bash
  • Loading branch information
gaelicWizard committed Aug 15, 2021
1 parent 836d009 commit 9e55192
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
78 changes: 40 additions & 38 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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-() {
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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"
Expand 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 ()
Expand All @@ -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 ()
Expand All @@ -544,7 +546,7 @@ _disable-alias ()
_example '$ disable-alias git'
_group 'lib'

_disable-thing "aliases" "alias" $1
_disable-thing "aliases" "alias" "$1"
}

_disable-completion ()
Expand All @@ -554,7 +556,7 @@ _disable-completion ()
_example '$ disable-completion git'
_group 'lib'

_disable-thing "completion" "completion" $1
_disable-thing "completion" "completion" "$1"
}

_disable-thing ()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ()
Expand All @@ -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 ()
Expand All @@ -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 ()
Expand All @@ -671,32 +673,32 @@ _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
fi

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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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 () {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/reloader.bash
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions themes/githelpers.theme.bash
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9e55192

Please sign in to comment.