mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-06-19 22:33:43 +00:00
Allow disabling colors via NO_COLOR
environment variable
This commit is contained in:
3
main.sh
3
main.sh
@ -39,6 +39,7 @@ set -o pipefail
|
||||
|
||||
# Environment variables and their defaults
|
||||
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
|
||||
NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected
|
||||
|
||||
# Commandline options. This defines the usage page, and is used to parse cli
|
||||
# opts & defaults from. The parsing is unforgiving so be precise in your syntax
|
||||
@ -80,7 +81,7 @@ function _fmt () {
|
||||
|
||||
local color="${!colorvar:-$color_error}"
|
||||
local color_reset="\x1b[0m"
|
||||
if [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then
|
||||
if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then
|
||||
# Don't use colors on pipes or non-recognized terminals
|
||||
color=""; color_reset=""
|
||||
fi
|
||||
|
Reference in New Issue
Block a user