Skip to content

Instantly share code, notes, and snippets.

@rkaneko
Last active September 21, 2017 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkaneko/013635451aaed684608b6c9bec258b56 to your computer and use it in GitHub Desktop.
Save rkaneko/013635451aaed684608b6c9bec258b56 to your computer and use it in GitHub Desktop.
Print with colors utilities on bash.
#!/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