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

Re: On the topic of prompts

On Jul 11,  1:51pm, DeWitt Clinton wrote:
> Subject: On the topic of prompts
> Since there is probably no way to justify a section of the prompt, perhaps
> there is a way to tell rprompt to write to the line just above using
> control characters?  Just wondering...

Sure.  Note that the following won't work properly if you don't have a
newline in PS1.

RPS1="%{$(echotc ku)%}whatever you want here%{$(echotc kd)%}"

You might have to replace $(echotc ku) and $(echotc kd) with different
up and down escapes for your terminal if your terminal has a keypad
transmit mode, because keypad mode is normally not in use.

I tried $(echotc up) and $(echotc do) but that doesn't work because "do"
is frequently just ctrl-J, which zsh strips out of rprompts.

> Also, is there a way to pad the variables with spaces?  If so, that would 
> solve this problem entirely.

Sort of.

precmd() {
    fakePS1=$(print -nP " %h %m %n %~ %W")
    unset fakeRPS1	# Clear any previous `typeset -R`
    fakeRPS1=$(print -nP %@)
    if [[ $[$COLUMNS-$#fakePS1-$#fakeRPS1-2] -gt 0 ]]
	typeset -R $[$COLUMNS-$#fakePS1-1] fakeRPS1="$fakeRPS1"
% "
% "

> While I am thinking about it, what I am really looking for is a status bar
> that would just sit at the top of the screen and hold certain useful
> information.  Anyone know of how to achieve this?

You can play all sorts of games with %{...%} and termcap sequences if
your terminal can set scrolling regions and so forth.  If you're using
an xterm, you can use something like this to change the title bar:

if [[ "$TERM" = xterm* || "$TERM" = vs100 || "$TERM" = vs100s ]]
    # Set top to introduce titlebar change
    # Set back to end titlebar change
    # Create precmd() to put stuff in the title bar
    precmd() { print -nP "%{$top%m.%l:%2c - %t$back%}" }

Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"

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