[comp.unix.questions] Time in prompt?

cs9h7atw@cybaswan.UUCP (Alex Williams) (06/13/89)

Hello,
	How can the Time be put in the prompt - sim. to the cwd alias' ?

							Alex
							----

yakker@bartok.ucr.edu (The Rastafari Yakker) (06/14/89)

There are a number of ways to put the time into the prompt, but it
may not be the best thing to do.  Here's a little command I tried
and got to work, but there's a problem with it:

          set prompt = "(`date '+%H:%M:%S'`):  "

This works, but the time isn't updated.  The C shell has to be reset
in order to update the time.  If you wanted to constantly update the
time, you would have to run a constant (C) shell in the background that
runs a command and then updates the prompt time.

 
      set prompt = "(`date '+%H:%M:%S'`):  "
      alias cd 'chdir \!*; set prompt = "(`date '+%H:%M:%S'`):  "'

Other than this, I don't know of another way to correctly change the
time without creating another shell in the background and making it 
more of a bother than checking your watch.

---------------------------------------*--------------------------------------
"Behold, God, is my salvation, I       |   Internet:    yakker@ucrmath.ucr.edu
will trust, and not be afraid.."      |+|      UUCP:    ...ucsd!ucrmath!yakker
                                     |+|+|          
"What lies behind you and what lies  |+|+|        The University of California
before you pales insignificant when   |+|                         at Riverside
compared to what lies within you.."    |        Department of Computer Science
---------------------------------------*--------------------------------------

cs9h7atw@cybaswan.UUCP (Alex Williams) (06/15/89)

In article <1106@ucrmath.UCR.EDU> yakker@bartok.UUCP (The Rastafari Yakker) writes:
>There are a number of ways to put the time into the prompt,
>
>          set prompt = "(`date '+%H:%M:%S'`):  "
>
>This works, but the time isn't updated.  The C shell has to be reset
>in order to update the time.  If you wanted to constantly update the
>time, you would have to run a constant (C) shell in the background that
>runs a command and then updates the prompt time.
>
> 
>      set prompt = "(`date '+%H:%M:%S'`):  "
>      alias cd 'chdir \!*; set prompt = "(`date '+%H:%M:%S'`):  "'
>
>Other than this, I don't know of another way to correctly change the
>time without creating another shell in the background and making it 
>more of a bother than checking your watch.
>

Yes, this is my problem and I agree about the watch bit but don`t own one!
(Send flames to West Glamorgan County Council Grants Dept. :-( ! )
Ok, so how do I set a vt220's time to be system time on my login?

						Alex

-- 
Janet: pyr.swan.ac.uk					 UUCP : cybaswan.uucp

Alex Williams:	 Department of Computer Scence, University College Swansea,
		 	Singleton Park, Swansea, Wales.	

jws@hpcljws.HP.COM (John Stafford) (06/16/89)

Well in ksh you can get updated time, there is an example in the book
that does hours and minutes.  Here is mine that adds seconds as well (I
don't claim it is the best way, I never have sorted out the weird
subscript stuff).  It should of course be .  invoked or in your .profile
or ENV file.

#
# Set up so we can use a clock in our prompt
#
export SECONDS="$(date '+3600*%H+60*%M+%S')"
typeset -Z2 _h _m _s
_hh="(SECONDS/3600)%24"
_mm="(SECONDS/60)%60"
_ss="SECONDS%60"
_time='${_x[(_m=_mm)==(_h=_hh)+(_s=_ss)]}$_h:$_m:$_s'

#
# Change working directory and show the basename of the current working
# directory and the current time in the prompt.
#
function wd
{
\cd $1
working="${PWD##*/}"
PS1="${working:-/} $_time > "
}
alias cd=wd

stripes@wam.UMD.EDU (06/26/89)

In article <512@cybaswan.UUCP> cs9h7atw@cybaswan.UUCP (Alex Williams) writes:
[Much removed from both sides...]
>Yes, this is my problem and I agree about the watch bit but don`t own one!
>(Send flames to West Glamorgan County Council Grants Dept. :-( ! )
>Ok, so how do I set a vt220's time to be system time on my login?
>						Alex
I don't know how to set the VT220 time, but I do beleve the VT220 is
capable of running the sysline program.  Which will display the date,
time, load, number of users, 1st line of mail recieved in the last 60
seconds (or whatever you have update time set to).  It came with the Ultrix
system I use, but I think it's a BSD thing so there is a good chance you
have it, if not mabie someone has written a PD version.
-- 
           stripes@wam.umd.edu          "Security for Unix is like
      Josh_Osborne@Real_World,The          Mutitasking for MS-DOS"
      "The dyslexic porgramer"                  - Kevin Lockwood
                "Dammit Jim, I'm a Doctor not an Excorsist"
                   - One of Bones' lines in a previous ST:V script...