summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjoe <joe@FreeBSD.org>2000-08-12 22:40:14 +0000
committerjoe <joe@FreeBSD.org>2000-08-12 22:40:14 +0000
commit4ab486798ec3907ec0d18962dcd76f75dcca2112 (patch)
tree6f6471340a04c3cc7448bd7aa00985d4382b73b8 /bin
parent002ef51d6eb85e40acd7d5111adaccddc33e3880 (diff)
downloadFreeBSD-src-4ab486798ec3907ec0d18962dcd76f75dcca2112.zip
FreeBSD-src-4ab486798ec3907ec0d18962dcd76f75dcca2112.tar.gz
A change to the way that colours are switched on in ls. The -G
flag has been depricated, although it still works with a warning message, and replaced with an environment variable CLICOLOR (command line interface colour). This could be used by other tools that want to be able to control colour output. In addition if the environment variable CLICOLOR_FORCE is defined colour sequences are output irrespective of whether the output is directed to a terminal (as long as TERM references a colour capable terminal of course ;) PR: bin/20291 and bin/20483
Diffstat (limited to 'bin')
-rw-r--r--bin/ls/ls.163
-rw-r--r--bin/ls/ls.c35
2 files changed, 54 insertions, 44 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 1cb3395..37ed1df 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -43,7 +43,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm ls
-.Op Fl ABCFGHLPRTWabcdfgiklnoqrstu1
+.Op Fl ABCFHLPRTWabcdfgiklnoqrstu1
.Op Ar file ...
.Sh DESCRIPTION
For each operand that names a
@@ -91,29 +91,8 @@ a percent sign (%) after each whiteout,
and a vertical bar (|) after each that is a
.Tn FIFO .
.It Fl G
-Use
-.Tn 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.
-The colorization is dependent on a terminal type with the proper
-.Xr termcap 5
-capabilities.
-The default
-.Dq cons25
-console has the proper capabilities,
-however if you want to display the colors in an
-.Xr xterm 1
-for example,
-you need to set your
-.Ev TERM
-variable to
-.Dq xterm-color .
-Other terminal types may require similar adjustments.
+This flag has been depricated. Please use the
+.Ev CLICOLOR environment variable instead.
.It Fl H
Symbolic links on the command line are followed. This option is assumed if
none of the
@@ -393,6 +372,33 @@ is set, the block counts
(see
.Fl s )
will be displayed in units of that size block.
+.It Ev CLICOLOR
+Use
+.Tn ANSI
+color sequences to distinguish file types.
+See
+.Ev LSCOLORS
+below.
+In addition to the file types mentioned in the
+.Fl F
+option some extra attributes (setuid bit set, etc.) are also displayed.
+The colorization is dependent on a terminal type with the proper
+.Xr termcap 5
+capabilities.
+The default
+.Dq cons25
+console has the proper capabilities,
+however if you want to display the colors in an
+.Xr xterm 1
+for example,
+you need to set your
+.Ev TERM
+variable to
+.Dq xterm-color .
+Other terminal types may require similar adjustments.
+.It Ev CLICOLOR_FORCE
+Color sequences are normally disabled if the output isn't directed to
+a color capable terminal. This can be overridden by setting this flag.
.It Ev COLUMNS
If this variable contains a string representing a
decimal integer, it is used as the
@@ -414,9 +420,8 @@ See
for more information.
.It Ev LSCOLORS
The value of this variable describes what color to use for which
-attribute when the color output
-.Pq Fl G
-is specified.
+attribute when colors are enabled with
+.Ev CLICOLOR.
This string is a concatenation of pairs of the format
.Sy fb ,
where
@@ -494,8 +499,8 @@ in order: inode, block count, number of links, user name,
group name, flags, file size, file name.
.It Ev TERM
The
-.Fl G
-option depends on a terminal type with color capabilities.
+.Ev CLICOLOR
+functionality depends on a terminal type with color capabilities.
.It Ev TZ
The timezone to use when displaying dates.
See
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 4b48ef9..87cea23 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -202,23 +202,11 @@ main(argc, argv)
fts_options |= FTS_COMFOLLOW;
break;
case 'G':
- if (isatty(STDOUT_FILENO))
#ifdef COLORLS
- if (tgetent(termcapbuf, getenv("TERM")) == 1) {
- ansi_fgcol = tgetstr("AF", &bp);
- ansi_bgcol = tgetstr("AB", &bp);
-
- /* To switch colours off use 'op' if
- * available, otherwise use 'oc', or
- * don't do colours at all. */
- ansi_coloff = tgetstr("op", &bp);
- if (!ansi_coloff)
- ansi_coloff = tgetstr("oc", &bp);
- if (ansi_fgcol && ansi_bgcol && ansi_coloff)
- f_color = 1;
- }
+ (void)fprintf(stderr, "The -G flag is depricated, please define CLICOLOR instead.\n");
+ setenv("CLICOLOR", "", 1);
#else
- (void)fprintf(stderr, "Color support not compiled in.\n");
+ (void)fprintf(stderr, "Color support not compiled in.\n");
#endif
break;
case 'L':
@@ -295,6 +283,23 @@ main(argc, argv)
argv += optind;
#ifdef COLORLS
+ /* Enabling of colours is conditional on the environment. */
+ if (getenv("CLICOLOR") &&
+ (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
+ if (tgetent(termcapbuf, getenv("TERM")) == 1) {
+ ansi_fgcol = tgetstr("AF", &bp);
+ ansi_bgcol = tgetstr("AB", &bp);
+
+ /* To switch colours off use 'op' if
+ * available, otherwise use 'oc', or
+ * don't do colours at all. */
+ ansi_coloff = tgetstr("op", &bp);
+ if (!ansi_coloff)
+ ansi_coloff = tgetstr("oc", &bp);
+ if (ansi_fgcol && ansi_bgcol && ansi_coloff)
+ f_color = 1;
+ }
+
if (f_color) {
/*
* We can't put tabs and color sequences together:
OpenPOWER on IntegriCloud