Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 935FF429E32 for ; Fri, 28 Oct 2011 13:59:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KA0jZ0XY482X for ; Fri, 28 Oct 2011 13:59:49 -0700 (PDT) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 5A918429E21 for ; Fri, 28 Oct 2011 13:59:47 -0700 (PDT) Received: by mail-fx0-f53.google.com with SMTP id i28so4419077faa.26 for ; Fri, 28 Oct 2011 13:59:47 -0700 (PDT) Received: by 10.223.92.135 with SMTP id r7mr8801871fam.35.1319835587101; Fri, 28 Oct 2011 13:59:47 -0700 (PDT) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id j5sm19444105faf.14.2011.10.28.13.59.45 (version=SSLv3 cipher=OTHER); Fri, 28 Oct 2011 13:59:46 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [RFC PATCH 2/3] cli: add support for limiting the number of search results Date: Fri, 28 Oct 2011 23:59:30 +0300 Message-Id: X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: Cc: amdragon@mit.edu X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Oct 2011 20:59:51 -0000 Add command line parameter --maxitems=N to notmuch search to limit the number of displayed messages to N. These two are equal: $ notmuch search --output=messages --sort=newest-first --maxitems=10 SEARCH $ notmuch search --output=messages --sort=newest-first SEARCH | head As are these: $ notmuch search --output=messages --sort=oldest-first --maxitems=10 SEARCH $ notmuch search --output=messages --sort=oldest-first SEARCH | tail Note that N refers to the maximum amount of messages, even for --output=threads. Signed-off-by: Jani Nikula --- notmuch-search.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 6f04d9a..a3a6475 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -394,6 +394,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) const search_format_t *format = &format_text; int i, ret; output_t output = OUTPUT_SUMMARY; + unsigned int maxitems = 0; argc--; argv++; /* skip subcommand argument */ @@ -412,6 +413,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) fprintf (stderr, "Invalid value for --sort: %s\n", opt); return 1; } + } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) { + const char *p; + opt = argv[i] + sizeof ("--maxitems=") - 1; + maxitems = strtoul(opt, &p, 10); + if (*opt == '\0' || p == opt || *p != '\0') { + fprintf (stderr, "Invalid value for --maxitems: %s\n", opt); + return 1; + } } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) { opt = argv[i] + sizeof ("--format=") - 1; if (strcmp (opt, "text") == 0) { @@ -473,6 +482,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) } notmuch_query_set_sort (query, sort); + notmuch_query_set_maxitems (query, maxitems); switch (output) { default: -- 1.7.5.4