Last active
September 21, 2017 03:04
-
-
Save rkaneko/013635451aaed684608b6c9bec258b56 to your computer and use it in GitHub Desktop.
Print with colors utilities on bash.
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
#!/bin/bash -eu | |
exist_arg1() { | |
local EXIST_ARG1=false | |
if [ "$1" ]; then | |
local EXIST_ARG1=true | |
fi | |
echo ${EXIST_ARG1} | |
} | |
printColor() { | |
local TEXT="$1" | |
local COLOR="$2" | |
local NO_COLOR="\033[0m" | |
if [ $(exist_arg1 ${TEXT}) = "true" ] && [ $(exist_arg1 ${COLOR}) = "true" ]; then | |
echo -en ${COLOR} | |
cat <<__EOT__ | |
${TEXT} | |
__EOT__ | |
echo -en ${NO_COLOR} | |
# printf "${COLOR}${TEXT}${NO_COLOR}\n" | |
fi | |
} | |
printError() { | |
local RED="\033[0;31m" | |
local TEXT="$1" | |
printColor "${TEXT}" ${RED} | |
} | |
printInfo() { | |
local GREEN="\033[0;32m" | |
local TEXT="$1" | |
printColor "${TEXT}" ${GREEN} | |
} | |
printWarn() { | |
local BROWN="\033[0;33m" | |
local TEXT="$1" | |
printColor "${TEXT}" ${BROWN} | |
} | |
printDebug() { | |
local BLUE="\033[0;34m" | |
local TEXT="$1" | |
printColor "${TEXT}" ${BLUE} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment