Skip to content

Commit 8064685

Browse files
committed
improve enable_auto_colors in colors library
1 parent efb5ad8 commit 8064685

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

examples/colors/src/lib/colors.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
1616
##
1717
enable_auto_colors() {
18-
[[ -z ${NO_COLOR+x} && ! -t 1 ]] && NO_COLOR=1 || true
18+
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
19+
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
20+
NO_COLOR=1
21+
fi
1922
}
2023

2124
print_in_color() {

examples/dependencies-alt/src/lib/colors.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
1616
##
1717
enable_auto_colors() {
18-
[[ -z ${NO_COLOR+x} && ! -t 1 ]] && NO_COLOR=1 || true
18+
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
19+
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
20+
NO_COLOR=1
21+
fi
1922
}
2023

2124
print_in_color() {

examples/dependencies/src/lib/colors.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
1616
##
1717
enable_auto_colors() {
18-
[[ -z ${NO_COLOR+x} && ! -t 1 ]] && NO_COLOR=1 || true
18+
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
19+
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
20+
NO_COLOR=1
21+
fi
1922
}
2023

2124
print_in_color() {

lib/bashly/libraries/colors/colors.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
1616
##
1717
enable_auto_colors() {
18-
[[ -z ${NO_COLOR+x} && ! -t 1 ]] && NO_COLOR=1 || true
18+
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
19+
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
20+
NO_COLOR=1
21+
fi
1922
}
2023

2124
print_in_color() {

0 commit comments

Comments
 (0)