Skip to content

Commit fd2ffa8

Browse files
authored
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 7fbc07f, but it didn’t cover the test or ReadMe. This commit fixes that.
1 parent 3e563be commit fd2ffa8

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export __bp_enable_subshells="true"
9191
```
9292
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)
9393

94+
## Library authors
95+
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`:
96+
97+
```bash
98+
if [[ -n "${bash_preexec_imported:-}" ]]; then
99+
echo "Bash-preexec is loaded."
100+
fi
101+
```
102+
94103
## Tests
95104
You can run tests using [Bats](https://github.com/bats-core/bats-core).
96105
```bash

bash-preexec.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ if [[ -z "${BASH_VERSION:-}" ]]; then
3838
fi
3939

4040
# Avoid duplicate inclusion
41-
if [[ "${__bp_imported:-}" == "defined" ]]; then
41+
if [[ -n "${bash_preexec_imported:-}" ]]; then
4242
return 0
4343
fi
44-
__bp_imported="defined"
44+
bash_preexec_imported="defined"
45+
46+
# WARNING: This variable is no longer used and should not be relied upon.
47+
# Use ${bash_preexec_imported} instead.
48+
__bp_imported="${bash_preexec_imported}"
4549

4650
# Should be available to each precmd and preexec
4751
# functions, should they want it. $? and $_ are available as $? and $_, but

test/include-test.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bats
22

33
@test "should not import if it's already defined" {
4-
__bp_imported="defined"
4+
bash_preexec_imported="defined"
55
source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"
66
[ -z $(type -t __bp_install) ]
77
}
88

99
@test "should import if not defined" {
10-
unset __bp_imported
10+
unset bash_preexec_imported
1111
source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"
1212
[ -n $(type -t __bp_install) ]
1313
}

0 commit comments

Comments
 (0)