Created
September 14, 2011 15:23
-
-
Save ralfstx/1216858 to your computer and use it in GitHub Desktop.
Script that prints an overview of escape sequences for changing colors
This file contains 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
#!/bin/bash | |
# | |
# This script prints an overview of the escape sequences for changing the | |
# terminal text and background colors using escape sequences. | |
name030="Black " | |
name130="Gray " | |
name031="Red " | |
name131="Light Red " | |
name032="Green " | |
name132="Light Green" | |
name033="Brown " | |
name133="Yellow " | |
name034="Blue " | |
name134="Light Blue " | |
name035="Purple " | |
name135="Pink " | |
name036="Cyan " | |
name136="Light Cyan " | |
name037="Light Gray " | |
name137="White " | |
# OUTPUT TABLE | |
echo -e -n "\033[47;30m" | |
echo -n " Background: 40 41 42 43 44 45 46 47 " | |
echo -e "\033[0m" | |
for fg in 30 31 32 33 34 35 36 37 | |
do | |
for hl in 0 1 | |
do | |
eval name=\$name$hl$fg | |
test $hl -gt 0 && fg="1;$fg" | |
echo -e -n "\033[${fg}m $name \033[0m" | |
for bg in 40 41 42 43 44 45 46 47 | |
do | |
echo -e -n "\033[$bg;${fg}m" | |
test $hl -eq 0 && echo -n " " | |
echo -e -n " $fg \033[0m" | |
done | |
echo | |
done | |
done | |
echo | |
echo " Examples: Result:" | |
echo -n " foo \e[1mbar\e[0m baz " | |
echo -e " foo \e[1mbar\e[0m baz" | |
echo -n " foo \e[1;37;41mbar\e[0m baz " | |
echo -e " foo \e[1;37;41mbar\e[0m baz" | |
echo -n " \e[1;31;40mfoo \e[1;33mbar \e[1;32mbaz\e[0m " | |
echo -e " \e[1;31;40mfoo \e[1;33mbar \e[1;32mbaz\e[0m" | |
echo -e " \\\\e can also be written as \\\\033." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment