aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-09-14 10:47:52 -0300
committerEuAndreh <eu@euandre.org>2023-09-14 10:47:52 -0300
commitb17ae4187f18f18b65003af5ed32d6c3d0a3212f (patch)
tree33306755e453cacadb3cfbfe2288790bb65ee787 /bin
parentetc/sh/rc: Remove $LEX environment variable (diff)
downloaddotfiles-b17ae4187f18f18b65003af5ed32d6c3d0a3212f.tar.gz
dotfiles-b17ae4187f18f18b65003af5ed32d6c3d0a3212f.tar.xz
bin/muffle: Re-interleave STDOUT and STDERR on error
Diffstat (limited to 'bin')
-rwxr-xr-xbin/muffle24
1 files changed, 19 insertions, 5 deletions
diff --git a/bin/muffle b/bin/muffle
index 73c9103..6f93306 100755
--- a/bin/muffle
+++ b/bin/muffle
@@ -67,13 +67,27 @@ shift $((OPTIND - 1))
OUT="$(mkstemp)"
ERR="$(mkstemp)"
-trap 'rm -f "$OUT" "$ERR"' EXIT
+STATUS_F="$(mkstemp)"
+trap 'rm -f "$OUT" "$ERR" "$STATUS_F"' EXIT
-STATUS=0
-"$@" 1>"$OUT" 2>"$ERR" || STATUS=$?
+timed() {
+ ts -s -m '%.s'
+}
+
+echo 0 > "$STATUS_F"
+{
+ { "$@" || echo $? > "$STATUS_F"; } | timed | pre out > "$OUT"
+} 2>&1 | timed | pre err > "$ERR"
+STATUS="$(cat "$STATUS_F")"
if [ "$STATUS" != 0 ]; then
- cat "$OUT"
- cat "$ERR" >&2
+ cat "$OUT" "$ERR" |
+ sort -k2 | while read -r line; do
+ if [ "$(echo "$line" | cut -d' ' -f1)" = 'out:' ]; then
+ echo "$line" | cut -d' ' -f3- >&1
+ else
+ echo "$line" | cut -d' ' -f3- >&2
+ fi
+ done
exit "$STATUS"
fi