diff --git a/bash_it.sh b/bash_it.sh index 215c33c7..db18f319 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -1,61 +1,57 @@ #!/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 - # Setting $BASH to maintain backwards compatibility - export BASH_IT=$BASH - BASH="$(bash -c 'echo $BASH')" - export BASH - BASH_IT_OLD_BASH_SETUP=true -fi +: "${BASH_IT:=${BASH_SOURCE%/*}}" +: "${BASH_IT_CUSTOM:=${BASH_IT}/custom}" +: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM}/themes"}" +# Store the rcfile for later +: "${BASH_IT_BASHRC:=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}}" # Load composure first, so we support function metadata -# shellcheck disable=SC1090 -source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh - -# We need to load logging module first as well in order to be able to log -# 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!" - -# For backwards compatibility, look in old BASH_THEME location -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 - +# shellcheck source-path=SCRIPTDIR/vendor/github.com/erichs/composure +source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" # support 'plumbing' metadata cite _about _param _example _group _author _version cite about-alias about-plugin about-completion +# We need to load logging module early in order to be able to log +# shellcheck source-path=SCRIPTDIR/lib +source "${BASH_IT}/lib/log.bash" + +# We can log now; sanity checks +BASH_IT_LOG_PREFIX="core: main: " +if [[ -d "${BASH}" ]]; then + _log_warning "BASH variable initialized improperly, please upgrade your bash-it version!" + BASH="$(bash -c 'echo $BASH')" +fi + # 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} +for _bash_it_lib_file in "${BASH_IT}"/lib/*.bash; do + if [[ "$_bash_it_lib_file" != "$APPEARANCE_LIB" ]]; then + filename="${_bash_it_lib_file##*/}" + filename="${filename%.bash}" BASH_IT_LOG_PREFIX="lib: ${filename}: " _log_debug "Loading library file..." - # shellcheck disable=SC1090 - source "$_bash_it_config_file" + # shellcheck source-path=SCRIPTDIR/lib disable=SC1090 + source "$_bash_it_lib_file" fi done +unset _bash_it_lib_file filename # 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)\"..." +for _bash_it_vendor_init in "${BASH_IT}/vendor/init.d"/*.bash; do + filename="${_bash_it_vendor_init##*/}" + filename="${filename%.bash}" + _log_debug "Loading '${filename}'..." # shellcheck disable=SC1090 source "${_bash_it_vendor_init}" done -unset _bash_it_vendor_init +unset _bash_it_vendor_init filename BASH_IT_LOG_PREFIX="core: main: " # Load the global "enabled" directory @@ -65,40 +61,48 @@ source "${BASH_IT}/scripts/reloader.bash" # Load enabled aliases, completion, plugins for file_type in "aliases" "plugins" "completion"; do - # shellcheck source=./scripts/reloader.bash + # shellcheck source-path=SCRIPTDIR/scripts source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type" done # Load theme, if a theme was set -if [[ -n "${BASH_IT_THEME}" ]]; then +# For backwards compatibility, look in old BASH_THEME location +if [[ -n "${BASH_IT_THEME:="${BASH_THEME:-}"}" ]]; then + if [[ -n "${BASH_THEME:-}" ]]; then + _log_warning "BASH_THEME variable is set, please use BASH_IT_THEME instead!" + unset BASH_THEME + fi + _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: " - # shellcheck source=./themes/colors.theme.bash + # shellcheck source-path=SCRIPTDIR/themes source "${BASH_IT}/themes/colors.theme.bash" BASH_IT_LOG_PREFIX="themes: githelpers: " - # shellcheck source=./themes/githelpers.theme.bash + # shellcheck source-path=SCRIPTDIR/themes source "${BASH_IT}/themes/githelpers.theme.bash" BASH_IT_LOG_PREFIX="themes: p4helpers: " - # shellcheck source=./themes/p4helpers.theme.bash + # shellcheck source-path=SCRIPTDIR/themes source "${BASH_IT}/themes/p4helpers.theme.bash" BASH_IT_LOG_PREFIX="themes: command_duration: " - # shellcheck source=./themes/command_duration.theme.bash + # shellcheck source-path=SCRIPTDIR/themes source "${BASH_IT}/themes/command_duration.theme.bash" BASH_IT_LOG_PREFIX="themes: base: " - # shellcheck source=./themes/base.theme.bash + # shellcheck source-path=SCRIPTDIR/themes source "${BASH_IT}/themes/base.theme.bash" BASH_IT_LOG_PREFIX="lib: appearance: " # appearance (themes) now, after all dependencies # shellcheck source=./lib/appearance.bash source "$APPEARANCE_LIB" +else + _log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version!" 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 + if [[ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]]; then BASH_IT_LOG_PREFIX="${file_type}: custom: " _log_debug "Loading component..." # shellcheck disable=SC1090 @@ -109,51 +113,47 @@ 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 - filename=$(basename "${_bash_it_config_file}") - filename=${filename%*.bash} - # shellcheck disable=SC2034 +for _bash_it_custom_file in "$BASH_IT_CUSTOM"/*.bash "$BASH_IT_CUSTOM"/*/*.bash; do + if [[ -e "${_bash_it_custom_file}" ]]; then + filename="${_bash_it_custom_file##*/}" + filename="${filename%*.bash}" + # shellcheck disable=SC2034 # expected BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..." # shellcheck disable=SC1090 - source "$_bash_it_config_file" + source "$_bash_it_custom_file" fi done +unset _bash_it_custom_file filename -unset _bash_it_config_file if [[ -n "${PROMPT:-}" ]]; then - export PS1="\[""$PROMPT""\]" + PS1="\[""$PROMPT""\]" fi # Adding Support for other OSes PREVIEW="less" - -if [ -s /usr/bin/gloobus-preview ]; then +if [[ -s /usr/bin/gloobus-preview ]]; then PREVIEW="gloobus-preview" -elif [ -s /Applications/Preview.app ]; then +elif [[ -s /Applications/Preview.app ]]; then # shellcheck disable=SC2034 PREVIEW="/Applications/Preview.app" fi # Load all the Jekyll stuff -if [ -e "$HOME/.jekyllconfig" ]; then +if [[ -e "$HOME/.jekyllconfig" ]]; then # shellcheck disable=SC1090 - . "$HOME/.jekyllconfig" + source "$HOME/.jekyllconfig" fi # BASH_IT_RELOAD_LEGACY is set. +# shellcheck disable=SC2139 if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then - case $OSTYPE in - darwin*) - alias reload='source ~/.bash_profile' - ;; - *) - alias reload='source ~/.bashrc' - ;; - esac + if shopt -q login_shell; then + alias reload="source '${BASH_IT_BASHRC:-$HOME/.bash_profile}'" + else + alias reload="source '${BASH_IT_BASHRC:-$HOME/.bashrc}'" + fi fi # Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040