Skip to content

Instantly share code, notes, and snippets.

@mekb-turtle
Last active April 17, 2023 04:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mekb-turtle/258044bd442253d829b724b59357696a to your computer and use it in GitHub Desktop.
Save mekb-turtle/258044bd442253d829b724b59357696a to your computer and use it in GitHub Desktop.
bash script to show terminal colors
#!/usr/bin/bash
if [[ "$TERM" == "linux" ]]; then
printf "%s" $'\x1b[48;5;0;38;5;15m 0 \x1b[48;5;1;38;5;15m 1 \x1b[48;5;2;38;5;15m 2 \x1b[48;5;3;38;5;15m 3 \x1b[48;5;4;38;5;15m 4 \x1b[48;5;5;38;5;15m 5 \x1b[48;5;6;38;5;15m 6 \x1b[48;5;7;38;5;15m 7 \x1b[0m\n'
printf "%s" $'\x1b[48;5;0;38;5;15m 8 \x1b[48;5;1;38;5;15m 9 \x1b[48;5;2;38;5;15m10 \x1b[48;5;3;38;5;15m11 \x1b[48;5;4;38;5;15m12 \x1b[48;5;5;38;5;15m13 \x1b[48;5;6;38;5;15m14 \x1b[48;5;7;38;5;15m15 \x1b[0m\n'
else
printf "%s" $'\x1b[48;5;0;38;5;255m 0 \x1b[48;5;1;38;5;255m 1 \x1b[48;5;2;38;5;255m 2 \x1b[48;5;3;38;5;255m 3 \x1b[48;5;4;38;5;255m 4 \x1b[48;5;5;38;5;255m 5 \x1b[48;5;6;38;5;255m 6 \x1b[48;5;7;38;5;16m 7 \x1b[0m\n'
printf "%s" $'\x1b[48;5;8;38;5;255m 8 \x1b[48;5;9;38;5;16m 9 \x1b[48;5;10;38;5;16m10 \x1b[48;5;11;38;5;16m11 \x1b[48;5;12;38;5;16m12 \x1b[48;5;13;38;5;16m13 \x1b[48;5;14;38;5;16m14 \x1b[48;5;15;38;5;16m15 \x1b[0m\n'
printf "%s" $'\n'
for m in {0..5}; do
for l in {0..5}; do
for k in {0..5}; do
i=$((${k}+(${m}*6)+16+(${l}*36)));
b=$(((${i}-16)%6)); g=$(((${i}-16)/6%6)); r=$(((${i}-16)/36));
z=255;
if [[ "$r" -ge 4 ]] || [[ "$g" -ge 4 ]]; then z=16; fi; if [[ "$g" -ge 3 ]] && [[ "$b" -ge 3 ]]; then z=16; fi; if [[ "$r" -ge 3 ]] && [[ "$g" -ge 2 ]]; then z=16; fi; if [[ "$r" -eq 3 ]] && [[ "$g" -le 2 ]] && [[ "$b" -le 2 ]]; then z=255; fi; if [[ "$r" -eq 4 ]] && [[ "$g" -eq 0 ]]; then z=255; fi;
I="$i ";
while [[ "${#I}" < 4 ]]; do I=" $I"; done;
printf "%s" $'\x1b'"[38;5;${z};48;5;${i}m${I}";
done
printf "%s" $'\x1b[0m '
done
printf "%s" $'\n'
done
printf "%s" $'\n'
for l in {232..255}; do true
z=255;
if [[ "$l" -ge 244 ]]; then z=16; fi
printf "%s" $'\x1b'"[38;5;${z};48;5;${l}m ${l} "
done
printf "%s" $'\n'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment