Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Sep 2008 07:39:15 -0700
From:      Jeremy Chadwick <koitsu@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Extending find(1) to support -printf
Message-ID:  <20080905143915.GA60002@icarus.home.lan>
In-Reply-To: <20080905101253.GA53396@icarus.home.lan>
References:  <20080905101253.GA53396@icarus.home.lan>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Sep 05, 2008 at 03:12:53AM -0700, Jeremy Chadwick wrote:
> Also, some folks on #bsdports asked why I was bothering with this in the
> first place: mutt supports backticks to run shell commands inside of
> a muttrc file.  See "Building a list of mailboxes on the fly" below:
> 
> http://wiki.mutt.org/?ConfigTricks
> 
> Note the find ... -printf '%h ' method.  I can accomplish (just
> about) the same using `echo $HOME/Maildir/*`, but if I want to
> exclude an entry, I can't use | grep -v, because mutt doesn't support
> pipes within backticks.  :-)

Follow-up:

mutt's backtick support does in fact respect pipes.  My echo|grep -v was
doing exactly what I requested: the grep -v was removing all output of
the echo, since echo returned the results in a space-delimited format,
not one per line.  Hence, "mailboxes" was being executed without any
arguments.

Equally as frustrating, mutt's backtick support will only honour the
first line of input.  If a backticked command returns multiple lines,
only the first is read; the rest are ignored.  This makes using BSD find
annoying, since find always outputs results terminated with a newline.
One of my peers uses find | perl -ne 'chomp; print "=", $_, " "' to deal
with this limit, which is quite disgusting.

I realise there are workarounds for the dilemma (e.g. write a shell
script that provides the exact output needed), but it seems like one
could kill two birds with one stone by extending BSD find to support
-printf, which does not output a newline unless \n is used within the
output formatting.  (This also explains why the Mutt Wiki entry uses
-printf '%h ', note the space.)

-- 
| Jeremy Chadwick                                jdc at parodius.com |
| Parodius Networking                       http://www.parodius.com/ |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.              PGP: 4BD6C0CB |




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080905143915.GA60002>