Parcourir la source

Merge pull request #46684 from smoser/fix/no-colors-in-check-config-to-file

contrib/check-config: Only add color if output is a terminal.
Sebastiaan van Stijn il y a 1 an
Parent
commit
b275f95f37
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 8 0
      contrib/check-config.sh

+ 8 - 0
contrib/check-config.sh

@@ -25,6 +25,10 @@ if ! command -v zgrep > /dev/null 2>&1; then
 	}
 	}
 fi
 fi
 
 
+useColor=true
+if [ "$NO_COLOR" = "1" ] || [ ! -t 1 ]; then
+	useColor=false
+fi
 kernelVersion="$(uname -r)"
 kernelVersion="$(uname -r)"
 kernelMajor="${kernelVersion%%.*}"
 kernelMajor="${kernelVersion%%.*}"
 kernelMinor="${kernelVersion#$kernelMajor.}"
 kernelMinor="${kernelVersion#$kernelMajor.}"
@@ -41,6 +45,10 @@ is_set_as_module() {
 }
 }
 
 
 color() {
 color() {
+	# if stdout is not a terminal, then don't do color codes.
+	if [ "$useColor" = "false" ]; then
+		return 0
+	fi
 	codes=
 	codes=
 	if [ "$1" = 'bold' ]; then
 	if [ "$1" = 'bold' ]; then
 		codes='1'
 		codes='1'