I am trying to use Champion and Blackman's nice bash script,
which I have appended below, to assign different date formats
according to the age of the date.
I have tested each of the conditionals of this script and
it seems to work from the shell. However when I try to use it
from the mutt command line, it sets the desired format ONLY
for the messages which are less than one day old. More accurately
it applies the "less-than-one-day-old" to ALL messages.
I'll appreciate any suggestion about what I am doing wrong.
##############################
#!/bin/bash
#format_date
# use with
# set index_format="format_date.sh '%[%s]' |"
# test with
# format_date.sh 1321504390 1321704390 <--- 2 days
# format_date.sh 1321504390 1322704390 <--- 13 days
# Improvements by
# David Champion <[email protected]>
# Ed Blackman <[email protected]>
msg_date="$1" # datetime of message in epoch seconds
now="$2" # local current time in epoch seconds
msg_age="$(( ($now - $msg_date) / 86400 ))" # age of message integer days
if [ $msg_age -ge 30 ]; then
format="%[%d/%b/%y]" # '20/Jan/11'
elif [ $msg_age -ge 7 ]; then
format="%8[%d %b]" # ' 20 Jan'
elif [ $msg_age -ge 1 ]; then
format="%8[%a %-H:%M]" # 'Thu 14:21'
else
format="%[ %_H:%M]" # ' 18:21'
fi
echo "%4C %Z $format %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
##############################