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

Re: PATCH: 3.1.5: Re: New-line in prompt

On Nov 9,  4:00pm, Peter Stephenson wrote:
} Subject: PATCH: 3.1.5: Re: New-line in prompt
} However, the other bit, adding a newline if the current line is too
} long, is a different kettle of fish.  It's possible to add a test flag
} so you can put in arbitrary text if the line has reached a certain
} length.  With the patch to 3.1.5 at the end, you can do e.g.
} PS1='any old stuff%(30l.
} .)some more stuff'

This is certainly interesting.

My first thought was to approach this problem with truncation behavior,
which turned out to be a lot more painful than I expected.  For one
thing, the documentation for $<...< and %>...> don't explain that the
truncation AND the computation of the length of the string apply only to
*one* immediately following prompt component.  Once that's understood,
it becomes apparent that the conditional syntax is the only way to group
other prompt components (except for %{...%} which isn't desirable here).

So I end up with something silly like (warning, this doesn't work):

%m[%h] >%(0_.%/ %m[%h] .)'

At which point I discover (which perhaps should have been obvious, but
wasn't) that the string inside the %>...> is not itself prompt-expanded;
and further that %>...> "reaches inside" the %(...) construct to only
truncate the %/ in spite of my effort to group it.  (Oh, and, BTW, that
there's no way to escape '>' or '<' inside %>...> or %<...<.)

At the very least, this all ought to be documented.

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

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