Created
December 5, 2017 08:39
-
-
Save mkdym/8eb5fae6b16cc4f0e88e55a135990950 to your computer and use it in GitHub Desktop.
echo color functions
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/sh | |
# | |
# echo utils | |
# | |
echo_prefix="" | |
set_echo_prefix(){ | |
echo_prefix=$1 | |
} | |
echo_color(){ | |
local color=$1 | |
shift | |
case $color in | |
red) | |
echo -e "\e[0;31m${@}\e[0m" | |
;; | |
green) | |
echo -e "\e[0;32m${@}\e[0m" | |
;; | |
yellow) | |
echo -e "\e[0;33m${@}\e[0m" | |
;; | |
cyan) | |
echo -e "\e[0;36m${@}\e[0m" | |
;; | |
esac | |
} | |
echo_color_with_prefix(){ | |
local color=$1 | |
local msg=$2 | |
echo_color $color "$echo_prefix$msg" | |
} | |
echo_begin(){ | |
local msg=$1 | |
echo_color_with_prefix green ">>> ${msg}" | |
} | |
echo_end(){ | |
local msg=$1 | |
echo_color_with_prefix green "<<< ${msg}" | |
} | |
echo_info(){ | |
local msg=$1 | |
echo_color_with_prefix cyan "${msg}" | |
} | |
echo_warn(){ | |
local msg=$1 | |
echo_color_with_prefix yellow "${msg}" | |
} | |
echo_error(){ | |
local msg=$1 | |
echo_color_with_prefix red "${msg}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment