Search the web
Sign In
New User? Sign Up
mutt-users · MUTT- text-based MIME mail client
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
quotes   Message List  
Reply | Forward Message #30735 of 49484 |
Re: quotes -> set attribution=`script`

>>>>> "RFP" == Rob Feztaa Park <feztaa@...> 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. dgc@... NSIT University of Chicago


Sat Apr 20, 2002 7:01 pm

dgc@...
Send Email Send Email

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


Forward
Message #30735 of 49484 |
Expand Messages Author Sort by Date

hi, I've got a prb with quoting, in my .muttrc I wrote : send-hook user@... \ "set attribution = \"D'`if [ \`date '+%w'\` = 1 ];then echo al;else echo ...
Bernard Massot
bmassot@...
Send Email
Apr 18, 2002
1:20 pm

... shell parsing is different from mutt's parsing. what else is new? try this: set attribution=`script` im mutt, of course. anyway, words in the...
Sven Guckes
guckes@...
Send Email
Apr 18, 2002
7:10 pm

... Easy fix. In your muttrc do this: "set attribution=`script %d`", and then in the script, $* will have the date of the mail in it. -- Rob 'Feztaa' Park ...
Rob 'Feztaa' Park
feztaa@...
Send Email
Apr 18, 2002
10:55 pm

... that's exactly what I've done but the script sees the litteral string "%d" instead of the date ! my script is called like that: ...
Bernard Massot
bmassot@...
Send Email
Apr 19, 2002
1:39 pm

... Ok, I've got it ;) The set attribution thing is expanded when mutt starts, not when the message is sent. That's why %d is being passed to the script: mutt ...
Rob 'Feztaa' Park
feztaa@...
Send Email
Apr 19, 2002
9:06 pm

... good idea but I need a way to give the script the date of the mail if I launch it with %d, the script doesn't see the date but the string "%d" ... off...
Bernard Massot
bmassot@...
Send Email
Apr 19, 2002
1:34 am

... It was along these lines, IIRC: If (date written=today) then quote normal attribution Else quote some other attribution... -- [Simon White. vim/mutt....
Simon White
simon@...
Send Email
Apr 19, 2002
6:31 pm

... In that case, why not just use message-hooks with ~d or ~r in the pattern? Something like this: message-hook . "set attribution='On %d, %n...
Rob 'Feztaa' Park
feztaa@...
Send Email
Apr 19, 2002
7:08 pm

... it's not that ! it's : If (date written=a_monday) then quote with "D'al ..." Else quote with "D'ar ..." In brezhoneg language, you must write "d'al lun"...
Bernard Massot
bmassot@...
Send Email
Apr 19, 2002
8:16 pm

... Then use the message-hooks idea that I posted, but replace the `date +%m` bit with something that gives you the day-of-month of last monday. -- Rob...
Rob 'Feztaa' Park
feztaa@...
Send Email
Apr 20, 2002
12:55 am

... I'm sure Outlook will support it one day. HA! Now, how about using just WHATEVER in the attribution and replacing it from inside your editor? Sven...
Sven Guckes
guckes@...
Send Email
Apr 20, 2002
1:56 am

... I managed to do it, with this ugly hack : $ tail -1 ~/.vimrc autocmd BufRead /tmp/mutt*[0-9] source ~/.mutt/mutt.vim $ cat /home/bernard/.mutt/mutt.vim "...
Bernard Massot
bmassot@...
Send Email
Apr 23, 2002
12:42 am

* On 2002.04.22, in <20020423004208.GA10973@bernard>, ... Did you try my patch? It should make it pretty easy. set attribution="if [ %[%w] = 1 ]; then echo -n...
David Champion
dgc@...
Send Email
Apr 24, 2002
6:08 pm

... It works, thank you ! But I want it to apply in a send-hook. How can quote it properly ? I tried different combinations of simple quotes, double quotes and...
Bernard Massot
bmassot@...
Send Email
Apr 24, 2002
9:45 pm

* On 2002.04.24, in <20020424212120.GA7108@bernard>, ... Two ideas: 1. Place this set command in a separate file -- say, ~/.muttrc-brezhoneg. Put your current...
David Champion
dgc@...
Send Email
Apr 24, 2002
10:01 pm

... I've chosen this one since I also have to set $locale and $date_format in these cases. Is there a chance that this patch will be a part of the next mutt...
Bernard Massot
bmassot@...
Send Email
Apr 24, 2002
11:39 pm

Rob, et al -- ...and then Feztaa said... % % Alas! Bernard Massot spake thus: % > > Easy fix. In your muttrc do this: "set attribution=`script %d`", and ... % ...
David T-G
davidtg-muttusers@...
Send Email
Apr 19, 2002
7:13 pm

... I can't be sure the mail was written the previous monday. I may answer an old mail. -- Bernard Massot...
Bernard Massot
bmassot@...
Send Email
Apr 19, 2002
9:34 pm

... Then I guess you'll just have to settle on speaking broken brezhoneg then, won't you? -- Rob 'Feztaa' Park feztaa@... -- Boy! Eucalyptus!...
Rob 'Feztaa' Park
feztaa@...
Send Email
Apr 19, 2002
11:10 pm

... 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...
David Champion
dgc@...
Send Email
Apr 20, 2002
7:01 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help