This syncs the color code in sysutils/colorls with FreeBSD's. In
particular, it adds a long option --color=WHEN for compatibility
with GNU coreutils.
People who actually use colorls may want to give this one a try.
Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/colorls/Makefile,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile
--- Makefile 4 Apr 2018 19:02:00 -0000 1.36
+++ Makefile 1 Apr 2019 08:51:03 -0000
@@ -2,7 +2,7 @@
COMMENT= ls(1) that can use color to display file attributes
-VERSION= 6.3
+VERSION= 6.4
DISTNAME= ls-${VERSION}
PKGNAME= colorls-${VERSION}
CATEGORIES= sysutils
Index: distinfo
===================================================================
RCS file: /cvs/ports/sysutils/colorls/distinfo,v
retrieving revision 1.23
diff -u -p -r1.23 distinfo
--- distinfo 4 Apr 2018 19:02:00 -0000 1.23
+++ distinfo 1 Apr 2019 08:51:03 -0000
@@ -1,2 +1,2 @@
-SHA256 (ls-6.3.tar.gz) = lmZkj2KQI1hCIM7E//ZiJ/TQjWS4hyauy0ah1Hw6eSY=
-SIZE (ls-6.3.tar.gz) = 13627
+SHA256 (ls-6.4.tar.gz) = AOiDGFS5emhlW5OHnBMwrOxI7jGUNdbWO24DhMENvOk=
+SIZE (ls-6.4.tar.gz) = 13644
Index: patches/patch-colorls_1
===================================================================
RCS file: /cvs/ports/sysutils/colorls/patches/patch-colorls_1,v
retrieving revision 1.18
diff -u -p -r1.18 patch-colorls_1
--- patches/patch-colorls_1 14 Mar 2018 21:50:56 -0000 1.18
+++ patches/patch-colorls_1 1 Apr 2019 08:51:03 -0000
@@ -2,7 +2,7 @@ $OpenBSD: patch-colorls_1,v 1.18 2018/03
Index: colorls.1
--- colorls.1.orig
+++ colorls.1
-@@ -37,11 +37,11 @@
+@@ -37,11 +37,12 @@
.Dt COLORLS 1
.Os
.Sh NAME
@@ -14,10 +14,79 @@ Index: colorls.1
-.Op Fl 1AaCcdFfgHhikLlmnopqRrSsTtux
+.Nm
+.Op Fl 1AaCcdFfGgHhikLlmnopqRrSsTtux
++.Op Fl -color Ns = Ns Ar when
.Op Ar
.Sh DESCRIPTION
For each operand that names a
-@@ -123,6 +123,12 @@ after each that is a FIFO.
+@@ -100,6 +101,67 @@ or printing
+ .Pf ( Fl g , l ,
+ or
+ .Fl n ) .
++.It Fl -color Ns = Ns Ar when
++Output colored escape sequences based on
++.Ar when ,
++which may be set to either
++.Cm always ,
++.Cm auto
++(default), or
++.Cm never .
++.Pp
++.Cm always
++will make
++.Nm
++always output color.
++If
++.Ev TERM
++is unset or set to an invalid terminal, then
++.Nm
++will fall back to explicit
++.Tn ANSI
++escape sequences without the help of
++.Xr termcap 5 .
++.Cm always
++is the default if
++.Fl -color
++is specified without an argument.
++.Pp
++.Cm auto
++will make
++.Nm
++output escape sequences based on
++.Xr termcap 5 ,
++but only if
++.Dv stdout
++is a tty and either the
++.Fl G
++flag is specified or the
++.Ev COLORTERM
++environment variable is set and not empty.
++.Pp
++.Cm never
++will disable color regardless of environment variables.
++.Pp
++For compatibility with GNU coreutils,
++.Nm
++supports
++.Cm yes
++or
++.Cm force
++as equivalent to
++.Cm always ,
++.Cm no
++or
++.Cm none
++as equivalent to
++.Cm never ,
++and
++.Cm tty
++or
++.Cm if-tty
++as equivalent to
++.Cm auto .
+ .It Fl d
+ Directories are listed as plain files (not searched recursively) and
+ symbolic links in the argument list are not indirected through.
+@@ -123,6 +185,14 @@ after each that is a FIFO.
Output is not sorted.
This option implies
.Fl a .
@@ -25,12 +94,14 @@ Index: colorls.1
+Enable colorized output.
+This option is equivalent to defining
+.Ev CLICOLOR
++or
++.Ev COLORTERM
+in the environment.
+(See below.)
.It Fl g
List in long format as in
.Fl l ,
-@@ -425,7 +431,7 @@ user append-only
+@@ -425,7 +495,7 @@ user append-only
user immutable
.El
.Sh ENVIRONMENT
@@ -39,7 +110,7 @@ Index: colorls.1
.It Ev BLOCKSIZE
If the environment variable
.Ev BLOCKSIZE
-@@ -435,6 +441,40 @@ option is not specified, the block counts
+@@ -435,6 +505,47 @@ option is not specified, the block counts
(see
.Fl s )
will be displayed in units of that size block.
@@ -67,7 +138,10 @@ Index: colorls.1
+Colorization is silently disabled if the output isn't directed to a terminal
+unless the
+.Ev CLICOLOR_FORCE
-+variable is defined.
++variable is defined or
++.Fl -color
++is set to
++.Dq always .
+.It Ev CLICOLOR_FORCE
+Color sequences are normally disabled if the output isn't directed to
+a terminal.
@@ -77,17 +151,23 @@ Index: colorls.1
+variable still needs to reference a color capable terminal however
+otherwise it is not possible to determine which color sequences to
+use.
++.It Ev COLORTERM
++See description for
++.Ev CLICOLOR
++above.
.It Ev COLUMNS
If set to a positive integer,
output is formatted to the given width in columns.
-@@ -450,6 +490,99 @@ If unset or set to
+@@ -450,6 +561,103 @@ If unset or set to
.Qq C ,
.Qq POSIX ,
or an unsupported value, non-ASCII bytes are replaced by question marks.
+.It Ev LSCOLORS
+The value of this variable describes what color to use for which
+attribute when colors are enabled with
-+.Ev CLICOLOR .
++.Ev CLICOLOR
++or
++.Ev COLORTERM .
+This string is a concatenation of pairs of the format
+.Ar f Ns Ar b ,
+where
@@ -176,11 +256,13 @@ Index: colorls.1
+.It Ev TERM
+The
+.Ev CLICOLOR
++and
++.Ev COLORTERM
+functionality depends on a terminal type with color capabilities.
.It Ev TZ
The time zone to use when displaying dates.
See
-@@ -457,33 +590,34 @@ See
+@@ -457,33 +665,34 @@ See
for more information.
.El
.Sh EXIT STATUS
@@ -220,7 +302,7 @@ Index: colorls.1
utility is compliant with the
.St -p1003.1-2008
specification,
-@@ -492,10 +626,10 @@ except behaviour for the
+@@ -492,10 +701,10 @@ except behaviour for the
flag differs.
.Pp
The flags
@@ -233,7 +315,7 @@ Index: colorls.1
are extensions to that specification.
.Pp
The flags
-@@ -515,6 +649,6 @@ flag has been changed in order to be compatible with t
+@@ -515,6 +724,6 @@ flag has been changed in order to be compatible with t
specification.
.Sh HISTORY
An
Index: patches/patch-extern_h
===================================================================
RCS file: /cvs/ports/sysutils/colorls/patches/patch-extern_h,v
retrieving revision 1.6
diff -u -p -r1.6 patch-extern_h
--- patches/patch-extern_h 6 Apr 2016 18:53:16 -0000 1.6
+++ patches/patch-extern_h 1 Apr 2019 08:51:03 -0000
@@ -1,7 +1,17 @@
$OpenBSD: patch-extern_h,v 1.6 2016/04/06 18:53:16 naddy Exp $
---- extern.h.orig Tue Dec 1 19:36:13 2015
-+++ extern.h Wed Apr 6 19:12:57 2016
-@@ -52,3 +52,13 @@ void printlong(DISPLAY *);
+Index: extern.h
+--- extern.h.orig
++++ extern.h
+@@ -32,6 +32,8 @@
+ * @(#)extern.h 8.1 (Berkeley) 5/31/93
+ */
+
++#include <stdbool.h>
++
+ extern char *__progname;
+
+ int acccmp(const FTSENT *, const FTSENT *);
+@@ -52,3 +54,20 @@ void printlong(DISPLAY *);
void printscol(DISPLAY *);
void printstream(DISPLAY *);
void usage(void);
@@ -9,9 +19,16 @@ $OpenBSD: patch-extern_h,v 1.6 2016/04/0
+void parsecolors(const char *cs);
+void colorquit(int);
+
-+extern char *ansi_fgcol;
-+extern char *ansi_bgcol;
-+extern char *ansi_coloff;
-+extern char *attrs_off;
-+extern char *enter_bold;
++extern char *ansi_fgcol;
++extern char *ansi_bgcol;
++extern char *ansi_coloff;
++extern char *attrs_off;
++extern char *enter_bold;
++
++extern int colorflag;
++extern bool explicitansi;
++
++#define COLORFLAG_NEVER 0
++#define COLORFLAG_AUTO 1
++#define COLORFLAG_ALWAYS 2
+#endif
Index: patches/patch-ls_c
===================================================================
RCS file: /cvs/ports/sysutils/colorls/patches/patch-ls_c,v
retrieving revision 1.17
diff -u -p -r1.17 patch-ls_c
--- patches/patch-ls_c 5 Aug 2016 19:52:19 -0000 1.17
+++ patches/patch-ls_c 1 Apr 2019 08:51:03 -0000
@@ -1,7 +1,19 @@
$OpenBSD: patch-ls_c,v 1.17 2016/08/05 19:52:19 naddy Exp $
---- ls.c.orig Fri Aug 5 21:32:46 2016
-+++ ls.c Fri Aug 5 21:41:30 2016
-@@ -50,6 +50,10 @@
+Index: ls.c
+--- ls.c.orig
++++ ls.c
+@@ -41,8 +41,10 @@
+ #include <err.h>
+ #include <errno.h>
+ #include <fts.h>
++#include <getopt.h>
+ #include <grp.h>
+ #include <pwd.h>
++#include <stdbool.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -50,6 +52,10 @@
#include <limits.h>
#include <locale.h>
#include <util.h>
@@ -12,35 +24,119 @@ $OpenBSD: patch-ls_c,v 1.17 2016/08/05 1
#include "ls.h"
#include "extern.h"
-@@ -92,6 +96,15 @@ int f_statustime; /* use time of last mode change
*/
+@@ -58,6 +64,16 @@ static void display(FTSENT *, FTSENT *);
+ static int mastercmp(const FTSENT **, const FTSENT **);
+ static void traverse(int, char **, int);
+
++#define COLOR_OPT (CHAR_MAX + 1)
++
++static const struct option long_opts[] =
++{
++#ifdef COLORLS
++ {"color", optional_argument, NULL, COLOR_OPT},
++#endif
++ {NULL, no_argument, NULL, 0}
++};
++
+ static void (*printfcn)(DISPLAY *);
+ static int (*sortfcn)(const FTSENT *, const FTSENT *);
+
+@@ -92,9 +108,82 @@ int f_statustime; /* use time of last mode change
*/
int f_stream; /* stream format */
int f_type; /* add type character for non-regular files */
int f_typedir; /* add type character for directories */
+#ifdef COLORLS
++int colorflag = COLORFLAG_AUTO; /* passed in colorflag */
+int f_color; /* add type in color for non-regular files */
-+
+
++bool explicitansi; /* Explicit ANSI sequences, no termcap(5) */
+char *ansi_bgcol; /* ANSI sequence to set background color */
+char *ansi_fgcol; /* ANSI sequence to set foreground color */
+char *ansi_coloff; /* ANSI sequence to reset colors */
+char *attrs_off; /* ANSI sequence to turn off attributes */
+char *enter_bold; /* ANSI sequence to set color to bold mode */
+#endif
-
++
int rval;
-@@ -103,6 +116,11 @@ ls_main(int argc, char *argv[])
++static bool
++do_color_from_env(void)
++{
++ const char *p;
++ bool doit;
++
++ doit = false;
++ p = getenv("CLICOLOR");
++ if (p == NULL) {
++ /*
++ * COLORTERM is the more standard name for this variable. We'll
++ * honor it as long as it's both set and not empty.
++ */
++ p = getenv("COLORTERM");
++ if (p != NULL && *p != '\0')
++ doit = true;
++ } else
++ doit = true;
++
++ return (doit &&
++ (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")));
++}
++
++static bool
++do_color(void)
++{
++
++#ifdef COLORLS
++ if (colorflag == COLORFLAG_NEVER)
++ return (false);
++ else if (colorflag == COLORFLAG_ALWAYS)
++ return (true);
++#endif
++ return (do_color_from_env());
++}
++
++#ifdef COLORLS
++static bool
++do_color_always(const char *term)
++{
++
++ return (strcmp(term, "always") == 0 || strcmp(term, "yes") == 0 ||
++ strcmp(term, "force") == 0);
++}
++
++static bool
++do_color_never(const char *term)
++{
++
++ return (strcmp(term, "never") == 0 || strcmp(term, "no") == 0 ||
++ strcmp(term, "none") == 0);
++}
++
++static bool
++do_color_auto(const char *term)
++{
++
++ return (strcmp(term, "auto") == 0 || strcmp(term, "tty") == 0 ||
++ strcmp(term, "if-tty") == 0);
++}
++#endif /* COLORLS */
++
+ int
+ ls_main(int argc, char *argv[])
+ {
+@@ -103,6 +192,11 @@ ls_main(int argc, char *argv[])
int ch, fts_options, notused;
int kflag = 0;
char *p;
+#ifdef COLORLS
+ char termcapbuf[1024]; /* termcap definition buffer */
+ char tcapbuf[512]; /* capability buffer */
-+ char *bp = tcapbuf;
++ char *bp = tcapbuf, *term;
+#endif
#ifndef SMALL
setlocale(LC_CTYPE, "");
-@@ -124,7 +142,11 @@ ls_main(int argc, char *argv[])
+@@ -124,7 +218,11 @@ ls_main(int argc, char *argv[])
if (termwidth == 0)
termwidth = 80;
@@ -52,16 +148,18 @@ $OpenBSD: patch-ls_c,v 1.17 2016/08/05 1
err(1, "pledge");
/* Root is -A automatically. */
-@@ -132,7 +154,7 @@ ls_main(int argc, char *argv[])
+@@ -132,7 +230,9 @@ ls_main(int argc, char *argv[])
f_listdot = 1;
fts_options = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "1ACFHLRSTacdfghiklmnopqrstux")) != -1)
{
-+ while ((ch = getopt(argc, argv, "1ACFGHLRSTacdfghiklmnopqrstux")) !=
-1) {
++ while ((ch = getopt_long(argc, argv,
++ "+1ACFGHLRSTacdfghiklmnopqrstux", long_opts,
++ NULL)) != -1) {
switch (ch) {
/*
* The -1, -C and -l, -m, -n and -x options all override each
-@@ -186,6 +208,9 @@ ls_main(int argc, char *argv[])
+@@ -186,6 +286,9 @@ ls_main(int argc, char *argv[])
case 'F':
f_type = 1;
break;
@@ -71,15 +169,37 @@ $OpenBSD: patch-ls_c,v 1.17 2016/08/05 1
case 'H':
fts_options |= FTS_COMFOLLOW;
break;
-@@ -258,19 +283,59 @@ ls_main(int argc, char *argv[])
- if (f_grouponly == -1)
+@@ -244,6 +347,19 @@ ls_main(int argc, char *argv[])
+ case 't':
+ sortkey = BY_TIME;
+ break;
++#ifdef COLORLS
++ case COLOR_OPT:
++ if (optarg == NULL || do_color_always(optarg))
++ colorflag = COLORFLAG_ALWAYS;
++ else if (do_color_auto(optarg))
++ colorflag = COLORFLAG_AUTO;
++ else if (do_color_never(optarg))
++ colorflag = COLORFLAG_NEVER;
++ else
++ errx(2, "unsupported --color value '%s' (must
be always, auto, or never)",
++ optarg);
++ break;
++#endif
+ default:
+ usage();
+ }
+@@ -259,18 +375,70 @@ ls_main(int argc, char *argv[])
f_grouponly = 0;
-+ /* Enabling of colours is conditional on the environment. */
-+ if (getenv("CLICOLOR") &&
-+ (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
+ /*
++ * Enabling of colours is conditional on the environment in conjunction
++ * with the --color and -G arguments, if supplied.
++ */
++ if (do_color()) {
+#ifdef COLORLS
-+ if (tgetent(termcapbuf, getenv("TERM")) == 1) {
++ if ((term = getenv("TERM")) != NULL &&
++ tgetent(termcapbuf, term) == 1) {
+ ansi_fgcol = tgetstr("AF", &bp);
+ ansi_bgcol = tgetstr("AB", &bp);
+ attrs_off = tgetstr("me", &bp);
@@ -93,10 +213,19 @@ $OpenBSD: patch-ls_c,v 1.17 2016/08/05 1
+ ansi_coloff = tgetstr("oc", &bp);
+ if (ansi_fgcol && ansi_bgcol && ansi_coloff)
+ f_color = 1;
++ } else if (colorflag == COLORFLAG_ALWAYS) {
++ /*
++ * If we're *always* doing color but we don't have
++ * a functional TERM supplied, we'll fallback to
++ * outputting raw ANSI sequences.
++ */
++ f_color = 1;
++ explicitansi = true;
+ }
+#else
+ warnx("color support not compiled in");
+#endif /*COLORLS*/
++ }
+
+#ifdef COLORLS
+ if (f_color) {
@@ -106,7 +235,7 @@ $OpenBSD: patch-ls_c,v 1.17 2016/08/05 1
+ }
+#endif
+
- /*
++ /*
* If not -F, -i, -l, -p, -S, -s or -t options, don't require stat
- * information.
+ * information, unless in color mode in which case we do
Index: patches/patch-print_c
===================================================================
RCS file: /cvs/ports/sysutils/colorls/patches/patch-print_c,v
retrieving revision 1.16
diff -u -p -r1.16 patch-print_c
--- patches/patch-print_c 14 Mar 2018 21:50:56 -0000 1.16
+++ patches/patch-print_c 1 Apr 2019 08:51:03 -0000
@@ -14,18 +14,20 @@ Index: print.c
#include "ls.h"
#include "extern.h"
-@@ -58,6 +63,10 @@ static void printsize(int, off_t);
+@@ -58,6 +63,12 @@ static void printsize(int, off_t);
static void printtime(time_t);
static int printtype(mode_t);
static int compute_columns(DISPLAY *, int *);
+#ifdef COLORLS
++static void endcolor_termcap(int);
++static void endcolor_ansi(void);
+static void endcolor(int);
+static int colortype(mode_t);
+#endif
#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
-@@ -66,6 +75,32 @@ static int compute_columns(DISPLAY *, int *);
+@@ -66,6 +77,32 @@ static int compute_columns(DISPLAY *, int *);
#define SECSPERDAY (24 * 60 * 60)
#define SIXMONTHS (SECSPERDAY * 365 / 2)
@@ -58,7 +60,7 @@ Index: print.c
void
printscol(DISPLAY *dp)
{
-@@ -86,6 +121,9 @@ printlong(DISPLAY *dp)
+@@ -86,6 +123,9 @@ printlong(DISPLAY *dp)
FTSENT *p;
NAMES *np;
char buf[20];
@@ -68,7 +70,7 @@ Index: print.c
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
(void)printf("total %llu\n", howmany(dp->btotal, blocksize));
-@@ -123,7 +161,15 @@ printlong(DISPLAY *dp)
+@@ -123,7 +163,15 @@ printlong(DISPLAY *dp)
printtime(sp->st_ctime);
else
printtime(sp->st_mtime);
@@ -84,7 +86,7 @@ Index: print.c
if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
(void)printtype(sp->st_mode);
if (S_ISLNK(sp->st_mode))
-@@ -223,6 +269,9 @@ printaname(FTSENT *p, int inodefield, int sizefield)
+@@ -223,6 +271,9 @@ printaname(FTSENT *p, int inodefield, int sizefield)
{
struct stat *sp;
int chcnt;
@@ -94,7 +96,7 @@ Index: print.c
sp = p->fts_statp;
chcnt = 0;
-@@ -232,7 +281,15 @@ printaname(FTSENT *p, int inodefield, int sizefield)
+@@ -232,7 +283,15 @@ printaname(FTSENT *p, int inodefield, int sizefield)
if (f_size)
chcnt += printf("%*lld ", sizefield,
howmany((long long)sp->st_blocks, blocksize));
@@ -110,7 +112,7 @@ Index: print.c
if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
chcnt += printtype(sp->st_mode);
return (chcnt);
-@@ -345,6 +402,151 @@ printtype(mode_t mode)
+@@ -345,6 +404,194 @@ printtype(mode_t mode)
}
return (0);
}
@@ -133,7 +135,7 @@ Index: print.c
+}
+
+static void
-+printcolor(Colors c)
++printcolor_termcap(Colors c)
+{
+ char *ansiseq;
+
@@ -153,10 +155,53 @@ Index: print.c
+}
+
+static void
-+endcolor(int sig)
++printcolor_ansi(Colors c)
++{
++
++ printf("\033[");
++
++ if (colors[c].bold)
++ printf("1");
++ if (colors[c].num[0] != -1)
++ printf(";3%d", colors[c].num[0]);
++ if (colors[c].num[1] != -1)
++ printf(";4%d", colors[c].num[1]);
++ printf("m");
++}
++
++static void
++printcolor(Colors c)
+{
++
++ if (explicitansi)
++ printcolor_ansi(c);
++ else
++ printcolor_termcap(c);
++}
++
++static void
++endcolor_termcap(int sig)
++{
++
+ tputs(ansi_coloff, 1, sig ? writech : putch);
+ tputs(attrs_off, 1, sig ? writech : putch);
++}
++
++static void
++endcolor_ansi(void)
++{
++
++ printf("\33[m");
++}
++
++static void
++endcolor(int sig)
++{
++
++ if (explicitansi)
++ endcolor_ansi();
++ else
++ endcolor_termcap(sig);
+}
+
+static int
Index: patches/patch-util_c
===================================================================
RCS file: /cvs/ports/sysutils/colorls/patches/patch-util_c,v
retrieving revision 1.11
diff -u -p -r1.11 patch-util_c
--- patches/patch-util_c 6 Apr 2016 18:53:16 -0000 1.11
+++ patches/patch-util_c 1 Apr 2019 08:51:03 -0000
@@ -1,12 +1,13 @@
$OpenBSD: patch-util_c,v 1.11 2016/04/06 18:53:16 naddy Exp $
---- util.c.orig Tue Dec 1 19:36:13 2015
-+++ util.c Wed Apr 6 20:28:44 2016
+Index: util.c
+--- util.c.orig
++++ util.c
@@ -64,7 +64,11 @@ void
usage(void)
{
(void)fprintf(stderr,
+#ifdef COLORLS
-+ "usage: %s [-1AaCcdFfGgHhikLlmnopqRrSsTtux] [file ...]\n",
++ "usage: %s [-1AaCcdFfGgHhikLlmnopqRrSsTtux] [--color=when] [file
...]\n",
+#else
"usage: %s [-1AaCcdFfgHhikLlmnopqRrSsTtux] [file ...]\n",
+#endif
--
Christian "naddy" Weisgerber [email protected]