diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-27 13:46:08 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-27 13:46:08 +0200 |
commit | 85b4b2bb94c2ab4e837aa5fc99c5209cee4f58f2 (patch) | |
tree | 0f6beeecab8edb8302b5447deb775f81a9ecb4f2 | |
parent | 4bdec3f2e9025964ab810f832ff768fa32c1e173 (diff) | |
download | lr-85b4b2bb94c2ab4e837aa5fc99c5209cee4f58f2.tar.gz lr-85b4b2bb94c2ab4e837aa5fc99c5209cee4f58f2.tar.xz lr-85b4b2bb94c2ab4e837aa5fc99c5209cee4f58f2.zip |
lr: breaking change: swap meaning of -Q
This is a bit unfortunate, but the better behavior in the long run.
-rw-r--r-- | NEWS.md | 5 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | lr.1 | 15 | ||||
-rw-r--r-- | lr.c | 24 |
4 files changed, 32 insertions, 20 deletions
diff --git a/NEWS.md b/NEWS.md index f6bd01e..22d8499 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ ## HEAD +* **Breaking change**: the `-Q` flag changed meaning to *enable* quoting + (as it does in GNU ls), since shell quoting is not so useful in many + cases using a pipe. Filenames are quoted by default when printing + to TTY. + ## 0.4 (2017-04-25) * Feature: argument '-' means read files from standard input diff --git a/README.md b/README.md index b6e512d..d423dcd 100644 --- a/README.md +++ b/README.md @@ -51,14 +51,14 @@ Over ls: The special path argument `-` makes `lr` read file names from standard input, instead of traversing path. -* `-0`: output filenames seperated by NUL bytes (implies `-Q`). +* `-0`: output filenames seperated by NUL bytes. Likewise, read input filenames seperated by NUL bytes. * `-F`: output filenames and an indicator of their file type (`*/=>@|`). -* `-l`: long output ala `ls -l`. +* `-l`: long output ala `ls -l` (implies `-Q`). * `-TA`: with `-l`, output atime. * `-TC`: with `-l`, output ctime. * `-TM`: with `-l`, output mtime (default). -* `-S`: BSD stat(1)-inspired output. +* `-S`: BSD stat(1)-inspired output (implies `-Q`). * `-f FMT`: custom formatting, see below. * `-D`: depth first traversal. `prune` does not work, but `entries` and `total` are computed on the fly. @@ -67,7 +67,7 @@ input, instead of traversing path. * `-1`: don't go below one level of directories. * `-A`: don't list files starting with a dot. * `-G`: colorize output to tty. Use twice to force colorize. -* `-Q`: don't shell quote file names. +* `-Q`: shell quote file names (default for output to TTY). * `-d`: don't enter directories. * `-h`: print human readable size for `-l` (also `%s`). * `-s`: strip directory prefix passed on command line. diff --git a/lr.1 b/lr.1 index d44ea4e..67af994 100644 --- a/lr.1 +++ b/lr.1 @@ -1,4 +1,4 @@ -.Dd June 20, 2017 +.Dd July 27, 2017 .Dt LR 1 .Os .Sh NAME @@ -48,15 +48,16 @@ read file names from The options are as follows: .Bl -tag -width Ds .It Fl 0 -Output filenames seperated by NUL bytes (implies -.Fl Q ) . +Output filenames seperated by NUL bytes. Likewise, read input filenames seperated by NUL bytes. .It Fl F Output filenames and an indicator of their file type (one of .Sq Li */=>@| ) . .It Fl l Long output ala -.Ic ls -l . +.Sq Ic ls -l +(implies +.Fl Q ) . .It Fl TA With .Fl l , @@ -73,7 +74,9 @@ This is the default. .It Fl S Output inspired by BSD -.Xr stat 1 . +.Xr stat 1 +(implies +.Fl Q ) . .It Fl f Ar fmt Custom formatting, see .Sx FORMATTING . @@ -94,7 +97,7 @@ Don't go below one level of directories. .It Fl A Don't list files starting with a dot. .It Fl Q -Don't shell quote file names. +Quote file names (default for output to TTY). .It Fl d Don't enter directories. .It Fl G diff --git a/lr.c b/lr.c index 3277bed..d26e963 100644 --- a/lr.c +++ b/lr.c @@ -1419,11 +1419,11 @@ print_human(intmax_t i) static void print_shquoted(const char *s) { - if (Qflag || !strpbrk(s, "\001\002\003\004\005\006\007\010" - "\011\012\013\014\015\016\017\020" - "\021\022\023\024\025\026\027\030" - "\031\032\033\034\035\036\037\040" - "`^#*[]=|\\?${}()'\"<>&;\177")) { + if (!Qflag || !strpbrk(s, "\001\002\003\004\005\006\007\010" + "\011\012\013\014\015\016\017\020" + "\021\022\023\024\025\026\027\030" + "\031\032\033\034\035\036\037\040" + "`^#*[]=|\\?${}()'\"<>&;\177")) { printf("%s", s); return; } @@ -1941,7 +1941,7 @@ main(int argc, char *argv[]) while ((c = getopt(argc, argv, "01AC:DFGHLQST:Udf:lho:st:x")) != -1) switch(c) { - case '0': format = zero_format; input_delim = 0; Qflag++; break; + case '0': format = zero_format; input_delim = 0; Qflag = 0; break; case '1': expr = chain(parse_expr("depth == 0 || prune"), EXPR_AND, expr); break; case 'A': expr = chain(parse_expr("!(path ~~ \"*/.*\" && prune) && !path == \".\""), EXPR_AND, expr); break; case 'C': @@ -1960,13 +1960,13 @@ main(int argc, char *argv[]) case 'H': Hflag++; break; case 'L': Lflag++; break; case 'Q': Qflag++; break; - case 'S': format = stat_format; break; + case 'S': Qflag++; format = stat_format; break; case 'T': Tflag = timeflag(optarg); break; case 'U': Uflag++; break; case 'd': expr = chain(parse_expr("type == d && prune || print"), EXPR_AND, expr); break; case 'f': format = optarg; break; case 'h': hflag++; break; - case 'l': lflag++; format = long_format; break; + case 'l': lflag++; Qflag++; format = long_format; break; case 'o': ordering = optarg; break; case 's': sflag++; break; case 't': expr = chain(expr, EXPR_AND, parse_expr(optarg)); break; @@ -1978,8 +1978,12 @@ main(int argc, char *argv[]) exit(2); } - if (Gflag == 1 && !isatty(1)) - Gflag = 0; + if (isatty(1)) { + Qflag = 1; + } else { + if (Gflag == 1) + Gflag = 0; + } analyze_format(); |