diff --git a/man/mu-find.1 b/man/mu-find.1 index c8291939..738d24f5 100644 --- a/man/mu-find.1 +++ b/man/mu-find.1 @@ -1,4 +1,4 @@ -.TH MU FIND 1 "June 2013" "User Manuals" +.TH MU FIND 1 "September 2013" "User Manuals" .SH NAME @@ -343,6 +343,10 @@ Note, if you specify a sortfield, by default, messages are sorted in reverse (descending) order (e.g., from lowest to highest). This is usually a good choice, but for dates it may be more useful to sort in the opposite direction. +.TP +\fB\-n\fR, \fB\-\-maxnum=\fR +If > 0, display maximally that number of entries. If not specified, all matching entries are displayed. + .TP \fB\-\-summary-len=\fR If > 0, use that number of lines of the message to provide a summary. diff --git a/mu/mu-cmd-find.c b/mu/mu-cmd-find.c index 05ec4ad8..6b9ff452 100644 --- a/mu/mu-cmd-find.c +++ b/mu/mu-cmd-find.c @@ -132,7 +132,7 @@ run_query (MuQuery *xapian, const gchar *query, MuConfig *opts, GError **err) if (opts->threads) qflags |= MU_QUERY_FLAG_THREADS; - iter = mu_query_run (xapian, query, sortid, -1, qflags, err); + iter = mu_query_run (xapian, query, sortid, opts->maxnum, qflags, err); return iter; } @@ -598,6 +598,8 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err) MuMsg *msg; + if (count == opts->maxnum) + break; msg = get_message (iter, opts->after); if (!msg) break; diff --git a/mu/mu-config.c b/mu/mu-config.c index bfd1e104..dbad5d11 100644 --- a/mu/mu-config.c +++ b/mu/mu-config.c @@ -205,6 +205,8 @@ config_options_group_find (void) {"sortfield", 's', 0, G_OPTION_ARG_STRING, &MU_CONFIG.sortfield, "field to sort on", ""}, + {"maxnum", 'n', 0, G_OPTION_ARG_INT, &MU_CONFIG.maxnum, + "number of entries to display in the output", ""}, {"threads", 't', 0, G_OPTION_ARG_NONE, &MU_CONFIG.threads, "show message threads", NULL}, {"bookmark", 'b', 0, G_OPTION_ARG_STRING, &MU_CONFIG.bookmark, @@ -702,6 +704,8 @@ mu_config_init (int *argcp, char ***argvp, GError **err) memset (&MU_CONFIG, 0, sizeof(MU_CONFIG)); + MU_CONFIG.maxnum = -1; /* By default, output all matching entries. */ + if (!parse_cmd (argcp, argvp, err)) goto errexit; diff --git a/mu/mu-config.h b/mu/mu-config.h index dfd278d2..08636246 100644 --- a/mu/mu-config.h +++ b/mu/mu-config.h @@ -123,6 +123,7 @@ struct _MuConfig { /* options for querying 'find' (and view-> 'summary') */ gchar *fields; /* fields to show in output */ gchar *sortfield; /* field to sort by (string) */ + int maxnum; /* max # of entries to print */ gboolean reverse; /* sort in revers order (z->a) */ gboolean threads; /* show message threads */