summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-02-27 19:20:22 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-02-27 19:20:22 +0100
commitddc648c39a1d116cad5bddce3c74a4143cb139ab (patch)
tree097d75b57aa1d1a17fc1c9bd9363c329a75c6942
parentd0dfe2659d440785058fdce0529dd610d9fef01a (diff)
downloadlr-ddc648c39a1d116cad5bddce3c74a4143cb139ab.tar.gz
lr-ddc648c39a1d116cad5bddce3c74a4143cb139ab.tar.xz
lr-ddc648c39a1d116cad5bddce3c74a4143cb139ab.zip
customizable time stamp for -l
-rw-r--r--README.md5
-rw-r--r--lr.116
-rw-r--r--lr.c24
3 files changed, 39 insertions, 6 deletions
diff --git a/README.md b/README.md
index d40daf8..50c3291 100644
--- a/README.md
+++ b/README.md
@@ -43,11 +43,14 @@ Over ls:
 
 ## Usage:
 
-	lr [-0|-F|-l|-S|-f FMT] [-D] [-H|-L] [-1AGQdhsx] [-U|-o ORD] [-t TEST]* PATH...
+	lr [-0|-F|-l [-TA|-TC|-TM]|-S|-f FMT] [-D] [-H|-L] [-1AGQdhsx] [-U|-o ORD] [-t TEST]* PATH...
 
 * `-0`: output filenames seperated by NUL bytes (implies `-Q`).
 * `-F`: output filenames and an indicator of their file type (`*/=>@|`).
 * `-l`: long output ala `ls -l`.
+* `-TA`: with `-l`, output atime.
+* `-TC`: with `-l`, output ctime.
+* `-TM`: with `-l`, output mtime (default).
 * `-S`: BSD stat(1)-inspired output.
 * `-f FMT`: custom formatting, see below.
 * `-D`: depth first traversal. `prune` does not work, but `entries`
diff --git a/lr.1 b/lr.1
index 6c31017..6aa9817 100644
--- a/lr.1
+++ b/lr.1
@@ -6,7 +6,8 @@
 .Nd list files, recursively
 .Sh SYNOPSIS
 .Nm
-.Op Fl 0 | Fl F | Fl l | Fl S | Fl f Ar fmt
+.Op Fl 0 | Fl F | Fl l Oo Fl TA | Fl TC | Fl TM Oc | Fl S | Fl f Ar fmt
+.br
 .Op Fl D
 .Op Fl H | Fl L
 .Op Fl 1AGQdhsx
@@ -29,6 +30,19 @@ Output filenames and an indicator of their file type (one of
 .It Fl l
 Long output ala
 .Ic ls -l .
+.It Fl TA
+With
+.Fl l ,
+print atime.
+.It Fl TC
+With
+.Fl l ,
+print ctime.
+.It Fl TM
+With
+.Fl l ,
+print mtime.
+This is the default.
 .It Fl S
 Output inspired by
 BSD
diff --git a/lr.c b/lr.c
index f21cefc..3756eac 100644
--- a/lr.c
+++ b/lr.c
@@ -72,6 +72,7 @@ static int hflag;
 static int lflag;
 static int sflag;
 static int xflag;
+static char Tflag = 'M';
 
 static char *argv0;
 static char *format;
@@ -84,7 +85,7 @@ static size_t prefixl;
 static char default_ordering[] = "n";
 static char default_format[] = "%p\\n";
 static char type_format[] = "%p%F\\n";
-static char long_format[] = "%M%x %n %u %g %s %TF %TR %p%F%l\n";
+static char long_format[] = "%M%x %n %u %g %s %\324F %\324R %p%F%l\n";
 static char zero_format[] = "%p\\0";
 static char stat_format[] = "%D %i %M %n %u %g %R %s \"%Ab %Ad %AT %AY\" \"%Tb %Td %TT %TY\" \"%Cb %Cd %CT %CY\" %b %p\n";
 
@@ -1421,6 +1422,7 @@ color_name_on(const char *f, mode_t m)
 		fg256(154);
 }
 
+// unused format codes: BEHJKLNOQVWXZ achjoqrvwz
 void
 print_format(struct fileinfo *fi)
 {
@@ -1510,10 +1512,14 @@ print_format(struct fileinfo *fi)
 			break;
 		case 'A':
 		case 'C':
-		case 'T': {
+		case 'T':
+		case '\324': /* Meta-T */ {
 			char tfmt[3] = "%\0\0";
 			char buf[256];
 
+			if (*s == '\324')
+				*s = Tflag;
+
 			time_t t = (*s == 'A' ? fi->sb.st_atime :
 			    *s == 'C' ? fi->sb.st_ctime :
 			    fi->sb.st_mtime);
@@ -1727,6 +1733,15 @@ traverse(const char *path)
 	return recurse(pathbuf, 0);
 }
 
+static char
+timeflag(char *arg)
+{
+	if ((arg[0] == 'A' || arg[0] == 'C' || arg[0] == 'M') && !arg[1])
+		return arg[0];
+	fprintf(stderr, "%s: -T only accepts A, C or M as argument.\n", argv0);
+	exit(2);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -1738,7 +1753,7 @@ main(int argc, char *argv[])
 	argv0 = argv[0];
 	now = time(0);
 
-	while ((c = getopt(argc, argv, "01ADFGHLQSUdf:lho:st:x")) != -1)
+	while ((c = getopt(argc, argv, "01ADFGHLQST:Udf:lho:st:x")) != -1)
 		switch(c) {
 		case '0': format = zero_format; Qflag++; break;
 		case '1': expr = chain(expr, EXPR_AND, parse_expr("depth == 0 || prune")); break;
@@ -1750,6 +1765,7 @@ main(int argc, char *argv[])
 		case 'L': Lflag++; break;
 		case 'Q': Qflag++; break;
 		case 'S': format = stat_format; break;
+		case 'T': Tflag = timeflag(optarg); break;
 		case 'U': Uflag++; break;
 		case 'd': expr = chain(expr, EXPR_AND, parse_expr("type == d && prune || print")); break;
 		case 'f': format = optarg; break;
@@ -1760,7 +1776,7 @@ main(int argc, char *argv[])
 		case 't': expr = chain(expr, EXPR_AND, parse_expr(optarg)); break;
 		case 'x': xflag++; break;
 		default:
-			fprintf(stderr, "Usage: %s [-0|-F|-l|-S|-f FMT] [-D] [-H|-L] [-1AGQdhsx] [-U|-o ORD] [-t TEST]* PATH...\n", argv0);
+			fprintf(stderr, "Usage: %s [-0|-F|-l [-TA|-TC|-TM]|-S|-f FMT] [-D] [-H|-L] [-1AGQdhsx] [-U|-o ORD] [-t TEST]* PATH...\n", argv0);
 			exit(2);
 		}