From 29977d50581569050a432d7c24aacba9905aaff8 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 20 Oct 2023 10:46:52 -0400 Subject: [PATCH] contrib/check-config: conditionally disable color output. Redirecting check-config.sh output to a file puts control character output into that file, which isn't helpful for reading. Disable colorized output if either 1. NO_COLOR environment is set to "1" 2. stdout is not a terminal. Signed-off-by: Scott Moser --- contrib/check-config.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/check-config.sh b/contrib/check-config.sh index 7f57c7bb39..b9cc6bf87d 100755 --- a/contrib/check-config.sh +++ b/contrib/check-config.sh @@ -25,6 +25,10 @@ if ! command -v zgrep > /dev/null 2>&1; then } fi +useColor=true +if [ "$NO_COLOR" = "1" ] || [ ! -t 1 ]; then + useColor=false +fi kernelVersion="$(uname -r)" kernelMajor="${kernelVersion%%.*}" kernelMinor="${kernelVersion#$kernelMajor.}" @@ -41,6 +45,10 @@ is_set_as_module() { } color() { + # if stdout is not a terminal, then don't do color codes. + if [ "$useColor" = "false" ]; then + return 0 + fi codes= if [ "$1" = 'bold' ]; then codes='1'