mirror of
https://github.com/rcaloras/bash-preexec.git
synced 2026-11-03 22:49:41 -09:00
Remove the underscore prefix of __bp_imported (#123)
* Remove the underscore prefix of "__bp_imported"
This formally exposes it as part of the public API.
* Fix Bats test after renaming the variable
* Rename the variable upon reviewer request
* Fix inconsistency after renaming variables
Variables were reanmed in 7fbc07fb4e, but
it didn’t cover the test or ReadMe. This commit fixes that.
This commit is contained in:
parent
3e563be4f1
commit
fd2ffa8876
3 changed files with 17 additions and 4 deletions
|
|
@ -91,6 +91,15 @@ export __bp_enable_subshells="true"
|
|||
```
|
||||
This is disabled by default due to buggy situations related to to `functrace` and Bash's `DEBUG trap`. See [Issue #25](https://github.com/rcaloras/bash-preexec/issues/25)
|
||||
|
||||
## Library authors
|
||||
If you want to detect bash-preexec in your library (for example, to add hooks to `preexec_functions` when available), use the Bash variable `bash_preexec_imported`:
|
||||
|
||||
```bash
|
||||
if [[ -n "${bash_preexec_imported:-}" ]]; then
|
||||
echo "Bash-preexec is loaded."
|
||||
fi
|
||||
```
|
||||
|
||||
## Tests
|
||||
You can run tests using [Bats](https://github.com/bats-core/bats-core).
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -38,10 +38,14 @@ if [[ -z "${BASH_VERSION:-}" ]]; then
|
|||
fi
|
||||
|
||||
# Avoid duplicate inclusion
|
||||
if [[ "${__bp_imported:-}" == "defined" ]]; then
|
||||
if [[ -n "${bash_preexec_imported:-}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
__bp_imported="defined"
|
||||
bash_preexec_imported="defined"
|
||||
|
||||
# WARNING: This variable is no longer used and should not be relied upon.
|
||||
# Use ${bash_preexec_imported} instead.
|
||||
__bp_imported="${bash_preexec_imported}"
|
||||
|
||||
# Should be available to each precmd and preexec
|
||||
# functions, should they want it. $? and $_ are available as $? and $_, but
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
@test "should not import if it's already defined" {
|
||||
__bp_imported="defined"
|
||||
bash_preexec_imported="defined"
|
||||
source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"
|
||||
[ -z $(type -t __bp_install) ]
|
||||
}
|
||||
|
||||
@test "should import if not defined" {
|
||||
unset __bp_imported
|
||||
unset bash_preexec_imported
|
||||
source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"
|
||||
[ -n $(type -t __bp_install) ]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue