From 2433700a31b293e22059e65d7526698591615543 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 1 Oct 2020 19:23:47 -0700 Subject: [PATCH] shlib.sh: provide overrideable bang_exit function When `bang_setup` is called, it sets a trap on EXIT. This will step on any previously set trap on EXIT. Make the EXIT trap set by `bang_setup` call a new `bang_exit` function as its last action. Provide a placeholder `bang_exit` function that does nothing. This way the `bang_exit` function can be replaced before calling `bang_setup` thereby avoiding loss of any needed EXIT trap activity as a result of the EXIT trap set by `bang_setup`. Signed-off-by: Kyle J. McKay --- shlib.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shlib.sh b/shlib.sh index 0ab1ff2..9b42dd6 100644 --- a/shlib.sh +++ b/shlib.sh @@ -568,6 +568,14 @@ bang_eval() { bang eval "$*" } +bang_exit() { + # placeholder empty function that get called + # when the bang_setup EXIT trap triggers + # can be replaced to avoid losing a pre bang_setup + # trap on EXIT + : +} + # Default bang settings: bang_setup() { bang_active= @@ -580,7 +588,7 @@ bang_setup() { echo "bang_setup called with current directory not a git directory" >&2 exit 1 } - trap 'rm -f "$bang_log"' EXIT + trap 'rm -f "$bang_log"; bang_exit' EXIT trap '[ -z "$bang_active" ] || { bang_errcode=130; bang_failed; }; exit 130' INT trap '[ -z "$bang_active" ] || { bang_errcode=143; bang_failed; }; exit 143' TERM } -- 2.11.4.GIT