Skip to content

Commit 10b41c5

Browse files
committed
Return immediately when not run in Bash
- Return with an exit code of 1 when run in any shell other than Bash. Should prevent any functions or variables from being defined. This check was previously run later during initialization. - Updated test case for this - Should address #113
1 parent 7884535 commit 10b41c5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

bash-preexec.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. If you override
3333
# either of these after bash-preexec has been installed it will most likely break.
3434

35+
# Make sure this is bash that's running and return otherwise.
36+
if [[ -z "${BASH_VERSION:-}" ]]; then
37+
return 1;
38+
fi
39+
3540
# Avoid duplicate inclusion
3641
if [[ "${__bp_imported:-}" == "defined" ]]; then
3742
return 0
@@ -318,11 +323,6 @@ __bp_install() {
318323
# after our session has started. This allows bash-preexec to be included
319324
# at any point in our bash profile.
320325
__bp_install_after_session_init() {
321-
# Make sure this is bash that's running this and return otherwise.
322-
if [[ -z "${BASH_VERSION:-}" ]]; then
323-
return 1;
324-
fi
325-
326326
# bash-preexec needs to modify these variables in order to work correctly
327327
# if it can't, just stop the installation
328328
__bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return

test/bash-preexec.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ test_preexec_echo() {
2121
printf "%s\n" "$1"
2222
}
2323

24-
@test "__bp_install_after_session_init should exit with 1 if we're not using bash" {
24+
@test "sourcing bash-preexec should exit with 1 if we're not using bash" {
2525
unset BASH_VERSION
26-
run '__bp_install_after_session_init'
26+
run source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"
2727
[ $status -eq 1 ]
2828
[ -z "$output" ]
2929
}

0 commit comments

Comments
 (0)