* On 21 Nov 2011, von der Burg wrote: 
> 
>   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.


Caveats: I remember this coming up but I don't remember exactly when or
in what context.  (If you have a URL where you got this I could double
check.)  And I don't use the script in question, since I get the same
functionality (faster) through a patch to mutt's code.

It looks to me like there's an error in the documentation:

> #  use with
> #        set index_format="format_date.sh '%[%s]' |"
> # test with 
> #  format_date.sh 1321504390  1321704390     <---  2 days

There should be two arguments to the script, but the $index_format
there passes only one.  You also need the current timestamp.

The simplest solution is probably to change the script: replace
this line:
    now="$2"                # local current time in epoch seconds
with this:
    now=$(date +%s)

But I haven't tested this.  Maybe Ed will see this and have a better
answer.

>      
> 
> 
> ##############################
> #!/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 <d...@uchicago.edu>
> # Ed Blackman <e...@edgewood.to>
>   
>    
>   
>   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%"
> ##############################
>   
>   
>   
> 

-- 
David Champion • d...@uchicago.edu • IT Services • University of Chicago

Reply via email to