shell日志颜色处理

记录一下shell日志颜色处理

_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)}
__detect_color_support() {
    # shellcheck disable=SC2181
    if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then
        RC='\033[1;31m'
        GC='\033[1;32m'
        BC='\033[1;34m'
        YC='\033[1;33m'
        EC='\033[0m'
    else
        RC=""
        GC=""
        BC=""
        YC=""
        EC=""
    fi
}
__detect_color_support
echoerror() {
    printf "${RC} * ERROR${EC}: %s\\n" "$@" 1>&2;
}
echoinfo() {
    printf "${GC} *  INFO${EC}: %s\\n" "$@";
}
echowarn() {
    printf "${YC} *  WARN${EC}: %s\\n" "$@";
}

 

posted @ 2018-09-27 15:41  流年有爱,岁月静好  阅读(911)  评论(0编辑  收藏  举报