Created
January 16, 2015 16:18
-
-
Save matesnippets/fe4e2e60a88e2648b52e to your computer and use it in GitHub Desktop.
Bash, Color function
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
# Colors | |
color_echo() { | |
# Parameters | |
local message=$1 | |
local color=${2-'default'} | |
local attribute=${3-'none'} | |
# Other vars | |
local color_type='3' | |
local color_code='0' | |
# Colors | |
case $color in | |
black) color_code='0';; | |
red) color_code='1';; | |
green) color_code='2';; | |
yellow) color_code='3';; | |
blue) color_code='4';; | |
magenta) color_code='5';; | |
cyan) color_code='6';; | |
white) color_code='7';; | |
esac | |
# Font styles, bold, udnerline etc | |
case $attribute in | |
bold) attribute_code=';1';; | |
underline) attribute_code=';4';; | |
reverse) attribute_code=';7';; | |
background) attribute_code='0;1;4';; | |
esac | |
echo -en "\033[${color_type}${color_code}${attribute_code}m" | |
echo -en "$message" | |
echo -en "\033[0m\n" | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment