Created
July 27, 2013 23:34
-
-
Save spudtrooper/6096721 to your computer and use it in GitHub Desktop.
Echos the message in a color given by the first argument.
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
# Echos the message in a color given by the first argument. | |
# | |
# Example: | |
# | |
# % ccho red "This is red" | |
# | |
# Outputs "This is red" in red | |
# | |
# The following colors are supported | |
# red|r - RED | |
# green|g - GREEN | |
# yellow|y - YELLOW | |
# blue|b - BLUE | |
# purple|p - PURPLE | |
# cyan|c - CYAN | |
# white|w - WHITE; | |
# lgray|l - LIGHT GRAY | |
# lred|l - LIGHT RED | |
# lgreen|l - LIGHT GREEN | |
# lyellow|l - LIGHT YELLOW | |
# lblue|l - LIGHT BLUE | |
# lpurple|l - LIGHT PURPLE | |
# lcyan|l - LIGHT CYAN | |
# | |
function ccho() | |
{ | |
local RESTORE='\033[0m' | |
local RED='\033[00;31m' | |
local GREEN='\033[00;32m' | |
local YELLOW='\033[00;33m' | |
local BLUE='\033[00;34m' | |
local PURPLE='\033[00;35m' | |
local CYAN='\033[00;36m' | |
local LGRAY='\033[00;37m' | |
local LRED='\033[01;31m' | |
local LGREEN='\033[01;32m' | |
local LYELLOW='\033[01;33m' | |
local LBLUE='\033[01;34m' | |
local LPURPLE='\033[01;35m' | |
local LCYAN='\033[01;36m' | |
local WHITE='\033[01;37m' | |
color_arg=$1 | |
shift | |
if [[ x$color_arg = x ]]; then | |
echo "Usage $(basename $0) <color> <string>+" | |
return 1 | |
fi | |
color_arg_lowercase=$(echo $color_arg | tr '[:upper:]' '[:lower:]') | |
case $color_arg_lowercase in | |
red|r) color=$RED;; | |
green|g) color=$GREEN;; | |
yellow|y) color=$YELLOW;; | |
blue|b) color=$BLUE;; | |
purple|p) color=$PURPLE;; | |
cyan|c) color=$CYAN;; | |
white|w) color=$WHITE;; | |
lgray|lg) color=$LGRAY;; | |
lred|lr) color=$LRED;; | |
lgreen|lg) color=$LGREEN;; | |
lyellow|ly) color=$LYELLOW;; | |
lblue|lb) color=$LBLUE;; | |
lpurple|lp) color=$LPURPLE;; | |
lcyan|lc) color=$LCYAN;; | |
esac | |
if [[ x$color = x ]]; then | |
echo "Invalid color $color_arg" | |
return 2 | |
fi | |
echo -en "$color" | |
echo "$@" | |
echo -en $RESTORE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment