Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

%m
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?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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

setopt PROMPT_SUBST

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 .)"
PS1="$HOSTANDSUBDOMAIN$ "
share|improve this answer
add comment

Your Answer

 
discard

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.