Tag Archives: urxvt

Configuring the default prompt (PS1)

I use the terminal every day and I have spent a lot of time customising its configuration, particularly the default prompt, to my liking.

Today, I will show you how to customise your default prompt, or PS1.  Before I show you my spartan configuration, let me explain.  I am a minimalist, so I do not see the point of having a long PS1 that shows a multitude of system information when the core *nix utils (/bin) can tell you that anyway.

Note: My terminal is rxvt-unicode, my shell is zsh, and I often run all my cli apps within GNU screen.

PS1="$(print '%{\e[1;31m%}%1%{\e[0m%} %{\e[1;32m%}%B%#%b%{\e[0m%} %(?..(%?%)) %_ \ek\e\\')"

Produces: ~ %

Explanation:  The entire PS1 expression is placed within a print command so my shell outputs a “null title-escape-sequence (<esc>k<esc>\) as a part of the prompt.”  GNU screen will then use the title-escape-sequence when naming the window (normally changed with C-a A).


– light red


– trailing component of $PWD


– resets the color


– light green


– start boldface mode


– prints a # if I am a superuser (root) or a % if I am not.


– end boldface mode


– resets the color


– takes advantage of zsh’s ternary expressions, which picks different strings depending on a test.  In this case, a message is displayed only if the exit code is not zero.


: status of the parser (i.e. if, for, then, while)


– the title-escape-sequence for GNU screen

Other common variables you can use include:


– history entry number


– current hostname (up to any dot)


– shows username


– the date in yy-mm-dd format

See “zsh: Prompt Expansion” for the definitive list of zsh prompt sequences.

A list of “colour equivalences:”

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37

Using a handy script I got from the bash manual, here is a picture of my current color scheme (zenburn):