Re: Yikes! Where is my prompt config hiding?

Re: Yikes! Where is my prompt config hiding?

am 10.04.2008 23:18:46 von Hans-Peter Sauer

On Thu, 10 Apr 2008 12:23:05 -0700, W. D. wrote:

> Can anyone else help me to automatically show:
> somehost someuser /somedir#
> Instead of:
> bash-3.1#

To apply it to everyone, copy-n-paste the following into /etc/bashrc,
otherwise into your $HOME/.bashrc and the prompt will be active next
shell you open, or into any window to make it immediately active:

export PROMPT_COMMAND='PS1=`if test "$UID" = 0 ; then \
echo "\[\033[01;31m\]\u@\h $(pwd)]#\[\033[0m\] " ; \
else \
echo "\[\033[01;34m\][\u@\h $(pwd)]$\[\033[0m\] " ; \
fi `'

The 31m is red for root's prompt; 34m is blue prompt for everyone not
root. Feel free to change them to whatever suits your eyes.

Re: Yikes! Where is my prompt config hiding?

am 14.04.2008 21:26:32 von wayne

Greg Russell wrote:
> On Thu, 10 Apr 2008 12:23:05 -0700, W. D. wrote:
>
>> Can anyone else help me to automatically show:
>> somehost someuser /somedir#
>> Instead of:
>> bash-3.1#
>
> To apply it to everyone, copy-n-paste the following into /etc/bashrc,
> otherwise into your $HOME/.bashrc and the prompt will be active next
> shell you open, or into any window to make it immediately active:
>
> export PROMPT_COMMAND='PS1=`if test "$UID" = 0 ; then \
> echo "\[\033[01;31m\]\u@\h $(pwd)]#\[\033[0m\] " ; \
> else \
> echo "\[\033[01;34m\][\u@\h $(pwd)]$\[\033[0m\] " ; \
> fi `'
>
> The 31m is red for root's prompt; 34m is blue prompt for everyone not
> root. Feel free to change them to whatever suits your eyes.

It is worth pointing out you can put this test logic in the
user's and root's .bashrc file and not use PROMPT_COMMAND.
Using PROMPT_COMMAND messes up the exit status, since
whatever command you think you ran last, you really
ran the echo in PROMPT_COMMAND. (This is not a problem
in a script, but can make interactive testing difficult.)

-Wayne