* On 07 Jan 2011, du yang wrote: 
> Hi,
> 
> I improved the script to fulfill the author's the expectation(just display 
> time for today's mails),
> only 'if condition' changed.
> ...
> if [ $(date -d "$(date '+%Y-%m-%d')" "+%s") -gt $epoch ]; then
>      echo "%4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"

It occurs to me that there is an optimization for this specific case.
Since the desired breaking point is simply "the beginning of today",
you can exploit the fact that %Y%m%d is a monotonic function when you
interpret it as an integer.  (That is, it alpha-sorts and integer-sorts
in the same order as it date-sorts.)

    set index_format="./format_date.sh '%[%Y%m%d]' |"

    #!/bin/sh

    if [ $1 -eq `date +%Y%m%d` ]; then
         echo "%4C %Z %{   %H:%M} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
    else
         echo "%4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
    fi

I'm still not sure about performance though.  I have a 58-row terminal
and do not want to run 116 processes for each page view in mutt. :)



Aha, finally I have discovered a use for mutt's %<strftime> expando.
You can optimize this one step further.

    set index_format="./format_date.sh '%[%Y%m%d]' '%<%Y%m%d>' |"

    #!/bin/sh

    if [ $1 -eq $2 ]; then
         echo "%4C %Z %{   %H:%M} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
    else
         echo "%4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
    fi

A single exec per message now; that's as good as it gets without
patching mutt.

I 'stole' %<strftime> for my nested_if patch because it looked
completely useless, so if you happen to be using nested_if, this latter
version won't work.  Now that I see a purpose for %<...> I'll have to
revisit nested_if.  (Unfortunately all the paired symbols are used
already.)

-- 
David Champion  *  [email protected]  *  IT Services  *  University of Chicago

Reply via email to