Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Nov 1998 05:46:09 GMT
From:      andrew@ugh.net.au
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   ports/8620: New option to colorls - -K, color only to a tty
Message-ID:  <199811090546.FAA00844@beebite.ugh.net.au>

next in thread | raw e-mail | index | archive | help

>Number:         8620
>Category:       ports
>Synopsis:       New option to colorls - -K, color only to a tty
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov  8 20:10:00 PST 1998
>Last-Modified:
>Originator:     Andrew
>Organization:
UgH!
>Release:        FreeBSD 2.2.7-STABLE i386
>Environment:

colorls from the ports collection (both 2.2.5 and 2.2.7).

>Description:

I have ls aliased to colorls -FG in my shell settings. This works well most of
the time but if I type, say ls | more I get the ANSI colour codes showing up,
ie I get ^[[31mcolorls*^[[m rather than colorls* in red. I assume more must fail
to print the escape character so the terminal dosn't interpret the code. I don't
know if that is a bug or a feature of more but I thought it would be nice to
have an option to colorls that only displayed colours if it was listing to a
terminal.

I used -K as -g was taken and it was close to -G. If anyone has a better letter
to use feel free to change it. 


>How-To-Repeat:

colorls -G | more

>Fix:
	
	The colorls port comes with one big patch file that patches everything in
one go but I did mine on a file by file basis so to incorporate them, either the
big patch will need to be split up into a patch for each file and my patches
used to replace the appropriate files or my patches will need to be copied and
pasted in with the others.

The patches were made in relation to the original ls source so they incorporate
asami@FreeBSD.ORG's original changes.


--- ls.c.orig	Mon Jul 20 16:29:17 1998
+++ ls.c	Mon Nov  9 15:19:00 1998
@@ -94,6 +94,7 @@
 int f_statustime;		/* use time of last mode change */
 int f_timesort;			/* sort by time vice name */
 int f_type;			/* add type character for non-regular files */
+int f_color;			/* add type in color for non-regular files */
 
 int rval;
 
@@ -131,7 +132,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "1ABCFHLPRTWabcdfgikloqrstu")) != -1) {
+	while ((ch = getopt(argc, argv, "1ABCFGHKLPRTWabcdfgikloqrstu")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C and -l options all override each other so shell
@@ -169,6 +170,13 @@
 		case 'H':
 		        fts_options |= FTS_COMFOLLOW;
 			break;
+		case 'G':
+			f_color = 1;
+			break;
+		case 'K':
+			if (isatty(STDOUT_FILENO))
+				f_color = 1;
+			break;
 		case 'L':
 			fts_options &= ~FTS_PHYSICAL;
 			fts_options |= FTS_LOGICAL;
@@ -236,18 +244,21 @@
 	argc -= optind;
 	argv += optind;
 
+	parsecolors(getenv("LSCOLORS"));
+
 	/*
 	 * If not -F, -i, -l, -s or -t options, don't require stat
 	 * information.
 	 */
-	if (!f_inode && !f_longform && !f_size && !f_timesort && !f_type)
+	if (!f_inode && !f_longform && !f_size && !f_timesort && !f_type
+	    && !f_color)
 		fts_options |= FTS_NOSTAT;
 
 	/*
 	 * If not -F, -d or -l options, follow any symbolic links listed on
 	 * the command line.
 	 */
-	if (!f_longform && !f_listdir && !f_type)
+	if (!f_longform && !f_listdir && !f_type && !f_color)
 		fts_options |= FTS_COMFOLLOW;
 
 	/* If -l or -s, figure out block size. */



--- colorls.1.orig	Sun Nov  8 08:47:49 1998
+++ colorls.1	Mon Nov  9 15:18:00 1998
@@ -36,16 +36,26 @@
 .\"	$Id: ls.1,v 1.5.2.6 1998/07/15 02:01:34 jkh Exp $
 .\"
 .Dd April 18, 1994
-.Dt LS 1
+.Dt COLORLS 1
 .Os
 .Sh NAME
 .Nm ls
-.Nd list directory contents
+.Nd list directory contents in color
 .Sh SYNOPSIS
-.Nm ls
-.Op Fl ABCFHLPRTWabcdfgikloqrstu1
+.Nm colorls
+.Op Fl ABCFGHKLPRTWabcdfgikloqrstu1
 .Op Ar file ...
 .Sh DESCRIPTION
+(Note: This man page describes the color version of the program.  To
+minimize the differences from the original, the program is referred to
+as
+.Nm ls
+in this manual.  The new options
+.Fl G
+and
+.Fl K
+are for color display.)
+.Pp
 For each operand that names a
 .Ar file
 of a type other than
@@ -90,6 +100,12 @@
 a percent sign (%) after each whiteout,
 and a vertical bar (|) after each that is a
 .Tn FIFO .
+.It Fl G
+Use ANSI color sequences to distinguish file types.  (See
+.Ev LSCOLORS
+below.)  In addition to those mentioned above in
+.Fl F ,
+some extra attributes (setuid bit set, etc.) are also displayed.
 .It Fl H
 Symbolic links on the command line are followed.  This option is assumed if
 none of the
@@ -98,6 +114,10 @@
 or
 .Fl l
 options are specified.
+.It Fl K
+Like
+.Fl G 
+but only works if stdout is a terminal.
 .It Fl L
 If argument is a symbolic link, list the file or directory the link references
 rather than the link itself. This option cancels the
@@ -373,6 +393,74 @@
 See
 .Xr environ 7
 for more information.
+.It LSCOLORS
+The value of this variable describes what color to use for which
+attribute when the color output
+.Pq Fl G
+is specified.  This string is a concatenation of pairs of the format
+.Sy fb ,
+where
+.Sy f
+is the foreground color and
+.Sy b
+is the background color.
+.Pp
+The color designators are as follows:
+.Pp
+.Bl -tag -width 4n -offset indent -compact
+.It Sy 0
+black
+.It Sy 1
+red
+.It Sy 2
+green
+.It Sy 3
+yellow
+.It Sy 4
+blue
+.It Sy 5
+magenta
+.It Sy 6
+cyan
+.It Sy 7
+white
+.It Sy x
+default foreground or background
+.El
+.Pp
+(Note: the above are standard ANSI colors.  The actual display may
+differ depending on the color capabilities of your terminal.)
+.Pp
+The order of the attributes are as follows:
+.Pp
+.Bl -enum -offset indent -compact
+.It
+directory
+.It
+symbolic link
+.It
+socket
+.It
+pipe
+.It
+executable
+.It
+block special
+.It
+character special
+.It
+executable with setuid bit set
+.It
+executable with setgid bit set
+.It
+directory writable to others, with sticky bit
+.It
+directory writable to others, without sticky bit
+.El
+.Pp
+The default is "4x5x2x3x1x464301060203", i.e., blue foreground and
+default background for regular directories, black foreground and red
+background for setuid executables, etc.
 .El
 .Sh COMPATIBILITY
 The group field is now automatically included in the long listing for
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811090546.FAA00844>