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

François Gannaz francois.gannaz at free.fr
Fri Oct 29 01:42:12 PDT 2010


On 2010-10-28, Carl Worth <cworth at 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


More information about the notmuch mailing list