Last active
October 20, 2024 21:39
-
-
Save hylophile/18a2b8894775da2a87bc2879d804c5b4 to your computer and use it in GitHub Desktop.
Color-coded prefixed logging of long-running commands with Just (similar to `docker compose logs`)
This file contains hidden or 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
| [positional-arguments] | |
| parallog +args: | |
| #!/usr/bin/env bash | |
| trap "kill 0" EXIT SIGINT SIGTERM | |
| align=$((1 + `printf "%s\n" "$@" | wc -L`)) | |
| while (("$#")); do | |
| color=$((31 + ("$#" % 6))) | |
| prefix=`printf "\033[${color};m%+${align}s\033[0m" "$1"` | |
| FORCE_COLOR=1 just $1 2>&1 | sed "s/^/${prefix} │ /;" & | |
| shift | |
| done | |
| wait -n | |
| bar seconds: | |
| while true; do sleep {{seconds}} && date; done | |
| foo: | |
| while true; do sleep $(($RANDOM % 3)) && date; done | |
| baz: | |
| while true; do sleep $(($RANDOM % 3)) && date; done | |
| example: | |
| just parallog foo "bar 1" baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment