A couple of alias to remind me how to change colors in bash or zsh
in ~/.bashrc or ~/.zshrc
alias colors='for ((i=30;i<=37;i++));do echo -e "\033[0;"$i"m echo -e \"\\\033[0;"$i"m"\";done;echo -e "\033[0;m echo -e \"\\\033[0;m\""'
alias declare_clr='\
echo "declare -A clr";
for a in 30m/black 31m/red 32m/green 33m/yellow 34m/purple 35m/magenta 36m/cyan 37m/white m/reset; do \
echo -e "\033[0;$(dirname $a)clr[$(basename $a)]=\"\\\033[0;$(dirname $a)\"\033[;m"; \
done'
The output of the aliases is colored when run in a terminal.
$ colors
echo -e "\033[0;30m"
echo -e "\033[0;31m"
echo -e "\033[0;32m"
echo -e "\033[0;33m"
echo -e "\033[0;34m"
echo -e "\033[0;35m"
echo -e "\033[0;36m"
echo -e "\033[0;37m"
echo -e "\033[0;m"
The escape sequences can be cut and pasted into echo -e
arguments. For example: echo -e "\033[0;31mERROR\033[;m"
$ declare_clr
declare -A clr
clr[black]="\033[0;30m"
clr[red]="\033[0;31m"
clr[green]="\033[0;32m"
clr[yellow]="\033[0;33m"
clr[purple]="\033[0;34m"
clr[magenta]="\033[0;35m"
clr[cyan]="\033[0;36m"
clr[white]="\033[0;37m"
clr[reset]="\033[0;m"
The clr declarations can be cut and pasted to the top of a script and then used in echo -e
commands.
For example: echo -e "$clr[red]ERROR$clr[reset]"