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

Re: Emulating tcsh:s prompt



On Jun 9, 10:50pm, =?iso-8859-1?Q?Johan_Sundstr=F6m?= wrote:
> Subject: 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!".

PS1="%(t.Ding\!.%D{%I:%M})> "

> ... the second time [that minute] a common HH:MM is generated.

Hardly seems worth the effort, but

precmd() {
  thisminute=$(print -P %D{%M})
  [[ $thisminute = ${lastminute:-0} ]] && {
	PS1="%D{%I:%M}> " ||
	PS1="%(t.Ding\!.%D{%I:%M})> " }
  lastminute=$thisminute
}

> I was wondering, whether there is any way I can set an environment variable
> in the parent shell from this function.

Any variable you set in a function is set in the "parent" shell.  Functions
run in the same context as builtins, by definition.

> I had hoped "exec export Hour=$HH" would do the job, but it didn't.

Leave off the "exec".



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