>>>>> "RFP" == Rob Feztaa Park <[EMAIL PROTECTED]> writes:
RFP> Alas! Bernard Massot spake thus:
RFP> > On Fri, Apr 19, 2002 at 02:13:31PM -0600, Rob 'Feztaa' Park wrote:
RFP> > > Then use the message-hooks idea that I posted, but replace the
RFP> > > `date +%m` bit with something that gives you the day-of-month of last
RFP> > > monday.
RFP> >
RFP> > I can't be sure the mail was written the previous monday.
RFP> > I may answer an old mail.
RFP>
RFP> Then I guess you'll just have to settle on speaking broken brezhoneg
RFP> then, won't you?
Oh, heavens.
This patch lets any variable that's subjected to %-expansion be a pipe,
just like filenames ($signature, source, etc.) can. With this patch,
Bernard can use
set attribution="~/.mutt/deiziat.sh %[%w] %d, %n en deus skrivet: |"
With something like:
#!/bin/sh
article="ar"
[ "$1" eq 1 ] && article="al"
shift
echo -n "D'$article $*"
and the attribution will be whatever deiziat.sh says. %-expandos are
expanded *before* the piped script is run (so watch your quoting), and
at the time that the variable is evaluated (not when the rcfile is
read).
I've wanted this kind of functionality a few times with other variables,
so maybe this approach is good. At the worst, it makes quoting rules
*much* simpler.
Note that if the text returned by your piped command ends in "%", the
command output will be recycled through the formatter. This means that
you can embed more mutt-style %-expandos in your command output, if you
like, so that the format sequences used can depend on the values of
other format sequences.
Watch out for newlines in your output -- the patch does not discard
them. And watch out for infinite loops. :)
Note also that you do probably do **NOT** want to use a piped command
for variables like $index_format which are evaluated frequently,
although someone might find some neat trick you can achieve with that.
Here's another fun example. "afh.sh" is attached.
set attribution="afh.sh -a '%n' '<%a>' |"
set indent_string="afh.sh -q '%n' |"
--
-D. [EMAIL PROTECTED] NSIT University of Chicago
diff -ur mutt-1.3.28-base/muttlib.c mutt-1.3.28-fmtpipe/muttlib.c
--- mutt-1.3.28-base/muttlib.c Sun Jan 13 02:52:15 2002
+++ mutt-1.3.28-fmtpipe/muttlib.c Sat Apr 20 13:35:24 2002
@@ -907,6 +907,10 @@
char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
size_t wlen, count, len;
+ pid_t pid;
+ FILE *filter;
+ int n, dofilter = 0;
+ char *recycler;
destlen--; /* save room for the terminal \0 */
wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
@@ -1078,6 +1082,20 @@
wptr++;
wlen++;
}
+ else if (*src == '|')
+ {
+ if (*++src != '\0')
+ {
+ /* Not end of string - copy '|' */
+ *wptr++ = '|';
+ wlen++;
+ }
+ else
+ {
+ /* End of string - wants to be filtered */
+ dofilter = 1;
+ }
+ }
else
{
*wptr++ = *src++;
@@ -1085,6 +1103,39 @@
}
}
*wptr = 0;
+
+ /* Filter this string? */
+ if (dofilter)
+ {
+ wptr = dest; /* reset write ptr */
+ wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
+ if (pid = mutt_create_filter(dest, NULL, &filter, NULL))
+ {
+ n = fread(dest, 1, destlen /* already decremented */, filter);
+ fclose(filter);
+ dest[n] = '\0';
+ if (pid != -1)
+ mutt_wait_filter(pid);
+
+ /* If ends with '%', recycle through FormatString :P */
+ /* To really end with '%', use "%%" */
+ if (dest[--n] == '%')
+ {
+ dest[n] = '\0'; /* remove '%' */
+ if (dest[--n] != '%')
+ {
+ recycler = safe_strdup(dest);
+ mutt_FormatString(dest, destlen++, recycler, callback, data, flags);
+ safe_free((void **) &recycler);
+ }
+ }
+ }
+ else
+ {
+ /* Filter failed; erase write buffer */
+ *wptr = '\0';
+ }
+ }
#if 0
if (flags & M_FORMAT_MAKEPRINT)
#!/bin/sh
##
## Attributions from Hell.
##
initials () {
for word in $*; do
letter=`echo $word | cut -c1`
out="$out$letter"
done
echo $out;
}
attribute () {
inits=`initials "$1"`
cat <<GOD_HAVE_MERCY_ON_MY_SOUL
>>>>> "$inits" == $@ writes:
GOD_HAVE_MERCY_ON_MY_SOUL
}
quote () {
inits=`initials "$@"`
case "`echo -n`" in
-n) echo "$inits> \c";;
*) echo -n "$inits> ";;
esac
}
mode=$1
shift
case "$mode" in
-a) attribute "$1" "$2";;
-q) quote "$1";;
esac