zsh-users
 help / color / mirror / code / Atom feed
From: "Johan Sundström" <johsu650@student.liu.se>
To: <zsh-users@math.gatech.edu>
Subject: Emulating tcsh:s prompt
Date: Tue, 9 Jun 1998 22:50:57 +0200	[thread overview]
Message-ID: <005e01bd93e8$4da50cc0$cde8ec82@a205.ryd.student.liu.se> (raw)

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



             reply	other threads:[~1998-06-09 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-09 20:50 Johan Sundström [this message]
1998-06-09 22:15 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005e01bd93e8$4da50cc0$cde8ec82@a205.ryd.student.liu.se' \
    --to=johsu650@student.liu.se \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).