* Notmuch scripters rejoice! New "notmuch search --output=(...)"
@ 2010-10-28 19:24 Carl Worth
2010-10-29 7:13 ` Sebastian Spaeth
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Carl Worth @ 2010-10-28 19:24 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]
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@intel.com
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Notmuch scripters rejoice! New "notmuch search --output=(...)"
2010-10-28 19:24 Notmuch scripters rejoice! New "notmuch search --output=(...)" Carl Worth
@ 2010-10-29 7:13 ` Sebastian Spaeth
2010-10-29 8:42 ` François Gannaz
2010-10-30 0:24 ` Bryan Hunt
2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Spaeth @ 2010-10-29 7:13 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 402 bytes --]
On Thu, 28 Oct 2010 12:24:45 -0700, Carl Worth <cworth@cworth.org> wrote:
> --output=(summary|threads|messages|files|tags)
> for spamfile in $(notmuch search tag:spam); do
> rm $spamfile
> done
Wow, that is very useful thanks. This will creating scripts much easier
indeed.
As for count, I would leave that in, it's seems much nicer than a |wc -l
Thanks! Keep the good stuff coming.
Sebastian
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Notmuch scripters rejoice! New "notmuch search --output=(...)"
2010-10-28 19:24 Notmuch scripters rejoice! New "notmuch search --output=(...)" Carl Worth
2010-10-29 7:13 ` Sebastian Spaeth
@ 2010-10-29 8:42 ` François Gannaz
2010-10-30 0:24 ` Bryan Hunt
2 siblings, 0 replies; 4+ messages in thread
From: François Gannaz @ 2010-10-29 8:42 UTC (permalink / raw)
To: notmuch
On 2010-10-28, Carl Worth <cworth@cworth.org> wrote:
> 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.
Going from :
my $notmuch = `notmuch show @ARGV`;
my @filenames = ();
while ($notmuch =~ /^\x{0c}message{ .+filename:(.+)$/mg) {
push @filenames, $1;
}
to :
my @filenames = split /\n/, `notmuch search --output=files @ARGV`;
Thanks, that will clearly enhance my script.
--
François
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Notmuch scripters rejoice! New "notmuch search --output=(...)"
2010-10-28 19:24 Notmuch scripters rejoice! New "notmuch search --output=(...)" Carl Worth
2010-10-29 7:13 ` Sebastian Spaeth
2010-10-29 8:42 ` François Gannaz
@ 2010-10-30 0:24 ` Bryan Hunt
2 siblings, 0 replies; 4+ messages in thread
From: Bryan Hunt @ 2010-10-30 0:24 UTC (permalink / raw)
To: Carl Worth, notmuch
On Thu, 28 Oct 2010 12:24:45 -0700, Carl Worth <cworth@cworth.org> wrote:
> 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)
>
That is a cool feature.
Bryan Hunt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-30 0:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-28 19:24 Notmuch scripters rejoice! New "notmuch search --output=(...)" Carl Worth
2010-10-29 7:13 ` Sebastian Spaeth
2010-10-29 8:42 ` François Gannaz
2010-10-30 0:24 ` Bryan Hunt
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).