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

Re: Length of %? in prompt



On Tue, 26 Feb 2002, Ian Lynagh wrote:

> One more thing...as the first % escapes the second in
> "%%1v>-->%?---------%<< " it looks like there is no way to change this
> value on the fly without recreating the prompt - is this correct?

If you "setopt promptsubst" you can use a variable for the width:

setopt promptsubst
W=5
PS1='%$W>-->%?----------%<< '

You just have to make sure there are as many hyphens in the truncate
region as the largest value you ever expect to assign to W.

If for some other reason you want to avoid promptsubst, you will have to
recreate the prompt, or at least recreate one of the psvar values like
this:

W=5
PS1='%1v '
precmd {
  psvar[1]=${(%%):-%$W>-->%?----------%<<}
}

Just be sure that the prompt expansion of %? is the first thing in precmd,
or else it'll get the exit status of whatever other commands appear in
precmd rather than the exit status of the last interactive command.



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