|
1 | 1 | #!/usr/bin/env bash
|
| 2 | +# shellcheck source-path=SCRIPTDIR/lib source-path=SCRIPTDIR/scripts |
| 3 | +# shellcheck disable=SC2034 |
| 4 | +# |
2 | 5 | # Initialize Bash It
|
3 | 6 | 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]}}" |
13 | 11 |
|
14 | 12 | # 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 |
17 | 18 |
|
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=() |
20 | 21 |
|
21 | 22 | # We need to load logging module early in order to be able to log
|
22 |
| -# shellcheck source-path=SCRIPTDIR/lib |
23 | 23 | source "${BASH_IT}/lib/log.bash"
|
24 | 24 |
|
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 |
| - |
39 | 25 | # libraries, but skip appearance (themes) for now
|
40 | 26 | _log_debug "Loading libraries(except appearance)..."
|
41 |
| -LIB="${BASH_IT}/lib/*.bash" |
42 | 27 | 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: " |
52 | 35 | done
|
53 | 36 |
|
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: " |
64 | 43 | done
|
65 | 44 |
|
66 | 45 | # 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}'." |
69 | 49 | BASH_IT_LOG_PREFIX="themes: githelpers: "
|
70 |
| - # shellcheck source=./themes/githelpers.theme.bash |
71 | 50 | source "${BASH_IT}/themes/githelpers.theme.bash"
|
72 | 51 | BASH_IT_LOG_PREFIX="themes: p4helpers: "
|
73 |
| - # shellcheck source=./themes/p4helpers.theme.bash |
74 | 52 | source "${BASH_IT}/themes/p4helpers.theme.bash"
|
75 | 53 | BASH_IT_LOG_PREFIX="themes: command_duration: "
|
76 |
| - # shellcheck source=./themes/command_duration.theme.bash |
77 | 54 | source "${BASH_IT}/themes/command_duration.theme.bash"
|
78 | 55 | BASH_IT_LOG_PREFIX="themes: base: "
|
79 |
| - # shellcheck source=./themes/base.theme.bash |
80 | 56 | source "${BASH_IT}/themes/base.theme.bash"
|
81 | 57 |
|
82 | 58 | BASH_IT_LOG_PREFIX="lib: appearance: "
|
83 | 59 | # appearance (themes) now, after all dependencies
|
84 |
| - # shellcheck source=./lib/appearance.bash |
| 60 | + # shellcheck source=SCRIPTDIR/lib/appearance.bash |
85 | 61 | source "$APPEARANCE_LIB"
|
| 62 | + BASH_IT_LOG_PREFIX="core: main: " |
86 | 63 | fi
|
87 | 64 |
|
88 |
| -BASH_IT_LOG_PREFIX="core: main: " |
89 | 65 | _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}" |
93 | 70 | _log_debug "Loading component..."
|
94 | 71 | # shellcheck disable=SC1090
|
95 |
| - source "${BASH_IT}/${file_type}/custom.${file_type}.bash" |
| 72 | + source "${_bash_it_main_file_custom}" |
96 | 73 | fi
|
| 74 | + BASH_IT_LOG_PREFIX="core: main: " |
97 | 75 | done
|
98 | 76 |
|
99 | 77 | # Custom
|
100 |
| -BASH_IT_LOG_PREFIX="core: main: " |
101 | 78 | _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}" |
109 | 82 | _log_debug "Loading custom file..."
|
110 | 83 | # shellcheck disable=SC1090
|
111 |
| - source "$_bash_it_config_file" |
| 84 | + source "$_bash_it_main_file_custom" |
112 | 85 | fi
|
| 86 | + BASH_IT_LOG_PREFIX="core: main: " |
113 | 87 | done
|
114 | 88 |
|
115 |
| -unset _bash_it_config_file |
116 | 89 | if [[ -n "${PROMPT:-}" ]]; then
|
117 |
| - export PS1="\[""$PROMPT""\]" |
| 90 | + PS1="${PROMPT}" |
118 | 91 | fi
|
119 | 92 |
|
120 | 93 | # Adding Support for other OSes
|
121 |
| -PREVIEW="less" |
122 |
| - |
123 |
| -if [ -s /usr/bin/gloobus-preview ]; then |
| 94 | +if _command_exists gloobus-preview; then |
124 | 95 | PREVIEW="gloobus-preview"
|
125 |
| -elif [ -s /Applications/Preview.app ]; then |
126 |
| - # shellcheck disable=SC2034 |
| 96 | +elif [[ -d /Applications/Preview.app ]]; then |
127 | 97 | PREVIEW="/Applications/Preview.app"
|
| 98 | +else |
| 99 | + PREVIEW="less" |
128 | 100 | fi
|
129 | 101 |
|
130 | 102 | # 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?}'" |
140 | 106 | fi
|
141 | 107 |
|
142 | 108 | for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
|
143 | 109 | eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
|
144 | 110 | done
|
145 |
| -unset "${!_bash_it_library_finalize_@}" |
| 111 | +unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}" |
0 commit comments