Skip to content

Instantly share code, notes, and snippets.

@allen0099
Created March 3, 2023 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allen0099/ae565411755468fbeda6e451cb18d495 to your computer and use it in GitHub Desktop.
Save allen0099/ae565411755468fbeda6e451cb18d495 to your computer and use it in GitHub Desktop.
Testing color scripts
#!/usr/bin/env bash
# Source: https://misc.flogisoft.com/bash/tip_colors_and_formatting
set -e
echo "=== 16 colors ==="
# Background
for clbg in {40..47} 49 {100..107}; do
# Foreground
for clfg in {30..38} 39 {90..97}; do
# Formatting
for attr in {0..8}; do
# Print the result
echo -en "\e[${attr};${clbg};${clfg}m \\\e[${attr};${clbg};${clfg}m \e[0m"
done
echo #Newline
done
done
echo "=== 256 colors ==="
for fgbg in 38 48; do # Foreground / Background
for color in {0..255}; do # Colors
# Display the color
printf "\e[${fgbg};5;${color}m \\\e[${fgbg};5;%3sm \e[0m" "$color"
# Display 6 colors per lines
if [ $(((color + 1) % 6)) == 4 ]; then
echo # New line
fi
done
echo # New line
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment