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::
::\_)::(..)::
:::)./:::
::(_/