Skip to content

Instantly share code, notes, and snippets.

@joshbode
Last active January 5, 2023 00:42
Show Gist options
  • Save joshbode/e3bf05fd3e1b242da8fb473e3fcb64ce to your computer and use it in GitHub Desktop.
Save joshbode/e3bf05fd3e1b242da8fb473e3fcb64ce to your computer and use it in GitHub Desktop.
Split Logging Output using `splitvt`

Split logging output using splitvt

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
#! /bin/bash
. logging.sh
set -e
_ "Step 1" \
./test.sh A 10
_ "Step 2" \
./test.sh B 10
_ "Step 3" \
./test.sh C 5
#! /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