Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can you get the prompt "/home/user@address:/path" for Zsh?

I run the following unsuccessfully in my .zshrc

PROMPT='%d%>:%{\e[0m%} '

I get as my prompt

share|improve this question
Your request is very confusing. how is /home/user@address:/path composed of parts that will update? /home/user is a path address is ... do you mean host? and /path is a path again. – dlamblin Oct 29 '09 at 2:27
up vote 4 down vote accepted

This might be give you what you want (user@host:path):

PROMPT=$'%n@%m:%d%{\e[0m%} '

If you wanted to limit the length of the path (%> from your example), you limit it to only display the last 12 characters like this:

PROMPT=$'%n@%m:%12<...<%d%<<%{\e[0m%} '

If you did not actually want the embedded escape code in there (it is a typical VT100-style command to clear any bold/etc. formatting), you could simplify it to this:

PROMPT='%n@%m:%12<...<%d%<< '
share|improve this answer
What is the purpose of the dollar sign before ' in your first two commands? – Masi Oct 29 '09 at 3:34
See the "Quoting" section of man zshmisc. It processes escape sequences. Try echo '\e[0m' and then again with the dollar sign. Pipe each one through hd to see the difference more clearly. – Dennis Williamson Oct 29 '09 at 4:11
What is the purpose of piping the each one though hd? - It seems to give me hexadecimal output. If I increase the number of dollar signs in the order of two, then I get a different output. – Masi Oct 29 '09 at 20:47
Using echo, you only see a difference if the BSD_ECHO option is in effect. echo '\e' | hd shows the sequence 5c 65; echo $'\e' | hd shows 1b. Using $'...' is a way of making sure that the \e is always <ESC>, and not <backslash> + e. Really, see the zshmisc(1) under Quoting. – Chris Johnsen Oct 29 '09 at 22:13

In this case the manual might be really helpful.

I'm guessing you want something like:
PROMPT='$HOME@%M:%3~ '

Apparently actually reading the 4 sentences in the short manual page is too much work. Maybe because it's a link:

13. Prompt Expansion

13.1 Expansion of Prompt Sequences

Prompt sequences undergo a special form of expansion.
This type of expansion is also available using the -P option
to the print builtin.

If the PROMPT_SUBST option is set, ...

Certain escape sequences may be recognised in the prompt string.

If the PROMPT_BANG option is set, ...

If the PROMPT_PERCENT option is set, ...

13.2 Simple Prompt Escapes

13.2.1 Special characters

A `%'.

A `)'.

13.2.2 Login information

The line (tty) ...

The full machine hostname.

The hostname up to the first `.'. An integer may follow the `%' to specify
how many components of the hostname are desired. With a negative integer, 
trailing components of the hostname are shown.


The line (tty) ...

13.2.3 Shell state

A `#' if the shell is running with privileges, ...

The return status ...

The status of the parser, ...

Present working directory ($PWD). If an integer follows the `%', it 
specifies a number of trailing components of $PWD to show; zero means 
the whole path. A negative integer specifies leading components, 
i.e. %-1d specifies the first component.

As %d and %/, but if $PWD has a named directory as its prefix, that part
is replaced by a `~' followed by the name of the directory. If it starts
with $HOME, that part is replaced by a `~'.

Current history event number.

The line number ...

The line number ...

The number of jobs.

The current value of $SHLVL.

The name of the script, ...

The name of the file ...

Trailing component ...These are deprecated... equivalent to %1~ and %1/ ...

13.2.4 Date and time ... Ignored ...

13.2.5 Visual effects ... Ignored ...

13.3 Conditional Substrings in Prompts ... Possibly useful but ignored ...

share|improve this answer
What is the purpose of ´3´ in ´%3~´? The command seems to work too without it. – Masi Oct 29 '09 at 3:42
It only shows the lowest three directory levels of the current directory (PWD). Try cd /usr/share/doc/zsh - the prompt will only show "share/doc/zsh" – Dennis Williamson Oct 29 '09 at 4:18
You see that blue word that says "manual" there. It tells all about every possible variation. But, and I know this is a stretch, you have to click on it. With your mouse. – dlamblin Oct 29 '09 at 18:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.