Skip to content

Commit fd35094

Browse files
authored
Merge pull request #2004 from gaelicWizard/finalize
Create lib finalize hook
2 parents 8d5d907 + dc45958 commit fd35094

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

bash_it.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ fi
1515
# shellcheck disable=SC1090
1616
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
1717

18-
# We need to load logging module first as well in order to be able to log
19-
# shellcheck source=./lib/log.bash
18+
# Declare our end-of-main finishing hook
19+
declare -a _bash_it_library_finalize_hook
20+
21+
# We need to load logging module early in order to be able to log
22+
# shellcheck source-path=SCRIPTDIR/lib
2023
source "${BASH_IT}/lib/log.bash"
2124

2225
# We can only log it now
@@ -148,3 +151,8 @@ if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
148151
;;
149152
esac
150153
fi
154+
155+
for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
156+
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
157+
done
158+
unset "${!_bash_it_library_finalize_@}"

docs/development.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ Plugin Disable Callbacks
147147
Plugins can define a function that will be called when the plugin is being disabled.
148148
The callback name should be ``{PLUGIN_NAME}_on_disable``\ , you can see ``gitstatus`` for usage example.
149149

150+
Library Finalization Callback
151+
-----------------------------
152+
153+
Specifically for Bash-it library code, e.g. in the `lib` subdirectory, a hook is available to run some code at the very end of the main loader script after all other code has been loaded. For example, `lib/theme` uses `_bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init')` to add a function to be called after all plugins have been loaded.
154+
150155
Using the pre-commit hook
151156
-------------------------
152157

themes/base.theme.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function _bash_it_appearance_scm_init() {
106106
fi
107107
fi
108108
}
109-
_bash_it_appearance_scm_init
109+
_bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init')
110110

111111
function scm {
112112
if [[ "$SCM_CHECK" = false ]]; then

0 commit comments

Comments
 (0)