Skip to content

Commit 30e09cb

Browse files
committed
Do not enable it in non-interactive shells
1 parent 8926de0 commit 30e09cb

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

bash-preexec.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ if [[ -z "${BASH_VERSINFO-}" ]] || (( BASH_VERSINFO[0] < 3 || (BASH_VERSINFO[0]
4747
return 1
4848
fi
4949

50+
# We do not enable bash-preexc in non-interactive shells (except in tests)
51+
if [[ $- != *i* && ! ${__bp_inside_test-} ]]; then
52+
return 0
53+
fi
54+
5055
# Avoid duplicate inclusion
5156
if [[ -n "${bash_preexec_imported:-}" || -n "${__bp_imported:-}" ]]; then
5257
return 0

test/bash-preexec.bats

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

3+
# This variable tells bash-preexec.sh that it is loaded for the testing
4+
# purposes. bash-preexec.sh is intended to be used in interactive shell
5+
# sessions, so it is disabled in non-interactive shells by default. However,
6+
# it still needs to be loaded in non-interactive shells for the Bats tests,
7+
__bp_inside_test=yes
8+
39
setup() {
410
PROMPT_COMMAND='' # in case the invoking shell has set this
511
history -s fake command # preexec requires there be some history

test/include-test.bats

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

3+
# This variable tells bash-preexec.sh that it is loaded for the testing
4+
# purposes. bash-preexec.sh is intended to be used in interactive shell
5+
# sessions, so it is disabled in non-interactive shells by default. However,
6+
# it still needs to be loaded in non-interactive shells for the Bats tests,
7+
__bp_inside_test=yes
8+
39
@test "should not import if it's already defined" {
410
bash_preexec_imported="defined"
511
source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"

0 commit comments

Comments
 (0)