On Fri, Jan 07, 2011 at 05:29:32AM -0600, David Champion wrote:
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.

Outstanding! I didn't notice a slowdown from the extra exec, but saving cycles isn't a bad thing if you don't have to sacrifice clarity.

I went a little bit crazy with this, and now have different formats for less than a day old, more than a day but less than a week old, more than a week but less than 30 days, and more than 30 days. I've attached it.

Here's a (censored) view of my index right before I started this message:

 102     12/16/10 xx...@xxxxxx.xx (   8) xxxxx - xxx xxxxxx.xxxxxxxx xxxx
 103   +   Dec 27 xxxx xxx xxx xx (  80) xxxx xx xxxxxxx xx xxxxxxxx
 104   +   Jan 03 xxxxxx xxx      (  98) xx: xxxxxx xxx xxxxxxxx
 105   T   Jan 04 xxxxxx xxxxxxxx ( 104) xxxxxxxxxxx xxxxxxx xxxxxxx
 106   L   Jan 07 xxxxx xxxxxxxx  (  54) xx: xxxxxx xxxxxx: xxxx xxx xxxxx, 
xxxx xxx xxxxxx.
 107       Jan 07 xxxxx xxxxxxxx  (  92) xxxx xx xxxx xxxxxxxxxx xxxx xxxxx 
xxxx 1/4 xxxxxxx
 108   +   Jan 12 xxxxxxx xxxxx x (  82) xxxxxxxxxx xx xxxxxxx xx xxxxxxxx
 109   +   Jan 13 xxxxx, xxxxx    (  23) xx: xxxxxxxx!
 110   +  Mon 9pm xxxxx xxxxxxx   (  20) xx: x4x xxx xx (xxx: xxxxxxxxx 
xxxxxxxx/ xxxxxxxx)
 111   T  Tue 2pm xxxx xxxxxx     ( 153) xxxxxxx xxx xxxx xxxxx
 112   T Wed 11am xxx             ( 157) xxxxxx
 113      Wed 3pm xxxxx xxxxxx    ( 266) xxxxxxxx xxx xxx, xxxxxx 
x_xxxxxxxxxx_xxxx_xxxxxx
 114   T   8:59pm xxxxx xxxxxxxx  (  21) xxxxxxxxx xxx xxx xxxxxxx xxxxxx xxxxx 
xxxxxxx
 115   +   9:11pm xxxxxx xxxxxxx  (  50) xx: xxxx xxxx

The script relies on Unix epoch seconds for the calculation, so the break point is 24 hours ago, 168 hours ago, etc, not day boundaries, but that's what I want. I think day boundaries would be possible with some work on the msg_age calculation, maybe "$(( ($now/86400) - ($msg_date/86400) ))"?

Ed
#!/bin/bash
# format_date
#
# In .muttrc:
# set index_format="/path/to/format_date '%[%s]' '%<%s>' |"
#
# 
http://groups.google.com/group/de.comm.software.mailreader.misc/browse_thread/thread/ab966bddc0b424
 46/421549103438b830?q=#421549103438b830
# via Andreas Kneib <apo...@web.de>
# mutt-users Message-ID: <20110105233817.ga23...@andreas.kneib.biz>
# Improvements by
# David Champion <d...@uchicago.edu>
# Ed Blackman <e...@edgewood.to>

msg_date="$1"                           # datetime of message in local timezone 
in epoch seconds
now="$2"                                # current time in local timezone in 
epoch seconds
msg_age="$(( ($now - $msg_date) / 86400 ))"             # age of message in 
integer days

if [ $msg_age -ge 30 ]; then
  format="%[%m/%d/%y]"                  # '01/20/11'
elif [ $msg_age -ge 7 ]; then
  format="%8[%b %d]"                    # '  Jan 20'
elif [ $msg_age -ge 1 ]; then
  format="%8[%a %-I%P]"                 # ' Thu 6pm'
else
  format="%[ %_I:%M%P]"                 # '  6:41pm'
fi

echo "%4C %Z $format %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"

Attachment: signature.txt
Description: Digital signature

Reply via email to