Skip to content

Commit 23f9b74

Browse files
authored
Merge pull request #1902 from gaelicWizard/glob
Glob for *.bash properly when path contains spaces
2 parents 4dbe92e + 1461079 commit 23f9b74

File tree

1 file changed

+52
-86
lines changed

1 file changed

+52
-86
lines changed

bash_it.sh

Lines changed: 52 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,111 @@
11
#!/usr/bin/env bash
2+
# shellcheck source-path=SCRIPTDIR/lib source-path=SCRIPTDIR/scripts
3+
# shellcheck disable=SC2034
4+
#
25
# Initialize Bash It
36
BASH_IT_LOG_PREFIX="core: main: "
4-
5-
# Only set $BASH_IT if it's not already set
6-
if [ -z "${BASH_IT:-}" ]; then
7-
# Setting $BASH to maintain backwards compatibility
8-
export BASH_IT=$BASH
9-
BASH="$(bash -c 'echo $BASH')"
10-
export BASH
11-
BASH_IT_OLD_BASH_SETUP=true
12-
fi
7+
: "${BASH_IT:=${BASH_SOURCE%/*}}"
8+
: "${BASH_IT_CUSTOM:=${BASH_IT}/custom}"
9+
: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM}/themes"}"
10+
: "${BASH_IT_BASHRC:=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}}"
1311

1412
# Load composure first, so we support function metadata
15-
# shellcheck disable=SC1090
16-
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
13+
# shellcheck source-path=SCRIPTDIR/vendor/github.com/erichs/composure
14+
source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
15+
# support 'plumbing' metadata
16+
cite _about _param _example _group _author _version
17+
cite about-alias about-plugin about-completion
1718

18-
# Declare our end-of-main finishing hook
19-
declare -a _bash_it_library_finalize_hook
19+
# Declare our end-of-main finishing hook, but don't use `declare`/`typeset`
20+
_bash_it_library_finalize_hook=()
2021

2122
# We need to load logging module early in order to be able to log
22-
# shellcheck source-path=SCRIPTDIR/lib
2323
source "${BASH_IT}/lib/log.bash"
2424

25-
# We can only log it now
26-
[ -z "${BASH_IT_OLD_BASH_SETUP:-}" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
27-
28-
# For backwards compatibility, look in old BASH_THEME location
29-
if [ -z "${BASH_IT_THEME:-}" ]; then
30-
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
31-
export BASH_IT_THEME="${BASH_THEME:-}"
32-
unset BASH_THEME
33-
fi
34-
35-
# support 'plumbing' metadata
36-
cite _about _param _example _group _author _version
37-
cite about-alias about-plugin about-completion
38-
3925
# libraries, but skip appearance (themes) for now
4026
_log_debug "Loading libraries(except appearance)..."
41-
LIB="${BASH_IT}/lib/*.bash"
4227
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
43-
for _bash_it_config_file in $LIB; do
44-
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
45-
filename=${_bash_it_config_file##*/}
46-
filename=${filename%.bash}
47-
BASH_IT_LOG_PREFIX="lib: ${filename}: "
48-
_log_debug "Loading library file..."
49-
# shellcheck disable=SC1090
50-
source "$_bash_it_config_file"
51-
fi
28+
for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do
29+
[[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue
30+
_bash-it-log-prefix-by-path "${_bash_it_main_file_lib}"
31+
_log_debug "Loading library file..."
32+
# shellcheck disable=SC1090
33+
source "$_bash_it_main_file_lib"
34+
BASH_IT_LOG_PREFIX="core: main: "
5235
done
5336

54-
BASH_IT_LOG_PREFIX="core: main: "
55-
# Load the global "enabled" directory
56-
# "family" param is empty so that files get sources in glob order
57-
# shellcheck source=./scripts/reloader.bash
58-
source "${BASH_IT}/scripts/reloader.bash"
59-
60-
# Load enabled aliases, completion, plugins
61-
for file_type in "aliases" "plugins" "completion"; do
62-
# shellcheck source=./scripts/reloader.bash
63-
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
37+
# Load the global "enabled" directory, then enabled aliases, completion, plugins
38+
# "_bash_it_main_file_type" param is empty so that files get sourced in glob order
39+
for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do
40+
BASH_IT_LOG_PREFIX="core: reloader: "
41+
source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type"
42+
BASH_IT_LOG_PREFIX="core: main: "
6443
done
6544

6645
# Load theme, if a theme was set
67-
if [[ -n "${BASH_IT_THEME}" ]]; then
68-
_log_debug "Loading \"${BASH_IT_THEME}\" theme..."
46+
# shellcheck source-path=SCRIPTDIR/themes
47+
if [[ -n "${BASH_IT_THEME:-}" ]]; then
48+
_log_debug "Loading theme '${BASH_IT_THEME}'."
6949
BASH_IT_LOG_PREFIX="themes: githelpers: "
70-
# shellcheck source=./themes/githelpers.theme.bash
7150
source "${BASH_IT}/themes/githelpers.theme.bash"
7251
BASH_IT_LOG_PREFIX="themes: p4helpers: "
73-
# shellcheck source=./themes/p4helpers.theme.bash
7452
source "${BASH_IT}/themes/p4helpers.theme.bash"
7553
BASH_IT_LOG_PREFIX="themes: command_duration: "
76-
# shellcheck source=./themes/command_duration.theme.bash
7754
source "${BASH_IT}/themes/command_duration.theme.bash"
7855
BASH_IT_LOG_PREFIX="themes: base: "
79-
# shellcheck source=./themes/base.theme.bash
8056
source "${BASH_IT}/themes/base.theme.bash"
8157

8258
BASH_IT_LOG_PREFIX="lib: appearance: "
8359
# appearance (themes) now, after all dependencies
84-
# shellcheck source=./lib/appearance.bash
60+
# shellcheck source=SCRIPTDIR/lib/appearance.bash
8561
source "$APPEARANCE_LIB"
62+
BASH_IT_LOG_PREFIX="core: main: "
8663
fi
8764

88-
BASH_IT_LOG_PREFIX="core: main: "
8965
_log_debug "Loading custom aliases, completion, plugins..."
90-
for file_type in "aliases" "completion" "plugins"; do
91-
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then
92-
BASH_IT_LOG_PREFIX="${file_type}: custom: "
66+
for _bash_it_main_file_type in "aliases" "completion" "plugins"; do
67+
_bash_it_main_file_custom="${BASH_IT}/${_bash_it_main_file_type}/custom.${_bash_it_main_file_type}.bash"
68+
if [[ -s "${_bash_it_main_file_custom}" ]]; then
69+
_bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
9370
_log_debug "Loading component..."
9471
# shellcheck disable=SC1090
95-
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
72+
source "${_bash_it_main_file_custom}"
9673
fi
74+
BASH_IT_LOG_PREFIX="core: main: "
9775
done
9876

9977
# Custom
100-
BASH_IT_LOG_PREFIX="core: main: "
10178
_log_debug "Loading general custom files..."
102-
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
103-
for _bash_it_config_file in $CUSTOM; do
104-
if [ -e "${_bash_it_config_file}" ]; then
105-
filename=$(basename "${_bash_it_config_file}")
106-
filename=${filename%*.bash}
107-
# shellcheck disable=SC2034
108-
BASH_IT_LOG_PREFIX="custom: $filename: "
79+
for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/*/*.bash; do
80+
if [[ -s "${_bash_it_main_file_custom}" ]]; then
81+
_bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
10982
_log_debug "Loading custom file..."
11083
# shellcheck disable=SC1090
111-
source "$_bash_it_config_file"
84+
source "$_bash_it_main_file_custom"
11285
fi
86+
BASH_IT_LOG_PREFIX="core: main: "
11387
done
11488

115-
unset _bash_it_config_file
11689
if [[ -n "${PROMPT:-}" ]]; then
117-
export PS1="\[""$PROMPT""\]"
90+
PS1="${PROMPT}"
11891
fi
11992

12093
# Adding Support for other OSes
121-
PREVIEW="less"
122-
123-
if [ -s /usr/bin/gloobus-preview ]; then
94+
if _command_exists gloobus-preview; then
12495
PREVIEW="gloobus-preview"
125-
elif [ -s /Applications/Preview.app ]; then
126-
# shellcheck disable=SC2034
96+
elif [[ -d /Applications/Preview.app ]]; then
12797
PREVIEW="/Applications/Preview.app"
98+
else
99+
PREVIEW="less"
128100
fi
129101

130102
# BASH_IT_RELOAD_LEGACY is set.
131-
if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
132-
case $OSTYPE in
133-
darwin*)
134-
alias reload='source ~/.bash_profile'
135-
;;
136-
*)
137-
alias reload='source ~/.bashrc'
138-
;;
139-
esac
103+
if [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]] && ! _command_exists reload; then
104+
# shellcheck disable=SC2139
105+
alias reload="builtin source '${BASH_IT_BASHRC?}'"
140106
fi
141107

142108
for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
143109
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
144110
done
145-
unset "${!_bash_it_library_finalize_@}"
111+
unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}"

0 commit comments

Comments
 (0)