Skip to content

Commit f0ea9b6

Browse files
committed
code simplification
1 parent f77610f commit f0ea9b6

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

usr/libexec/helper-scripts/get_colors.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,39 @@
1414

1515
# shellcheck disable=SC2034
1616
get_colors() {
17+
local color_yes_or_no
18+
1719
get_colors_sourced=1
1820

1921
draw="" ## Intentionally not implemented, see below
2022

21-
if test -n "${NO_COLOR:-}" || test -n "${ANSI_COLORS_DISABLED:-}" || \
22-
test -z "${TERM:-}" || test "${TERM:-}" = "dumb" || test "${TERM:-}" = "unknown" || \
23-
! test -t 2 || ! test "${ASSUME_TERM_PRESENT-}" = 'true'; then
23+
if test -n "${NO_COLOR:-}"; then
24+
color_yes_or_no=no
25+
fi
26+
if test -n "${ANSI_COLORS_DISABLED:-}"; then
27+
color_yes_or_no=no
28+
fi
29+
if test -z "${TERM:-}"; then
30+
color_yes_or_no=no
31+
fi
32+
if test "${TERM:-}" = "dumb"; then
33+
color_yes_or_no=no
34+
fi
35+
if test "${TERM:-}" = "unknown"; then
36+
color_yes_or_no=no
37+
fi
38+
if ! test -t 2; then
39+
color_yes_or_no=no
40+
fi
41+
42+
## TODO: Rename to 'COLOR_FORCE_YES=true'?
43+
if test "${ASSUME_TERM_PRESENT-}" = 'true'; then
44+
color_yes_or_no=yes
45+
fi
46+
47+
[[ -v color_yes_or_no ]] || color_yes_or_no="yes"
48+
49+
if test "${color_yes_or_no}" = "no"; then
2450
nocolor=""; reset=""
2551
bold=""; nobold=""
2652
underline=""; nounderline=""

0 commit comments

Comments
 (0)