Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Emulating tcsh:s prompt



I'm trying to emulate tcsh:s cool prompt parameter %T in zsh using the
precmd function. Tcsh:s version of %T gives a five character long field in
the format HH:MM, with a slight exception; if the prompt is displayed on a
full hour (MM=00), the text changes to "Ding!". This only happens the first
time the prompt is generated that minute, the second time a common HH:MM is
generated. Example output near the hour shift for a prompt "%T>":

01:58>
01:58>
01:59>
01:59>
Ding!>
02:00>
02:01>
02:01>

I tried to emulate this behaviour using the precmd function, and even
managed to do it in a rather ugly way:

precmd () { PS1="`HH=\`date +%H\`;MM=\`date +%M\`;if [ -f /var/tmp/Hour -a
$HH != \`cat /var/tmp/Hour\` -a $MM = 00 ];then echo Ding\!;else echo
$HH:$MM;fi;echo $HH >/var/tmp/Hour`> " }

In a more readable fasion:

precmd () {
PS1="`HH=\`date +%H\`
      MM=\`date +%M\`
      if [ -f /var/tmp/Hour -a $HH != \`cat /var/tmp/Hour\` -a $MM = 00 ]
         then
             echo Ding\!
         else
             echo $HH:$MM
      fi
      echo $HH >/var/tmp/Hour
     `> " }

I was wondering, whether there is any way I can set an environment variable
in the parent shell from this function. The kludge using /var/tmp/Hour to
store the hour of the last prompt was a last resort when I didn't manage
setting $Hour. Is there a way? How should it be done?

I had hoped "exec export Hour=$HH" would do the job, but it didn't. I'm
using the Linux version 3.0.5, if that should be of any relevance.

/Johan Sundström




Messages sorted by: Reverse Date, Date, Thread, Author