Skip site navigation (1)Skip section navigation (2)
Date:      28 May 2000 12:30:46 +0200
From:      naddy@mips.inka.de (Christian Weisgerber)
To:        freebsd-questions@freebsd.org
Subject:   Re: sh prompt
Message-ID:  <8gqsgm$311u$1@bigeye.mips.inka.de>
References:  <001601bfc85d$9b60f680$1fdba7d1@odie>

next in thread | previous in thread | raw e-mail | index | archive | help
Duke Normandin <dnormandin@freewwweb.com> wrote:

> I have the following prompt in ~/.shrc:
> 
> PS1="[$(tty | cut -c9-11)]:`whoami`.`hostname | sed 's/\..*//'`@"`pwd`
                                       ^^^^^^^^^^^^^^^^^^^^^^^^    ~~~~~
                                             hostname -s
`pwd` will probably not do what you expect. This is evaluated only once
when PS1 is set, so it will not keep your current working directory in
your prompt. For that you'll need something along the lines of this:

PROMPT=$(whoami)@$(hostname -s)
cd()
{
    command cd "$@"
    case ${PWD} in
        "${HOME}"*) PS1="${PROMPT}[~${PWD#${HOME}}] " ;;
        *)          PS1="${PROMPT}[${PWD}] " ;;
    esac
}

> case `id -u` in
>         0) PS1="${PS1}# ";;
>         *) PS1="${PS1}$ ";;
> esac
> 
> I want to introduce a ^J or \n in the "case" so that my prompt

PS1="${PS1}
\$ "

However, this will screw up. sh assumes that all the characters in
PS1 print as one character on the same line. Putting a newline (or
terminal control sequences) there will confuse the command line
editor about the length of the line, and you will get strange
effects when entering and editing long lines.

Basically, what you are trying to do is beyond the capabilities of
sh.

-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8gqsgm$311u$1>