about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--scoop.19
-rw-r--r--scoop.c14
2 files changed, 18 insertions, 5 deletions
diff --git a/scoop.1 b/scoop.1
index 823e5ee..a9a40c0 100644
--- a/scoop.1
+++ b/scoop.1
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl pqv
+.Op Fl gpqv
 .Op Fl D Ar date
 .Op Fl N Ar network
 .Op Fl T Ar target
@@ -43,7 +43,9 @@ The arguments are as follows:
 Match events which occurred on
 .Ar date ,
 of the format
-.Ar YYYY-MM-DD .
+.Ar YYYY-MM-DD
+or the keyword
+.Cm now .
 .
 .It Fl N Ar network
 Match events from contexts on
@@ -72,6 +74,9 @@ The database must have been initialized by
 The default path is as in
 .Xr litterbox 1 .
 .
+.It Fl g
+Group events by context.
+.
 .It Fl h Ar host
 Match events from users with the hostname
 .Ar host .
diff --git a/scoop.c b/scoop.c
index 5855e70..1f031e2 100644
--- a/scoop.c
+++ b/scoop.c
@@ -29,6 +29,7 @@ static const char *Inner = SQL(
 	SELECT
 		contexts.network,
 		contexts.name AS context,
+		// TODO: Replace with a strftime and option.
 		date(events.time) || 'T' || time(events.time) || 'Z' AS time,
 		events.type,
 		names.nick,
@@ -66,6 +67,11 @@ static const char *Outer = SQL(
 	ORDER BY time, event
 );
 
+static const char *Group = SQL(
+	SELECT * FROM results
+	ORDER BY network, context, time, event
+);
+
 typedef void Format(
 	const char *network, const char *context, const char *time, enum Type type,
 	const char *nick, const char *user, const char *target, const char *message
@@ -176,15 +182,17 @@ int main(int argc, char *argv[]) {
 	const char *target = NULL;
 	const char *search = NULL;
 	int limit = -1;
+	bool group = false;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "D:N:T:c:d:h:l:n:pqst:u:v"))) {
+	while (0 < (opt = getopt(argc, argv, "D:N:T:c:d:gh:l:n:pqst:u:v"))) {
 		switch (opt) {
 			break; case 'D': date = optarg;
 			break; case 'N': network = optarg;
 			break; case 'T': target = optarg;
 			break; case 'c': context = optarg;
 			break; case 'd': path = optarg;
+			break; case 'g': group = true;
 			break; case 'h': host = optarg;
 			break; case 'l': limit = strtol(optarg, NULL, 0);
 			break; case 'n': nick = optarg;
@@ -244,13 +252,13 @@ int main(int argc, char *argv[]) {
 		snprintf(
 			sql, sizeof(sql),
 			"WITH results AS (%s AND %s %s) %s;",
-			Inner, Search, Limit, Outer
+			Inner, Search, Limit, (group ? Group : Outer)
 		);
 	} else {
 		snprintf(
 			sql, sizeof(sql),
 			"WITH results AS (%s %s) %s;",
-			Inner, Limit, Outer
+			Inner, Limit, (group ? Group : Outer)
 		);
 	}