The zshmisc man page on my new Debian Squeeze install states, under SIMPLE PROMPT ESCAPES:

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.

When I include %2m in my prompt, I see differing behaviour between OSX and Linux.

On OSX (10.7.3), running zsh 4.3.11, the prompt behaves as expected, showing the two leading components of the system hostname.

On Debian, running zsh 4.3.10, the prompt still only shows the bare hostname. hostname -f on this system confirms that the full hostname is set correctly. Note also that the manpage for this zsh release says that %2m should be supported.

Does anyone have any suggestions as to where to start debugging this?


A quick look at zsh's prompt handling source code suggests that %m is based on what your system returns for the gethostname system call. That's like running hostname without the -f option.

I'm assuming running hostname without -f returns your bare hostname on your Debian system?

You could try changing your hostname to include the domain name. The Debian HowTo/ChangeHostname docs should help with that. But maybe some Debian tools assume your hostname does not include the domain name, so that might be a bad idea.

It might make more sense to just use command substitution.

First set the PROMPT_SUBST option


then you can run any command and put its output in the prompt like this:

PS1='$(hostname -f)$ '

to get only the first however many parts of the hostname, you could use cut, e.g.

PS1='$(hostname -f | cut -f 1-2 -d .)$ '

Because your hostname shouldn't change, you could also be a little more efficient by running the command just once and storing it in a variable, then using the variable, e.g.

HOSTANDSUBDOMAIN="$(hostname -f | cut -f 1-2 -d .)"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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