I’ve just updated my system to the latest OpenSolaris release (snv_109) and suddenly my ZSH prompt has lost all it’s colours (I use them to clearly distinguish between me and the root user - I’m also a bit of a customisation freak
).
A little bit of research soon revealed that OpenSolaris snv_109 and later now ships with ZSH 4.3.9 in which they changed the prompt colouring scheme, and for the better too as it’s far easier to understand.
From the ZSHMISC(1) man page:
%F (%f)
Start (stop) using a different foreground colour, if
supported by the terminal. The colour may be specified
two ways: either as a numeric argument, as normal, or
by a sequence in braces following the %F, for example
%F{red}. In the latter case the values allowed are as
described for the fg zle_highlight attribute; see Char-
acter Highlighting in zshzle(1). This means that
numeric colours are allowed in the second format also.
So I need to change my PS1/PS2 from using the old $fg[color] format to the new format, which is easy enough. However I still need my colour prompt to work on pre snv_109 hosts, and this is where ZSH’s is-at-least comes in handy.
So, now the code that sets my prompt looks as follows (I’ve removed the rest of the stuff around it):
if ( is-at-least 4.3.9 ); then
PS1="%F{magenta}[%(!.%F{red}.%F{blue})%m : %F{green}%40<...<%~%F{magenta}]%F{blue}%(!.#.$) %f”
PS2=”%(!.%F{red}.%F{blue})%_< %f”
else
PS1=”%{${fg[magenta]}%}[%(!.%{${fg[red]}%}.%{${fg[blue]}%})%m : %{${fg[green]}%}\
%40<…<%~%{${fg[magenta]}%}]%{${fg[blue]}%}%(!.#.$) %{${fg[default]}%}”
PS2=”%(!.%{${fg[red]}%}.%{${fg[blue]}%})%_< %{${fg[default]}%}”
fi
If you’re curious, this give me the following prompt for a normal user:
[devon : ...data/70478860/ftp-2009-01-07/crash]$
… and …
[devon : /usr/bin]#
… for root and as you can see in the first example, it truncates long paths too.
Search
Related Entries
- HOWTO: Disable Timeout Alert in Lightning/WCAP Extension
- HB Audio Player 1.1
- Links for 10 Apr 2008 - 29 Apr 2008
- 10 People Who Don’t Matter
- Ultra 20 Graphics Card Not Seen OpenSolaris snv_108 and Later
- OpenSolaris 2008.11 RC2
- Happy 1st Birthday OpenSolaris
- OpenSolaris Now Available for SPARC
- Get OpenSolaris Media for Free
- OpenSolaris 2008.11 is Now Available



hi, you might be interested in little work I did to update ZSH completion system for some OpenSolaris commands. Check it out
http://www.opensolaris.org/jive/thread.jspa?threadID=105996&tstart=0
Nice work there Bart. I’ll have to give your stuff a spin.