Last active
June 8, 2024 16:22
-
-
Save razielanarki/00cec867340bb6540f15a3c71ce504e2 to your computer and use it in GitHub Desktop.
BASH: dead simple syntax highlighting for docker compose config yaml output
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
#!/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