From 64066d0172a8c42c0db819ff56d53c0ba1caa518 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Thu, 4 May 2023 14:38:30 -0500 Subject: [PATCH] Added unhappy_ending to happy wrappy Now happy prints the command line that failed before exiting! --- errhandl.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/errhandl.bash b/errhandl.bash index 816b432..3e4d18b 100644 --- a/errhandl.bash +++ b/errhandl.bash @@ -1,2 +1,7 @@ # Don't want subsequent commands to run after nonzero exit? Wrappy in happy! -happy() { $@ || exit $?; } +unhappy_ending() { + stat=$1; shift + (echo "Error while running: \"$@\"" >&2) + exit $stat +} +happy() { $@ || unhappy_ending $? $@; }