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

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

Date: Fri, 29 Oct 2010 10:42:12 +0200

To: notmuch@notmuchmail.org

Cc:

From: François Gannaz


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

Thread: