notmuch search: Add a new "notmuch search --output=files"

Yet another thing that will be extremely handy for scripts.
This commit is contained in:
Carl Worth 2010-10-28 11:33:55 -07:00
parent 6dcb7592e3
commit 5331161749
3 changed files with 27 additions and 3 deletions

View file

@ -24,6 +24,7 @@ typedef enum {
OUTPUT_SUMMARY, OUTPUT_SUMMARY,
OUTPUT_THREADS, OUTPUT_THREADS,
OUTPUT_MESSAGES, OUTPUT_MESSAGES,
OUTPUT_FILES,
OUTPUT_TAGS OUTPUT_TAGS
} output_t; } output_t;
@ -240,7 +241,8 @@ do_search_threads (const void *ctx,
static int static int
do_search_messages (const void *ctx, do_search_messages (const void *ctx,
const search_format_t *format, const search_format_t *format,
notmuch_query_t *query) notmuch_query_t *query,
output_t output)
{ {
notmuch_message_t *message; notmuch_message_t *message;
notmuch_messages_t *messages; notmuch_messages_t *messages;
@ -259,7 +261,13 @@ do_search_messages (const void *ctx,
if (! first_message) if (! first_message)
fputs (format->item_sep, stdout); fputs (format->item_sep, stdout);
format->item_id (ctx, "id:", notmuch_message_get_message_id (message)); if (output == OUTPUT_FILES) {
format->item_id (ctx, "",
notmuch_message_get_filename (message));
} else { /* output == OUTPUT_MESSAGES */
format->item_id (ctx, "id:",
notmuch_message_get_message_id (message));
}
first_message = 0; first_message = 0;
@ -363,6 +371,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
output = OUTPUT_THREADS; output = OUTPUT_THREADS;
} else if (strcmp (opt, "messages") == 0) { } else if (strcmp (opt, "messages") == 0) {
output = OUTPUT_MESSAGES; output = OUTPUT_MESSAGES;
} else if (strcmp (opt, "files") == 0) {
output = OUTPUT_FILES;
} else if (strcmp (opt, "tags") == 0) { } else if (strcmp (opt, "tags") == 0) {
output = OUTPUT_TAGS; output = OUTPUT_TAGS;
} else { } else {
@ -414,7 +424,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
ret = do_search_threads (ctx, format, query, sort, output); ret = do_search_threads (ctx, format, query, sort, output);
break; break;
case OUTPUT_MESSAGES: case OUTPUT_MESSAGES:
ret = do_search_messages (ctx, format, query); case OUTPUT_FILES:
ret = do_search_messages (ctx, format, query, output);
break; break;
case OUTPUT_TAGS: case OUTPUT_TAGS:
ret = do_search_tags (ctx, notmuch, format, query); ret = do_search_tags (ctx, notmuch, format, query);

View file

@ -182,6 +182,13 @@ either one per line (--format=text) or as a JSON array
.RE .RE
.RS 4 .RS 4
.TP 4 .TP 4
.B files
Output the filenames of all messages matching the search terms, either
one per line (--format=text) or as a JSON array (--format=json).
.RE
.RS 4
.TP 4
.B tags .B tags
Output all tags that appear on any message matching the search terms, Output all tags that appear on any message matching the search terms,

View file

@ -186,6 +186,12 @@ command_t commands[] = {
"\t\tterms, either one per line (--format=text) or as a JSON array\n" "\t\tterms, either one per line (--format=text) or as a JSON array\n"
"\t\t(--format=json).\n" "\t\t(--format=json).\n"
"\n" "\n"
"\t\tfiles\n"
"\n"
"\t\tOutput the filenames of all messages matching the search\n"
"\t\tterms, either one per line (--format=text) or as a JSON array\n"
"\t\t(--format=json).\n"
"\n"
"\t\ttags\n" "\t\ttags\n"
"\n" "\n"
"\t\tOutput all tags that appear on any message matching the search\n" "\t\tOutput all tags that appear on any message matching the search\n"