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

Re: Length of %? in prompt



On Feb 26,  4:05pm, Ian Lynagh wrote:
}
} If the length of %? will alter the number of dashes following it in my
} prompt am I right in thinking that my only course of action is to
} enumerate the (rather large!) set of possible cases with
} "%(n?,---...,)"? If so I guess I will have to redesign  :-(

No, you don't need to do that.  You can use the truncation sequences %>>
and/or %<<.  Let's assume that you want the value of %? plus the hyphens
to take up a total of 10 characters; you'd use:

    %10>-->%?--------%<<

The number of hyphens following %? must be at least 9 in order for the
field to always be 10 characters wide -- truncation won't lengthen the
prompt, only shorten it.

An important thing to note is that %N>STRING> means that STRING replaces
the last strlen(STRING) characters of the remaining prompt, up to %<<,
any time it is more than N characters long.  E.g., with %N>--> you can't
make N less than 5 without digits from %? being truncated when the exit
status is more than two digits long.

So the minimal fixed-width replacement for %? using this scheme is:

    %4>->%?---%<<

which works out to up to three digits of %? followed by at least 1 hyphen.

You can put the hyphens in front, too, of course:

    %4<-<---%?%>>

It's not necessary to reverse the > and < at the beginning and end of the
truncation region, I just do it for visual symmetry.  These work too:

    %4>->%?---%>>
    %4<-<---%?%<<

Finally, you can even do this:

    %(?.----.%4>->%?---)

Here, the truncation ends at the closing paren.  This example does not
show the exit status unless it is nonzero.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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