From fbdeac485820ba1dc1f522f70f9a897d0eaae7dd Mon Sep 17 00:00:00 2001 From: jim winstead Date: Tue, 23 Jan 2024 12:26:02 -0800 Subject: [PATCH] Don't load if old version already present (Fixes rcaloras/bash-preexec#146) --- bash-preexec.sh | 2 +- test/include-test.bats | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 6f26569..5bb11b6 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -48,7 +48,7 @@ if [[ -z "${BASH_VERSINFO-}" ]] || (( BASH_VERSINFO[0] < 3 || (BASH_VERSINFO[0] fi # Avoid duplicate inclusion -if [[ -n "${bash_preexec_imported:-}" ]]; then +if [[ -n "${bash_preexec_imported:-}" || -n "${__bp_imported:-}" ]]; then return 0 fi bash_preexec_imported="defined" diff --git a/test/include-test.bats b/test/include-test.bats index 73797ac..36a5f25 100644 --- a/test/include-test.bats +++ b/test/include-test.bats @@ -6,6 +6,12 @@ [ -z $(type -t __bp_install) ] } +@test "should not import if it's already defined (old guard, don't use elsewhere!)" { + __bp_imported="defined" + source "${BATS_TEST_DIRNAME}/../bash-preexec.sh" + [ -z $(type -t __bp_install) ] +} + @test "should import if not defined" { unset bash_preexec_imported source "${BATS_TEST_DIRNAME}/../bash-preexec.sh"