Time in prompt?

John Stafford jws at hpcljws.HP.COM
Fri Jun 16 06:19:24 AEST 1989


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



More information about the Comp.unix.questions mailing list