Skip to content

Instantly share code, notes, and snippets.

@razielanarki
Last active June 8, 2024 16:22
Show Gist options
  • Save razielanarki/00cec867340bb6540f15a3c71ce504e2 to your computer and use it in GitHub Desktop.
Save razielanarki/00cec867340bb6540f15a3c71ce504e2 to your computer and use it in GitHub Desktop.
BASH: dead simple syntax highlighting for docker compose config yaml output
#!/usr/bin/env bash
#============================================================================
# dead simple syntax highlighting for docker compose config yaml output
#----------------------------------------------------------------------------
function ansi::sgr { echo -n $'\033'"[$(IFS=';'; echo "$*")m"; }
function ansi::str { while (( $# > 1 )); do ansi::sgr $1; echo -n "$2";shift 2; done; ansi::sgr; }
#----------------------------------------------------------------------------
docker compose config | sed -nr \
"s/^(\s*)(-\s*)?(\S+)(:[| {}]*)(([^\"]*)|\"(([-0-9]+)|(.+))\")$/\1$(
ansi::str 90 '\2' '38;5;172' '\3' 90 '\4' \
32 '\6' 36 '\8' 94 '\9/;s/^(.*)$/' 37 '\1'
)/p"
#----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment