Skip to content

Instantly share code, notes, and snippets.

@dwoz
Created September 16, 2013 04:18
Show Gist options
  • Save dwoz/6576655 to your computer and use it in GitHub Desktop.
Save dwoz/6576655 to your computer and use it in GitHub Desktop.
Output ascii colors
#!/bin/bash
#
# Modified from here:
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
#
color16()
{
#Foreground
for clfg in {30..37} {90..97} 39 ; do
attr=0; #Print the result
clbg=49;
echo -en "\e[${attr};${clbg};${clfg}m $(printf '%4s' $clfg) \e[0m"
done
echo
#Foreground
for clbg in {40..47} {100..107} 49; do
attr=0; #Print the result
clfg=40;
echo -en "\e[${clbg}m $(printf '%4s' $clbg) \e[0m"
done
echo
}
color256()
{
for fgbg in 38 48 ; do #Foreground/Background
for color in {0..256} ; do #Colors
#Display the color
echo -en "\e[${fgbg};5;${color}m ${color}\t\e[0m"
#Display 10 colors per lines
if [ $((($color + 1) % 10)) == 0 ] ; then
echo #New line
fi
done
echo #New line
done
return 0
}
DO256="no";
DO16="no";
SHOWHELP="no";
for i in "$@";do
case $i in
-256)
DO256="yes";
;;
-16)
DO16="yes";
;;
-h|--help)
SHOW_HELP="yes";
;;
esac
done
[[ "$DO16" == "yes" ]] && color16;
[[ "$DO256" == "yes" ]] && color256;
[[ "$DO256" == "no" && "$DO16" == "no" ]] && SHOW_HELP="yes";
if [[ "$SHOW_HELP" == "yes" ]]; then
echo "
Output ascii colors to the screen.
Usage:
color.sh [OPTIONS]
Options:
-16 (output ASCII 16-bit colors)
-256 (output ASCII 16-bit colors)
-h (output this help message)
"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment