Skip to content

Instantly share code, notes, and snippets.

@hylophile
Last active October 20, 2024 21:39
Show Gist options
  • Select an option

  • Save hylophile/18a2b8894775da2a87bc2879d804c5b4 to your computer and use it in GitHub Desktop.

Select an option

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`)
[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