Last active
August 29, 2015 14:05
-
-
Save phalkunz/e43a2f68b400ba3eca78 to your computer and use it in GitHub Desktop.
Echo string in color based on `--type`
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
### | |
# | |
# Echo string in color based on `--type`. | |
# Read `colorEcho()` funncton for more info on type. | |
# | |
# AUTHOR: | |
# | |
# Saophalkun Ponlu (phalkunz@gmail.com) | |
# | |
### | |
### | |
# | |
# Print string in color. It takes two arguments: message and message type, | |
# where the message type can be one of the following: | |
# | |
# - 'success' | |
# - 'warning' | |
# - 'error' | |
# - If it doesn't match any of the above, default text color is used | |
# | |
### | |
colorEcho() { | |
CECHO_COLOR_RESET="\033[0m" | |
CECHO_COLOR_ERROR="\033[31m" | |
CECHO_COLOR_WARNING="\033[33m" | |
CECHO_COLOR_SUCCESS="\033[32m" | |
case "$2" in | |
success) | |
CECHO_COLOR=$CECHO_COLOR_SUCCESS;; | |
warning) | |
CECHO_COLOR=$CECHO_COLOR_WARNING;; | |
error) | |
CECHO_COLOR=$CECHO_COLOR_ERROR;; | |
esac | |
echo ${CECHO_COLOR}"${1}"${CECHO_COLOR_RESET} | |
} | |
### | |
# Starting point | |
## | |
TYPE="" | |
if [[ $1 = --type=* ]]; then | |
# Delete everything up to "=" | |
# on the first argument | |
TYPE=${1#*=} | |
shift | |
MESSAGE=$* | |
else | |
TYPE="" | |
MESSAGE=$* | |
fi | |
colorEcho "$MESSAGE" "$TYPE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment