66 lines
1.2 KiB
Bash
66 lines
1.2 KiB
Bash
#/bin/bash
|
|
#
|
|
# message ()
|
|
# ----------
|
|
#
|
|
# External library to display colored messages
|
|
#
|
|
|
|
DEBUG=0
|
|
EXIT_ON_ERROR=0
|
|
ERROR_CODE=10
|
|
|
|
DATE_FORMAT=""
|
|
|
|
msg () {
|
|
declare -A attr
|
|
local c="default"
|
|
|
|
#foreground colors
|
|
attr[default]="\e[39m"
|
|
attr[red]="\e[31m"
|
|
attr[green]="\e[32m"
|
|
attr[yellow]="\e[33m"
|
|
attr[blue]="\e[34m"
|
|
attr[magenta]="\e[35m"
|
|
attr[cyan]="\e[36m"
|
|
|
|
#formatting
|
|
attr[reset]="\e[0m"
|
|
attr[bold]="\e[1m"
|
|
attr[r_bold]="\e[22m"
|
|
attr[underl]="\e[4m"
|
|
attr[r_underl]="\e[24m"
|
|
if [[ $1 =~ ^(red|green|yellow|blue|magenta|cyan)$ ]]
|
|
then
|
|
c=$1
|
|
shift
|
|
else
|
|
c="default"
|
|
fi
|
|
#printf "Select color %s with numero %s\n" $c ${attr[$c]}
|
|
#variables
|
|
local message=$(echo "$@" | sed -E "
|
|
s/\*\*([^\*\*]*)\*\*/\\${attr[bold]}\1\\${attr[r_bold]}/g;
|
|
s/__([^__]*)__/\\${attr[underl]}\1\\${attr[r_underl]}/g
|
|
")
|
|
printf "${attr[$c]}${message}${attr[reset]}"
|
|
}
|
|
|
|
error (){
|
|
msg "red" "ERROR : $@\n"
|
|
[[ $EXIT_ON_ERROR -eq 1 ]] && exit $ERROR_CODE
|
|
exit
|
|
}
|
|
|
|
warning () {
|
|
msg "yellow" "WARNING : $@\n"
|
|
}
|
|
|
|
debug(){
|
|
if [ $DEBUG -eq 1 ]
|
|
then
|
|
local message=$(echo "$@")
|
|
msg "cyan" "DEBUG : ${message}\n"
|
|
fi
|
|
}
|