-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib-color.sh
More file actions
36 lines (27 loc) · 764 Bytes
/
lib-color.sh
File metadata and controls
36 lines (27 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/false
LIB_COLOR_STATUS='loading'
: ${NARGS:=0}
: ${COLOR:=auto}
declare -a VERBOSE_OPTIONS
# Ruler: ' -<option> Explanation'
VERBOSE_OPTIONS[${#VERBOSE_OPTIONS}]=' --color <color-mode> Where <color-mode> is either auto, yes, or no'
if [ ".$1" = '.--color' ]
then
COLOR="$2"
shift 2
NARGS=$((${NARGS} + 2))
fi
log "COLOR=[${COLOR}]"
if [[ ".${COLOR}" = ".auto" ]] && [[ -t 1 ]]
then
COLOR='yes'
fi
function stderr-color() {
if [[ ".${COLOR}" = ".yes" ]]
then
exec 2> >("${BIN}/color.sh" >&2)
sleep .1 # prevent race condition (https://stackoverflow.com/questions/30687504/redirected-output-hangs-when-using-tee)
fi
}
stderr-color
LIB_COLOR_STATUS='loaded'