Skip to content

Commit

Permalink
re-order for clarity and because preexec must be last. general cleanu…
Browse files Browse the repository at this point in the history
…p too.
  • Loading branch information
cornfeedhobo committed Jan 31, 2021
1 parent a6b37e2 commit 87db68b
Showing 1 changed file with 74 additions and 50 deletions.
124 changes: 74 additions & 50 deletions bash_it.sh
Original file line number Diff line number Diff line change
@@ -1,115 +1,128 @@
#!/usr/bin/env bash
# Initialize Bash It
BASH_IT_LOG_PREFIX="core: main: "

# Only set $BASH_IT if it's not already set
if [ -z "$BASH_IT" ]; then
if [[ -z "$BASH_IT" ]]; then
# Setting $BASH to maintain backwards compatibility
export BASH_IT=$BASH
BASH="$(bash -c 'echo $BASH')"
export BASH
BASH_IT_OLD_BASH_SETUP=true
fi

# Load composure first, so we support function metadata
# Load composure first, to support function metadata, then create our custom attributes.
# shellcheck source=./lib/composure.bash
source "${BASH_IT}/lib/composure.bash"
# We need to load logging module first as well in order to be able to log
cite _about _param _example _group _author _version
cite about-alias about-completion about-plugin

# Next, load our logging library so we can give useful feedback to the user
# shellcheck source=./lib/log.bash
source "${BASH_IT}/lib/log.bash"

# We can only log it now
[ -z "$BASH_IT_OLD_BASH_SETUP" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
BASH_IT_LOG_PREFIX='core: main: '

# Check for old installations
if [[ -n "$BASH_IT_OLD_BASH_SETUP" ]]; then
_log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
fi

# For backwards compatibility, look in old BASH_THEME location
if [ -z "$BASH_IT_THEME" ]; then
if [[ -z "$BASH_IT_THEME" ]]; then
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
export BASH_IT_THEME="$BASH_THEME"
unset BASH_THEME
fi

# support 'plumbing' metadata
cite _about _param _example _group _author _version
# Load the base libraries ...

# libraries, but skip appearance (themes) for now
_log_debug "Loading libraries(except appearance)..."
LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for _bash_it_config_file in $LIB; do
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
filename=${_bash_it_config_file##*/}
filename=${filename%.bash}
BASH_IT_LOG_PREFIX="lib: ${filename}: "
_log_debug "Loading library file..."
# shellcheck disable=SC1090
source "$_bash_it_config_file"
fi
done
# start with utilities - internal functions meant for use within the bash-it codebase
BASH_IT_LOG_PREFIX='lib: utilities: '
_log_debug 'Loading library file ...'
# shellcheck source=./lib/utilities.bash
source "${BASH_IT}/lib/utilities.bash"

# Load vendors
BASH_IT_LOG_PREFIX="vendor: "
for _bash_it_vendor_init in "${BASH_IT}"/vendor/init.d/*.bash; do
_log_debug "Loading \"$(basename "${_bash_it_vendor_init}" .bash)\"..."
# shellcheck disable=SC1090
source "${_bash_it_vendor_init}"
done
unset _bash_it_vendor_init
# then helpers - generic functions meant for generic use by end users,
# often wrappers of functions found in utilities
BASH_IT_LOG_PREFIX='lib: helpers: '
_log_debug 'Loading library file ...'
# shellcheck source=./lib/helpers.bash
source "${BASH_IT}/lib/helpers.bash"

# next search - allows end users to search for matching aliases, plugins and completions in bash-it
BASH_IT_LOG_PREFIX='lib: search: '
_log_debug 'Loading library file ...'
# shellcheck source=./lib/search.bash
source "${BASH_IT}/lib/search.bash"

# Load aliases, completion, plugins ...
BASH_IT_LOG_PREFIX='core: main: '

BASH_IT_LOG_PREFIX="core: main: "
# Load the global "enabled" directory
# "family" param is empty so that files get sources in glob order
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash"

# Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion"; do
for file_type in 'aliases' 'plugins' 'completion'; do
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
source "${BASH_IT}/scripts/reloader.bash" 'skip' "$file_type"
done

# Load theme, if a theme was set
if [[ -n "${BASH_IT_THEME}" ]]; then
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."

# Load colors and helpers first so they can be used in base theme
BASH_IT_LOG_PREFIX="themes: colors: "
BASH_IT_LOG_PREFIX='themes: colors: '
_log_debug 'Loading theme file ...'
# shellcheck source=./themes/colors.theme.bash
source "${BASH_IT}/themes/colors.theme.bash"
BASH_IT_LOG_PREFIX="themes: githelpers: "

BASH_IT_LOG_PREFIX='themes: githelpers: '
_log_debug 'Loading theme file ...'
# shellcheck source=./themes/githelpers.theme.bash
source "${BASH_IT}/themes/githelpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: p4helpers: "

BASH_IT_LOG_PREFIX='themes: p4helpers: '
_log_debug 'Loading theme file ...'
# shellcheck source=./themes/p4helpers.theme.bash
source "${BASH_IT}/themes/p4helpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: command_duration: "

BASH_IT_LOG_PREFIX='themes: command_duration: '
_log_debug 'Loading theme file ...'
# shellcheck source=./themes/command_duration.theme.bash
source "${BASH_IT}/themes/command_duration.theme.bash"
BASH_IT_LOG_PREFIX="themes: base: "

BASH_IT_LOG_PREFIX='themes: base: '
_log_debug 'Loading theme file ...'
# shellcheck source=./themes/base.theme.bash
source "${BASH_IT}/themes/base.theme.bash"

BASH_IT_LOG_PREFIX="lib: appearance: "
BASH_IT_LOG_PREFIX='lib: appearance: '
_log_debug 'Loading library file ...'
# appearance (themes) now, after all dependencies
# shellcheck source=./lib/appearance.bash
source "$APPEARANCE_LIB"
source "${BASH_IT}/lib/appearance.bash"
fi

BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading custom aliases, completion, plugins..."
for file_type in "aliases" "completion" "plugins"; do
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
# Load custom components ...

BASH_IT_LOG_PREFIX='core: main: '
_log_debug 'Loading custom aliases, completion, plugins...'
for file_type in 'aliases' 'completion' 'plugins'; do
if [[ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]]; then
BASH_IT_LOG_PREFIX="${file_type}: custom: "
_log_debug "Loading component..."
_log_debug 'Loading component...'
# shellcheck disable=SC1090
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
fi
done

# Custom
BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading general custom files..."
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for _bash_it_config_file in $CUSTOM; do
if [ -e "${_bash_it_config_file}" ]; then
if [[ -e "${_bash_it_config_file}" ]]; then
filename=$(basename "${_bash_it_config_file}")
filename=${filename%*.bash}
BASH_IT_LOG_PREFIX="custom: $filename: "
Expand All @@ -135,7 +148,6 @@ elif [ -s /Applications/Preview.app ]; then
fi

# Load all the Jekyll stuff

if [ -e "$HOME/.jekyllconfig" ]; then
# shellcheck disable=SC1090
. "$HOME/.jekyllconfig"
Expand All @@ -153,5 +165,17 @@ if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then
esac
fi

# Now that everything is loaded and configured, load the previewer
BASH_IT_LOG_PREFIX='lib: preview: '
# and the associated preview script
# shellcheck source=./lib/preview.bash
source "${BASH_IT}/lib/preview.bash"

# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
set +T

# Finally, load preexec directly from vendor.
# This has to be last because it wants to have full control over DEBUG trap and PROMPT_COMMAND
BASH_IT_LOG_PREFIX='vendor: bash-preexec: '
# shellcheck source=./vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
source "${BASH_IT}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh"

0 comments on commit 87db68b

Please sign in to comment.