Created
January 23, 2015 17:17
-
-
Save elucify/c7ccfee9f13b42f11f81 to your computer and use it in GitHub Desktop.
BASH: set variables for ANSI text color escape sequences
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
RESTORE=$(echo -en '\033[0m') | |
RED=$(echo -en '\033[00;31m') | |
GREEN=$(echo -en '\033[00;32m') | |
YELLOW=$(echo -en '\033[00;33m') | |
BLUE=$(echo -en '\033[00;34m') | |
MAGENTA=$(echo -en '\033[00;35m') | |
PURPLE=$(echo -en '\033[00;35m') | |
CYAN=$(echo -en '\033[00;36m') | |
LIGHTGRAY=$(echo -en '\033[00;37m') | |
LRED=$(echo -en '\033[01;31m') | |
LGREEN=$(echo -en '\033[01;32m') | |
LYELLOW=$(echo -en '\033[01;33m') | |
LBLUE=$(echo -en '\033[01;34m') | |
LMAGENTA=$(echo -en '\033[01;35m') | |
LPURPLE=$(echo -en '\033[01;35m') | |
LCYAN=$(echo -en '\033[01;36m') | |
WHITE=$(echo -en '\033[01;37m') | |
# Test | |
echo ${RED}RED${GREEN}GREEN${YELLOW}YELLOW${BLUE}BLUE${PURPLE}PURPLE${CYAN}CYAN${WHITE}WHITE${RESTORE} |
Thanks @mathieu-aubin ... thats a great little utility.
I have created that as a gist, with some bashism tweaks
https://gist.github.com/codemedic/af013d32b4b7476d3108fc8309057970#file-bash-colors-sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, for what its worth, i have created a nice little function that shows the many different colors that can be used in the terminal and its available as part of a little centos7 base installation setup i created a while back.
The function code as of today is as follows:
and is available here: https://github.com/mathieu-aubin/c7repos/blob/master/functions/bash-colors
In order to add this function to your set of 'tools' you can either create a separate .bash_functions file that you later source from your main rc file or you can use this code:
Then source the ~/.bashrc file using
source ~/.bashrc
or opening another terminal. You will then have 'bash-colors' (and its derivates) available for your pleasure.Here's a little demo (thanks to asciinema - click on the pic to view)
The i have removed the \033[ from the output in the demo function to shorten the output the function remains the same.
Thanks