[BusyBox] patch: allow ls coloring to be disabled

Paul Fox pgf at brightstareng.com
Tue Nov 9 10:28:00 MST 2004


hi --

if one turns on CONFIG_FEATURE_LS_COLOR, then you're stuck
with coloring (on tty devices) -- there's no way to disable it.
this is really wrong, imho -- like -F, -p, and -C, there should
be a command-line means of enabling/disabling such a feature. 
(especially since the colors themselves aren't configurable.)

the following patch is one way of implementing a means of turning
off color:  exporting BB_LSCOLOR as "none", "always", or "auto"
will cause the appropriate behavior.  better, and more general,
would be a command line argument for controlling color, along with
an LSOPTS variable that was parsed before with the command line
for setting default options.  but that's a bigger deal, not very
busybox-ish, and there's no precedent for a single-character
"color" option, that i know of.

i'm not attached to this particular implementation, but i do feel
that the mechanism is necessary.

paul

--- busybox-1.00.orig/coreutils/ls.c	2004-09-23 22:04:13.000000000 -0400
+++ busybox-1.00/coreutils/ls.c	2004-11-09 12:09:37.000000000 -0500
@@ -984,8 +984,20 @@
 #endif
 
 #ifdef CONFIG_FEATURE_LS_COLOR
-	if (isatty(STDOUT_FILENO))
-		show_color = 1;
+	{ 
+		char *lscolor;
+		lscolor = getenv("BB_LSCOLOR");
+		if (!lscolor)
+			show_color = 1;  /* backwards compatible default */
+		else if (*lscolor == 'n')  /* never */
+			show_color = 0;
+		else if (*lscolor == 'a') {
+			if (*(lscolor+1) == 'l')  /* always */
+				show_color = 1;
+			else if (*(lscolor+1) == 'u') /* auto */
+				show_color = isatty(STDOUT_FILENO);
+		}
+	}
 #endif
 
 	/* process options */

=---------------------
 paul fox, pgf at brightstareng.com


More information about the busybox mailing list