Skip site navigation (1)Skip section navigation (2)
Date:      30 Mar 2000 00:03:31 +0200
From:      naddy@mips.rhein-neckar.de (Christian Weisgerber)
To:        freebsd-questions@freebsd.org
Subject:   Re: Prompt and Path questions
Message-ID:  <8btujj$1peq$1@bigeye.rhein-neckar.de>
References:  <200003290559.AA228787102@mail.ev1.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Vodyanoi <hawk76@mail.ev1.net> wrote:

> PS1="`whoami`@`hostname | sed 's/\..*//'`"
                 ^^^^^^^^^^^^^^^^^^^^^^^^
Simpler:               hostname -s

>  case `id -u` in
>         0) PS1="${PS1}|`pwd`# ";;
>         *) PS1="${PS1}|`pwd`$ ";;
>  esac

This doesn't work because `pwd` is expanded at the time you assign
this value to PS1. Also, contrary to for instance ksh, sh will not
expand variables when evaluating PS1.

> I searched the archives for the mailing list and found somethig
> about using CD insteadof PS1 but not sure what CD is or how to set
> that up.

prompt1="$(whoami)@$(hostname -s)|"

case $(id -u) in
    0) prompt2='# ' ;;
    *) prompt2='$ ' ;;
esac

cd()
{
    command cd "$@"
    PS1="${prompt1}${PWD}${prompt2}"
}

cd "${PWD}"     # initialize prompt

-- 
Christian "naddy" Weisgerber                  naddy@mips.rhein-neckar.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?8btujj$1peq$1>