Subject: new option for ls(1): opposite of -q
To: None <tech-userlevel@netbsd.org>
From: Dieter Baron <dillo@danbala.ifoer.tuwien.ac.at>
List: tech-userlevel
Date: 05/09/2001 15:03:27
hi,

I have a slight problem with the addition of the -q option and making
it the default for output to a tty: while quoting non-printable
characters in file names is a good idea, as is making this the default
for output to a tty, I miss the possibility to tell ls not to do so.
(`ls -C | cat' can hardly be called a solution.)

  Therefore, I propose a new option to keep ls from quoting
non-printables; in the patch below that implements this, I've choosen
-Q, but any other (unused) letter is just as well.

  Any objections to this change?

						yours,
						dillo

----------------
diff -ur ls/ls.1 ls-Q/ls.1
--- ls/ls.1	Mon Sep  4 09:30:11 2000
+++ ls-Q/ls.1	Wed May  9 14:46:40 2001
@@ -44,7 +44,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm
-.Op Fl ACFLRSTWacdfgiklmnoqrstux1
+.Op Fl ACFLQRSTWacdfgiklmnoqrstux1
 .Op Ar file ...
 .Sh DESCRIPTION
 For each operand that names a
@@ -90,6 +90,9 @@
 .It Fl L
 If argument is a symbolic link, list the file or directory the link references
 rather than the link itself.
+.It Fl Q
+Print non-graphic characters in file names as themselves;
+this is the default when output is not to a terminal.
 .It Fl R
 Recursively list subdirectories encountered.
 .It Fl S
@@ -188,6 +191,13 @@
 .Fl u
 options override each other; the last one specified determines
 the file time used.
+.Pp
+The
+.Fl Q ,
+and
+.Fl q
+options override each other; the last one specified determines whether to
+replace non-printable characters with `?'. 
 .Pp
 By default,
 .Nm
diff -ur ls/ls.c ls-Q/ls.c
--- ls/ls.c	Sat Jul 29 05:46:15 2000
+++ ls-Q/ls.c	Wed May  9 14:36:21 2001
@@ -136,7 +136,8 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "1ACFLRSTWacdfgiklmnopqrstux")) != -1) {
+	while ((ch = getopt(argc, argv, "1ACFLQRSTWacdfgiklmnopqrstux"))
+	    != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C, -l, -m and -x options all override each other so
@@ -217,6 +218,9 @@
 			break;
 		case 'q':
 			f_nonprint = 1;
+			break;
+		case 'Q':
+			f_nonprint = 0;
 			break;
 		case 'r':
 			f_reversesort = 1;
diff -ur ls/util.c ls-Q/util.c
--- ls/util.c	Sat Jul 29 05:46:15 2000
+++ ls-Q/util.c	Wed May  9 14:37:59 2001
@@ -75,7 +75,7 @@
 usage(void)
 {
 	(void)fprintf(stderr, 
-	    "usage: ls [-1ACFLRSTWacdfgiklmnopqrstux] [file ...]\n");
+	    "usage: ls [-1ACFLQRSTWacdfgiklmnopqrstux] [file ...]\n");
 	exit(EXIT_FAILURE);
 	/* NOTREACHED */
 }