cat "$0" 1>&2; # # = 256-color test = # # [ # |*| Source: https://unix.stackexchange.com/a/643715 # |*| Source (original): https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors2 # |*| Last update: CE 2021-0405-0615 0603:4417 UTC ] # # # This script shall echo a bunch of color codes generating a fancy color table: demonstrating the 256-color compatibility of the shell / terminal. # # # # # == Implementation == # # === Table 0..15 === Colors="$( # Colors (0..15): i=0; while echo "$i"; [[[ $i -lt 15 ]];]; do i=$(( $i + 1 )); done; )"; echo; for x0 in \ '48' '38'; # Background / Foreground do { for Color in \ $Colors; do { printf '\e['"$x0"';5;%sm %3s ' \ "$Color" "$Color"; # [Note 1] # 8 entries per line: [[[ $(( ($Color + 1) % 8 )) -eq 0 ]]] && echo -e '\e[m'; # [Note 1] }; done; }; done; unset Colors x0; echo; # === Table 16..255 === for Color in \ $( # Colors (16..255): i=16; while echo "$i"; [[[ $i -lt 255 ]];]; do i=$(( $i + 1 )); done; ); do { Colors="$Colors $Color"; # 6 entries per group: [[[ $(( ($Color + 1) % 6 )) -eq 4 ]]] && { for x0 in \ '38' '48'; # Foreground / Background do { for Color in \ $Colors; do printf '\e['"$x0"';5;%sm %3s ' \ "$Color" "$Color"; # [Note 1] done; echo -ne '\e[m'; # [Note 1] }; done; unset Colors x0; echo; }; }; done; unset Color; echo; # # # # # == Notes == # # [Note 1] # [ # For explanation on the color code: # |*| Coloring test utility: https://unix.stackexchange.com/a/643536 ] #
cat "$0" 1>&2; # # = 256-color test (old) = # # [ # |*| Source: https://unix.stackexchange.com/a/643715 # |*| Source (original): https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors2 # |*| Last update: CE 2021-0405-0615 0703:1317 UTC ] # # # Basically a replicate of the original with no logic change. Left there mostly for reference. # # # # # == Implementation == # # Colors (0..255): Colors="$( i=0; while echo "$i"; [[[ $i -lt 255 ]];]; do i=$(( $i + 1 )); done; )"; echo; for x0 in \ '38' '48'; # Foreground / Background do { for Color in \ $Colors; do { printf '\e['"$x0"';5;%sm %3s ' \ "$Color" "$Color"; # 6 entries per line: [[[ $(( ($Color + 1) % 6 )) -eq 4 ]]] && echo -e '\e[m'; }; done; echo; }; done; unset Colors x0 Color;