Re: format string: time for today, date for others.

2011-01-20 Thread Ed Blackman

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...@xx.xx (   8) x - xxx xx. 
 103   +   Dec 27  xxx xxx xx (  80)  xx xxx xx 
 104   +   Jan 03 xx xxx  (  98) xx: xx xxx 
 105   T   Jan 04 xx  ( 104) xxx xxx xxx
 106   L   Jan 07 x   (  54) xx: xx xx:  xxx x, 
 xxx xx.
 107   Jan 07 x   (  92)  xx  xx  x 
 1/4 xxx
 108   +   Jan 12 xxx x x (  82) xx xx xxx xx 
 109   +   Jan 13 x, x(  23) xx: !
 110   +  Mon 9pm x xxx   (  20) xx: x4x xxx xx (xxx: x 
/ )
 111   T  Tue 2pm  xx ( 153) xxx xxx  x
 112   T Wed 11am xxx ( 157) xx
 113  Wed 3pm x xx( 266)  xxx xxx, xx 
x_xx__xx
 114   T   8:59pm x   (  21) x xxx xxx xxx xx x 
xxx
 115   +   9:11pm xx xxx  (  50) xx:  

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%


signature.txt
Description: Digital signature


Re: format string: time for today, date for others.

2011-01-07 Thread Yue Wu
On Wed, Jan 05, 2011 at 04:32:44PM -0600, David Champion wrote:
 * On 05 Jan 2011, Yue Wu wrote: 
  Hi list,
  
  Is there a date/time string that show the time only for today's emails
  but date for else? So, in the index, the emails that got today will
  show the time only, but the ones that got on other days will show the
  date and time.
 
 Not in out-of-box mutt.  For that you need the date_conditional patch by
 Aaron Schrab.  I don't see a version on the web that is rebased against
 current mutt but I can send you one if you're comfortable patching and
 compiling your own mutt.
 

Thank you all the infos, I don't know much about patching/compiling,
and it's not a must-have feature, so I will stick to the unpatched
mutt. I'm sorry if I've wasted your time, but the infos is useful, it
let me know that mutt hasn't such feature without patch, and it lets
guys who are interested in it know the patch to do the job.

Thanks again for infos!

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-07 Thread Yue Wu
On Fri, Jan 07, 2011 at 03:40:12PM +0800, 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.
 
 - du yang
 
 
 #!/bin/bash
 
 epoch=$1
 
 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%   
 
 else  

  echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%   
 
 fi

Must it be bash script? No bash here, it fails the test with sh...

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-07 Thread du yang
On Fri, Jan 07, 2011 at 18:21 +0800, Yue Wu wrote:
 On Fri, Jan 07, 2011 at 03:40:12PM +0800, 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.
  
  - du yang
  
  
  #!/bin/bash
  
  epoch=$1
  
  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% 

  else
   
   echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s% 

  fi
 
 Must it be bash script? No bash here, it fails the test with sh...
 

Change '#!/bin/bash' to '#!/bin/sh' in the script header, then it may work.

else please post the error details.

-- 
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/


Re: format string: time for today, date for others.

2011-01-07 Thread Yue Wu
On Fri, Jan 07, 2011 at 06:32:44PM +0800, du yang wrote:
 
 Change '#!/bin/bash' to '#!/bin/sh' in the script header, then it may work.
 
 else please post the error details.
 

I've tried it, but many messages like:

usage: date [-jnu] [-d dst] [-r seconds] [-t west]
[-v[+|-]val[ymwdHMS]] ...
  [-f fmt date |
  [cc]yy]mm]dd]HH]MM[.ss]]
  [+format]

 [:-gt: unexpected operator

mess up my mutt index screen at all.

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-07 Thread David Champion
* On 07 Jan 2011, Yue Wu wrote:
 On Fri, Jan 07, 2011 at 03:40:12PM +0800, du yang wrote:
 
  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%
  else
   echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
  fi

 Must it be bash script? No bash here, it fails the test with sh...

This is a POSIX sh script, not Bourne, which is why it fails for you.
Specifically, $(command) is a POSIX construction that is not supported
by conventional Bourne shells.  You can fix it by replacing this:

if [ $(date -d $(date '+%Y-%m-%d') +%s) -gt $epoch ]; then

with this:

now=`date '+%Y-%m-%d'`
if [ `date -d $now +%s` -gt $epoch ]; then

However, if I'm not mistaken that command still relies on GNU extensions
to the date command.  (Mixing POSIX and GNU is another common
portability problem in the Linux era.)  Since you appear to be using
FreeBSD you may have problems with that even after adapting the shell
syntax.  (In fact I think it's even more confusing.  Where the -d
option will simply fail on a pure POSIX system, I think it is actually
a completely different option on BSD, which has its own extensions
separate from GNU's.)

Remember that setting $index_format to a piped command means that the
command is run once each time a message is displayed on your index.  I
wrote the code to allow $index_format to be a piped command, and as I
remember the result is *not* cached.  Since the command in this case is
a shell script, it's actually going to run three commands: sh, date, and
another date.

For these reasons -- portability and performance -- I would not use
shell for this purpose.  I prefer Python, but Perl might be a better
choice since it typically has a lower startup time.  Naturally for
performance concerns, C would be the best choice.

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


Re: format string: time for today, date for others.

2011-01-07 Thread du yang
On Fri, Jan 07, 2011 at 18:54 +0800, Yue Wu wrote:
 On Fri, Jan 07, 2011 at 06:32:44PM +0800, du yang wrote:
  
  Change '#!/bin/bash' to '#!/bin/sh' in the script header, then it may work.
  
  else please post the error details.
  
 
 I've tried it, but many messages like:
 
 usage: date [-jnu] [-d dst] [-r seconds] [-t west]
 [-v[+|-]val[ymwdHMS]] ...
   [-f fmt date |
   [cc]yy]mm]dd]HH]MM[.ss]]
   [+format]
   
[:-gt: unexpected 
 operator
 
 mess up my mutt index screen at all.
 

Oh it may be the symbol $() which caused the problem.
It is ok on my machine just because /bin/sh is a soft link to bash.
Here I post a new one.

if it still doesn't work, you may have to post the date command help('date 
--help') to see if it is a problem of your 'date'.

- du yang

==
#!/bin/sh

epoch=$1

_today=`date '+%Y-%m-%d'`
_yesterday=`date -d $_today +%s`

if [ $_yesterday -gt $epoch ]; then
echo %4C %Z %[%d-%m-%y] %?M?%-11.11F [%2M]%-16.16F? (%?c?%4c%4l?)  
%?H?[%H]?%s%
else
echo %4C %Z %[   %H:%M] %?M?%-11.11F [%2M]%-16.16F? (%?c?%4c%4l?)  
%?H?[%H]?%s%
fi 



-- 
  临江仙·滚滚长江东逝水--杨慎
滚滚长江东逝水,浪花淘尽英雄。
是非成败转头空。青山依旧在,几度夕阳红。
白发渔樵江渚上,惯看秋月春风。
一壶浊酒喜相逢。古今多少事,都付笑谈中。


Re: format string: time for today, date for others.

2011-01-07 Thread Yue Wu
On Fri, Jan 07, 2011 at 05:07:47AM -0600, David Champion wrote:
 * On 07 Jan 2011, Yue Wu wrote:
  On Fri, Jan 07, 2011 at 03:40:12PM +0800, du yang wrote:
  
   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%
   else
echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
   fi
 
  Must it be bash script? No bash here, it fails the test with sh...
 
 This is a POSIX sh script, not Bourne, which is why it fails for you.
 Specifically, $(command) is a POSIX construction that is not supported
 by conventional Bourne shells.  You can fix it by replacing this:
 
 if [ $(date -d $(date '+%Y-%m-%d') +%s) -gt $epoch ]; then
 
 with this:
 
 now=`date '+%Y-%m-%d'`
 if [ `date -d $now +%s` -gt $epoch ]; then
 
 However, if I'm not mistaken that command still relies on GNU extensions
 to the date command.  (Mixing POSIX and GNU is another common
 portability problem in the Linux era.)  Since you appear to be using
 FreeBSD you may have problems with that even after adapting the shell
 syntax.  (In fact I think it's even more confusing.  Where the -d
 option will simply fail on a pure POSIX system, I think it is actually
 a completely different option on BSD, which has its own extensions
 separate from GNU's.)
 
 Remember that setting $index_format to a piped command means that the
 command is run once each time a message is displayed on your index.  I
 wrote the code to allow $index_format to be a piped command, and as I
 remember the result is *not* cached.  Since the command in this case is
 a shell script, it's actually going to run three commands: sh, date, and
 another date.
 
 For these reasons -- portability and performance -- I would not use
 shell for this purpose.  I prefer Python, but Perl might be a better
 choice since it typically has a lower startup time.  Naturally for
 performance concerns, C would be the best choice.
 

Thank you detailed explanation! I got it. I concern the performance,
and it isn't a must feature, it's just for curiosity :)

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-07 Thread David Champion
* 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  *  d...@uchicago.edu  *  IT Services  *  University of Chicago


Re: format string: time for today, date for others.

2011-01-07 Thread du yang
On Fri, Jan 07, 2011 at 05:29 -0600, David Champion wrote:
 * 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.)
 

Excellent! 
your improvement is helpful for some slow machines and machines during high 
load such as compiling.

And mutt should be a single thread program, so it could just flush the terminal 
line by line, and would not fork many processes simultaneously.

- du yang
-- 
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/


Re: format string: time for today, date for others.

2011-01-07 Thread du yang
On Fri, Jan 07, 2011 at 18:21 +0800, Yue Wu wrote:
 On Fri, Jan 07, 2011 at 03:40:12PM +0800, 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.
  
  - du yang
  
  
  #!/bin/bash
  
  epoch=$1
  
  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% 

  else
   
   echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s% 

  fi
 
 Must it be bash script? No bash here, it fails the test with sh...
 

you can first test it like this,
# ./format_date.sh 1294329609

-- 
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/


Re: format string: time for today, date for others.

2011-01-07 Thread du yang
On Fri, Jan 07, 2011 at 05:07 -0600, David Champion wrote:
 * On 07 Jan 2011, Yue Wu wrote:
  On Fri, Jan 07, 2011 at 03:40:12PM +0800, du yang wrote:
  
   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%
   else
echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
   fi
 
  Must it be bash script? No bash here, it fails the test with sh...
 
 This is a POSIX sh script, not Bourne, which is why it fails for you.
 Specifically, $(command) is a POSIX construction that is not supported
 by conventional Bourne shells.  You can fix it by replacing this:
 
 if [ $(date -d $(date '+%Y-%m-%d') +%s) -gt $epoch ]; then
 
 with this:
 
 now=`date '+%Y-%m-%d'`
 if [ `date -d $now +%s` -gt $epoch ]; then
 
 However, if I'm not mistaken that command still relies on GNU extensions
 to the date command.  (Mixing POSIX and GNU is another common
 portability problem in the Linux era.)  Since you appear to be using
 FreeBSD you may have problems with that even after adapting the shell
 syntax.  (In fact I think it's even more confusing.  Where the -d
 option will simply fail on a pure POSIX system, I think it is actually
 a completely different option on BSD, which has its own extensions
 separate from GNU's.)
 
 Remember that setting $index_format to a piped command means that the
 command is run once each time a message is displayed on your index.  I
 wrote the code to allow $index_format to be a piped command, and as I
 remember the result is *not* cached.  Since the command in this case is
 a shell script, it's actually going to run three commands: sh, date, and
 another date.
 
 For these reasons -- portability and performance -- I would not use
 shell for this purpose.  I prefer Python, but Perl might be a better
 choice since it typically has a lower startup time.  Naturally for
 performance concerns, C would be the best choice.
 

You are absolutely correct. Considering performance in mind is always better.

But scripts and languages like java is still very important in computer world.
Because it allows people to accomplish their tasks easily without making any 
seriously mistake like core dump. It hides many system implementation details 
to whom doesn't care it. It frees programmers from memory tuning and it helps 
not-so clever programmers doing thing correctly.

Most cases for people, function is more important than performance. They just 
care working or not. Why Java is so popular in commercial world.. Simply 
because bosses like it.

At last not the least, for researching and system which is 
performance-sensitive, C/C++ is still the best choice.

- du yang
-- 
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/


Re: format string: time for today, date for others.

2011-01-06 Thread David Champion
* On 05 Jan 2011, Toby Cubitt wrote: 
 
 is dated less than 24h before the current time. That's *not* what I'm
 after. When the current time is 00:01 on the 6 Jan, I want an email that
 arrived at 23:59 on the 5 Jan to display Sun 05, even though the email
 is only two minutes old.

I understand now.  In your first post I read emphasis in the multiple
conditionality, not in the idea that yesterday is not the same as
less than one day ago.

Does your patch still support the original behavior of date_conditional?
I personally don't want everything to change at midnight.  (I'm more
sensitive to how long ago something happened than to what day it was at
the time.)  But if your version does both it's a more complete feature,
and I'm interested it using it instead.

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


Re: format string: time for today, date for others.

2011-01-06 Thread Toby Cubitt
On Thu, Jan 06, 2011 at 03:09:53AM +, Toby Cubitt wrote:
 As far as I recall (it's a long time since I looked at it), the
 date_conditional patch straightforwardly compares the email date stamp
 against the current time. The 1d conditional is true whenever the email
 is dated less than 24h before the current time. That's *not* what I'm
 after. When the current time is 00:01 on the 6 Jan, I want an email that
 arrived at 23:59 on the 5 Jan to display Sun 05, even though the email
 is only two minutes old.

In case anyone's interested, I've put the modified version of the
date_conditional patch which implements the above behaviour at:

http://www.dr-qubit.org/download.php?file
=mutt/mutt-1.5.21-patch.tsc.date_conditional.1

[URL should all be on one line]

Note that you can still get the original date_conditional behaviour by
specifying a finer time unit in the date format. E.g. if you want to
specify a format for emails from the last 24 hours, use 24h as the time
span. If you want to specify a format for emails from today (as described
above), use 1d as the time span.

(Roughly speaking, in this version of the date_conditional patch, the
current time and the email's date stamp are converted to the unit of time
specified in the conditional, and the fractional part discarded, before
comparing the two.)

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org


Re: format string: time for today, date for others.

2011-01-06 Thread du yang
Hi,

I improved the script to fulfill the author's the expectation(just display time 
for today's mails),
only 'if condition' changed.

- du yang


#!/bin/bash

epoch=$1

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% 
  
else
 
 echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s% 
  
fi


On Thu, Jan 06, 2011 at 00:38 +0100, Andreas Kneib wrote:
 Hi,
 
 * Yue Wu schrieb am Donnerstag, den 06. Januar 2011:
 
  Is there a date/time string that show the time only for today's emails
  but date for else? So, in the index, the emails that got today will
  show the time only, but the ones that got on other days will show the
  date and time.
 
 I use this script:
 http://groups.google.com/group/de.comm.software.mailreader.misc/browse_thread/thread/ab966bddc0b42446/421549103438b830?q=#421549103438b830
 
 In ~/.muttrc:
 #v+
 set index_format=./format_date.sh '%[%s]' |
 #v-
 
 #
 #!/bin/bash
 #
 # File: format_date.sh 
 
 epoch=$1
 
 if [ $(($(date '+%s') - $1)) -gt 86400 ]; then
 echo %4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
 else
 echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
 fi 
 #
 
 
 Andreas

-- 


format string: time for today, date for others.

2011-01-05 Thread Yue Wu
Hi list,

Is there a date/time string that show the time only for today's emails
but date for else? So, in the index, the emails that got today will
show the time only, but the ones that got on other days will show the
date and time.

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Yue Wu wrote: 
 Hi list,
 
 Is there a date/time string that show the time only for today's emails
 but date for else? So, in the index, the emails that got today will
 show the time only, but the ones that got on other days will show the
 date and time.

Not in out-of-box mutt.  For that you need the date_conditional patch by
Aaron Schrab.  I don't see a version on the web that is rebased against
current mutt but I can send you one if you're comfortable patching and
compiling your own mutt.

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


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 04:32:44PM -0600, David Champion wrote:
 * On 05 Jan 2011, Yue Wu wrote: 
  Hi list,
  
  Is there a date/time string that show the time only for today's emails
  but date for else? So, in the index, the emails that got today will
  show the time only, but the ones that got on other days will show the
  date and time.
 
 Not in out-of-box mutt.  For that you need the date_conditional patch by
 Aaron Schrab.  I don't see a version on the web that is rebased against
 current mutt but I can send you one if you're comfortable patching and
 compiling your own mutt.

If I remember correctly, the date_conditional patch doesn't *quite* let
you have a different date/time string for today, rather it gives you a
different date/time string for the last 24h.

A while back, I wrote a modified version of the date_conditional patch so
that it could be used to produce different formats for mails from today,
from the current month, from the current year, etc. I haven't gotten
around to making it available online, but if you want a copy I'd be happy
to mail it to you.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Toby Cubitt wrote: 
 
 If I remember correctly, the date_conditional patch doesn't *quite* let
 you have a different date/time string for today, rather it gives you a
 different date/time string for the last 24h.

The best documentation I've seen is the changelog entry that I wrote for
my mercurial patch queue:

Allows you to construct format expressions based on relative dates.

This adds conditionality features to mutt's date-formatting
operators, so that you can build conditions based on whether the
date in question is less than or grater than some amount in the
past.

Example: %?[1y?less than one yeargreater than one year?
Example: %?[3d?less than three daysgreater than three days?

This is particularly useful in concert with nested_if.  For example,
this expression:
%[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]

means to show the YYMMDD date for messages older than one year,
the mon dd date for messages from one week to one year, the day
dd date for messages from 1 to 7 days old, and the HH:MM time for
messages under one day old.

So it can handle a single split point as it stands (less than 24h,
greater than 24h).

 A while back, I wrote a modified version of the date_conditional patch so
 that it could be used to produce different formats for mails from today,
 from the current month, from the current year, etc. I haven't gotten
 around to making it available online, but if you want a copy I'd be happy
 to mail it to you.

That's what I want as well, but I do it by using date_conditional in
conjunction with the more general nested_if patch.  Nested_if, as its
name suggests, lets you nest mutt's ternary conditionals arbitrarily
deep.

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


Re: format string: time for today, date for others.

2011-01-05 Thread Andreas Kneib
Hi,

* Yue Wu schrieb am Donnerstag, den 06. Januar 2011:

 Is there a date/time string that show the time only for today's emails
 but date for else? So, in the index, the emails that got today will
 show the time only, but the ones that got on other days will show the
 date and time.

I use this script:
http://groups.google.com/group/de.comm.software.mailreader.misc/browse_thread/thread/ab966bddc0b42446/421549103438b830?q=#421549103438b830

In ~/.muttrc:
#v+
set index_format=./format_date.sh '%[%s]' |
#v-

#
#!/bin/bash
#
# File: format_date.sh 

epoch=$1

if [ $(($(date '+%s') - $1)) -gt 86400 ]; then
echo %4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
else
echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
fi 
#


Andreas


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 05:20:19PM -0600, David Champion wrote:
 * On 05 Jan 2011, Toby Cubitt wrote: 
  
  If I remember correctly, the date_conditional patch doesn't *quite*
  let you have a different date/time string for today, rather it gives
  you a different date/time string for the last 24h.
 
 The best documentation I've seen is the changelog entry that I wrote for
 my mercurial patch queue:
 
 Allows you to construct format expressions based on relative dates.
 
 This adds conditionality features to mutt's date-formatting
 operators, so that you can build conditions based on whether the
 date in question is less than or grater than some amount in the
 past.
 
 Example: %?[1y?less than one yeargreater than one year?
 Example: %?[3d?less than three daysgreater than three days?
 
 This is particularly useful in concert with nested_if.  For example,
 this expression:
 %[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]
 
 means to show the YYMMDD date for messages older than one year,
 the mon dd date for messages from one week to one year, the day
 dd date for messages from 1 to 7 days old, and the HH:MM time for
 messages under one day old.
 
 So it can handle a single split point as it stands (less than 24h,
 greater than 24h).

Yes, but how would you use this to e.g. print only the time for all
emails received today, but print the date for all emails received
yesterday or earlier? A split point of 24h is no use. If it's currently
10am, say, then all mails since 10am the previous day will display the
time only. Whereas what's wanted is all emails since midnight to display
the time, and emails prior to midnight to display the date.

I don't think this can be done with the date_conditional patch as it
stands, because the split point would have to depend on the current time,
and I know of no way of putting that calculation into the date-format
string.

I just modified the time comparisons in my version of the
date_conditional patch so that an interval of 1 day implies fractions of
a day are discarded before comparing with the current time, an interval
of 1 month discards days and below, an interval of a year discards months
and below, etc.

This lets me display just the time for today's emails, the day and month
for this year's emails, and the full date for older emails. That way, I
can see at a glance which emails arrived today, which arrived this year,
and which are older than a year. (As opposed to which arrived within the
last 24h, which arrived within the last 30 days, which arrived within the
last 365 days.)

  A while back, I wrote a modified version of the date_conditional
  patch so that it could be used to produce different formats for mails
  from today, from the current month, from the current year, etc. I
  haven't gotten around to making it available online, but if you want
  a copy I'd be happy to mail it to you.
 
 That's what I want as well, but I do it by using date_conditional in
 conjunction with the more general nested_if patch. Nested_if, as its
 name suggests, lets you nest mutt's ternary conditionals arbitrarily
 deep.

Indeed, I use nested_if with my modified date_conditional patch.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Toby Cubitt wrote: 
 
 Yes, but how would you use this to e.g. print only the time for all
 emails received today, but print the date for all emails received
 yesterday or earlier? A split point of 24h is no use. If it's currently

That's what nested_if is for.  Here is the date string from my $index_format:

%[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]

that is,
if  1y:
if  1w:
if  1d:
%H:%M
else:
# = 1d
%a %d
else:  
# = 1w
%b %d
else:
# = 1y
%y%m%d

It does work, or I've been misreading my index for the last 5 years. ;)

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


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 07:22:18PM -0600, David Champion wrote:
 * On 05 Jan 2011, Toby Cubitt wrote: 
  
  Yes, but how would you use this to e.g. print only the time for all
  emails received today, but print the date for all emails received
  yesterday or earlier? A split point of 24h is no use. If it's currently
 
 That's what nested_if is for.  Here is the date string from my $index_format:
 
 %[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]
 
 that is,
 if  1y:
   if  1w:
   if  1d:
   %H:%M
   else:
   # = 1d
   %a %d
   else:  
   # = 1w
   %b %d
 else:
   # = 1y
   %y%m%d
 
 It does work, or I've been misreading my index for the last 5 years. ;)

Perhaps I'm being dense here. But if it's 10:00 on the 6 January, and
there's an email dated 19:00 on the 5 January, then surely this will
display 19:00? But I want it to display Sun 05, because the email is
from yesterday, not today. I'm sure your date format does what you want,
it's just not what I'm talking about.

As far as I recall (it's a long time since I looked at it), the
date_conditional patch straightforwardly compares the email date stamp
against the current time. The 1d conditional is true whenever the email
is dated less than 24h before the current time. That's *not* what I'm
after. When the current time is 00:01 on the 6 Jan, I want an email that
arrived at 23:59 on the 5 Jan to display Sun 05, even though the email
is only two minutes old.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org