Split logging output using splitvt
Last active
January 5, 2023 00:42
-
-
Save joshbode/e3bf05fd3e1b242da8fb473e3fcb64ce to your computer and use it in GitHub Desktop.
Split Logging Output using `splitvt`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -t 1 ] && [ -x "$(which splitvt)" ]; then | |
STATUS_FILE="/tmp/$$.status" | |
echo 0 > "${STATUS_FILE}" | |
trap 'rm -f ${STATUS_FILE}' INT TERM EXIT | |
_() { | |
local MESSAGE=$1 STATUS | |
shift 1 | |
# workaround for splitvt eating command exit status | |
local COMMAND="trap 'echo 1 > ${STATUS_FILE}' INT TERM; "'"$@"'" || echo "'$?'" > ${STATUS_FILE}" | |
splitvt -fs 1 -upper "echo █ ${MESSAGE}" -- \ | |
sh -c "${COMMAND}" -- "$@" | |
read -r STATUS < "${STATUS_FILE}" | |
return "${STATUS}" | |
} | |
else | |
_() { | |
local MESSAGE=$1 STATUS | |
shift 1 | |
echo "█ Start: ${MESSAGE}" | |
"$@" | |
STATUS=$? | |
echo "█ End: ${MESSAGE}" | |
echo | |
return "${STATUS}" | |
} | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
. logging.sh | |
set -e | |
_ "Step 1" \ | |
./test.sh A 10 | |
_ "Step 2" \ | |
./test.sh B 10 | |
_ "Step 3" \ | |
./test.sh C 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
PREFIX="$1" | |
N="$2" | |
for I in $(seq "${N}"); do | |
echo "${PREFIX}: $I" | |
sleep 0.2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment