Here's an old technique which I believe dates back to ksh88 days; I'm 
sure I used it on HP-UX 10 versions

export _ss='SECONDS%60' _mm='(SECONDS/60)%60' _hh='(SECONDS/3600)%24'
export PS1='${_x[(_s=_ss)+(_m=_mm)+(_h=_hh)]}$_h:$_m:$_s '

firstly, _ss _mm and _hh are assigned something that looks like an 
expression. Each time it's evaluated the value of SECONDS is different 
and evaluated to yield the seconds, minutes and hour of the day. Simple 
so far.

The core of the trick is to get these things evaluated and assign their 
value to working variables _s _m and _h. Using ${_x[ ]} is sufficient to 
cause evaluation of the expressions embedded in ( ) which are added 
together just to get a successful execution.

As long as _x does not exist, the result of ${_x[ ]} will simply be an 
empty string which is the first part of the prompt.

Finally, the values assigned by side-effect to _h _m and _s are included 
in the prompt and you'll see the current time as your prompt.

So! anything you can cause to evaluate in the expressions will let you 
calculate values.

Don't forget you can also do things like ${PWD##*/} to slice the 
directory off the current PWD, or ${VAL:+expression} to only yield 
expression if VAL is set, etc.

With a bit of cleverness you can get quite a bit into the strings.

Please let us know (and remind me) if it works for you. I'm almost 
certain it will.


_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to