Last active
August 28, 2025 21:04
-
-
Save planetrocky/f49cc1791e0e16a5cac008528049af9c to your computer and use it in GitHub Desktop.
jq color palettes (JQ_COLORS)
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 | |
| # | |
| # shellcheck shell=bash | |
| # | |
| # https://gist.githubusercontent.com/planetrocky/f49cc1791e0e16a5cac008528049af9c/raw/jq_colors.sh | |
| show_usage() { | |
| echo "Usage: $0 [0-5] [--verbose|-v] [--print|--show|-p|-s]" >&2 | |
| echo " [0-5]: color palette 0-5 [default=1]" >&2 | |
| echo " --print, --show, -p, -sv: print palette example" >&2 | |
| echo " --verbose, -v: Enable verbose output" >&2 | |
| exit 1 | |
| } | |
| # Initialize variables | |
| VERBOSE=false | |
| PRINT=false | |
| PALETTE="1" | |
| CSI="\033[" | |
| ANSI_DEFAULT="${CSI}0m" | |
| # Parse arguments | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| [0-5]) | |
| PALETTE="$1" | |
| shift | |
| ;; | |
| --print|--show|-p|-s) | |
| PRINT=true | |
| shift | |
| ;; | |
| --verbose|-v) | |
| VERBOSE=true | |
| shift | |
| ;; | |
| -h|--help) | |
| show_usage | |
| ;; | |
| *) | |
| echo "Error: Unknown argument '$1'" >&2 | |
| show_usage | |
| ;; | |
| esac | |
| done | |
| if [[ -n "$PALETTE" ]]; then | |
| echo "seleceted color palette ${PALETTE}" | |
| fi | |
| # Execute the appropriate action | |
| case $PALETTE in | |
| 0) | |
| # JQ default | |
| export JQ_COLORS="0;90:0;39:0;39:0;39:0;32:1;39:1;39:1;34" | |
| ;; | |
| 1) | |
| # pastel colors | |
| export JQ_COLORS="38;2;255;173;173:38;2;255;214;165:38;2;253;255;182:38;2;202;255;191:38;2;155;246;255:38;2;160;196;255:38;2;189;178;255:38;2;255;198;255" | |
| ;; | |
| 2) | |
| # bright pastel colors | |
| export JQ_COLORS="38;2;255;173;173;1:38;2;255;214;165;1:38;2;253;255;182;1:38;2;202;255;191;1:38;2;155;246;255;1:38;2;160;196;255;1:38;2;189;178;255;1:38;2;255;198;255:1" | |
| ;; | |
| 3) | |
| export JQ_COLORS="38;2;147;161;161:38;2;130;170;255:38;2;152;195;121:38;2;229;192;123:38;2;198;120;221:38;2;86;182;194:38;2;224;108;117:38;2;171;178;191" | |
| ;; | |
| # 38;2;147;161;161 - Muted gray | |
| # 38;2;130;170;255 - Soft blue | |
| # 38;2;152;195;121 - Fresh green | |
| # 38;2;229;192;123 - Warm amber | |
| # 38;2;198;120;221 - Purple/magenta | |
| # 38;2;86;182;194 - Cyan/teal | |
| # 38;2;224;108;117 - Coral red | |
| # 38;2;171;178;191 - Light gray | |
| 4) | |
| # Alternative: Warmer palette | |
| export JQ_COLORS="38;2;156;163;175:38;2;96;165;250:38;2;34;197;94:38;2;251;191;36:38;2;168;85;247:38;2;20;184;166:38;2;239;68;68:38;2;209;213;219" | |
| ;; | |
| 5) | |
| # Alternative: High contrast palette | |
| export JQ_COLORS="38;2;107;114;126:38;2;116;199;236:38;2;163;190;140:38;2;235;203;139:38;2;180;142;173:38;2;136;192;208:38;2;191;97;106:38;2;217;224;238" | |
| ;; | |
| *) | |
| echo "Error: unknown color palette requested" >&2 | |
| esac | |
| if [[ "$PRINT" == "true" ]]; then | |
| JQ_COLORS_NAMES=( "null" "false" "true" "numbers" | |
| "strings" "arrays" "objects" "object keys" ) | |
| # split JQ_COLORS into an array:w | |
| IFS=: read -ra jqColors <<<"${JQ_COLORS}" | |
| if [[ "$VERBOSE" == "true" ]]; then | |
| echo "${jqColors[@]}" | |
| fi | |
| echo "" | |
| jq -nc '[null,false,true,42,{"a":"bc"}]' | |
| echo "" | |
| for ((i=0;i<8;i++)); do | |
| t="${CSI}${jqColors[i]}m" | |
| printf "%-14s" "${JQ_COLORS_NAMES[i]}:" | |
| echo -e "${t}Testing ▂▃▄▅▆▇█▉▊▋▌▍▎▏▔▕▐░▒▓███████████▓▒░${ANSI_DEFAULT}" | |
| done | |
| fi | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demonstration using Casdia Code font using block elements Unicode symbols:-