Notmuch scripters rejoice! New "notmuch search --output=(...)"

Carl Worth cworth at cworth.org
Thu Oct 28 12:24:45 PDT 2010


I just added a new feature to notmuch that I've been wanting for a very
long time. It's a new option to "notmuch search" as follows:

	--output=(summary|threads|messages|files|tags)

The "summary" value is the default and behaves as "notmuch search"
always has, (printing a one-line summary with a bunch of information
about each thread).

Each of the other options causes "notmuch search" to print only a single
value, (thread ID, message ID, filename, or tag), one-per-line[*]. This
is intended to be useful in scripts to do things as follows:

	for spamfile in $(notmuch search tag:spam); do
		rm $spamfile
	done

Or what have you.

I hope people find this useful. See "notmuch help search" for more
details.

Oh, and with this change, the existing "notmuch search-tags" command is
redundant, (it behaves in the same way as "notmuch search
--output=tags"). I think I'll drop search-tags from the list of
documented commands, (but it probably won't be too painful to continue
to support it as a deprecated command name).

I'm also wondering about "notmuch count". With the new feature above,
one could count matching messages as "notmuch count" does with something
like:

	notmuch search --output=messages <search-terms> | wc -l

That's a bit of a mouthful compared to "notmuch count", but the new
command also enables the counting of matching threads:

	notmuch search --output=threads <search-terms> | wc -l

which is something that "notmuch count" doesn't do.

I don't think I'll change "notmuch count". It's probably still useful,
(doing what it's documented to do), and it's also likely much more
efficient than either of the above "notmuch search" pipelines.

-Carl

[*] Or, when under the influence of --format=json, the results are
printed as a single JSON array.

-- 
carl.d.worth at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20101028/e7c0a790/attachment.pgp>


More information about the notmuch mailing list