Re: Yikes! Where is my prompt config hiding?

Re: Yikes! Where is my prompt config hiding?

am 15.04.2008 06:15:53 von googlegroups

On Apr 14, 2:26 pm, Wayne wrote:
> 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 thepromptwill 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'sprompt; 34m is bluepromptfor 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

OK. How would you avoid using "PROMPT_COMMAND"? Just
not put it in any bashrc files?

Re: Yikes! Where is my prompt config hiding?

am 15.04.2008 09:30:31 von Joachim Schmitz

W. D. wrote:
> On Apr 14, 2:26 pm, Wayne wrote:
>> 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 thepromptwill 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'sprompt; 34m is bluepromptfor 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
>
> OK. How would you avoid using "PROMPT_COMMAND"? Just
> not put it in any bashrc files?
in root's .bashrc:
PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
in every one else's .bashrc:
PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt

Or in /etc/profile
if [ "$UID" = 0 ];then
PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
else
PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
fi

\$ in a bash prompt turns into $ for mere mortals and into # for root
\w expands to the current directory, with the user's home being shortened to
~

Bye, Jojo

Re: Yikes! Where is my prompt config hiding?

am 15.04.2008 21:58:44 von wayne

Joachim Schmitz wrote:
> W. D. wrote:
>> On Apr 14, 2:26 pm, Wayne wrote:
>>> 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 thepromptwill 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'sprompt; 34m is bluepromptfor 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
>> OK. How would you avoid using "PROMPT_COMMAND"? Just
>> not put it in any bashrc files?
> in root's .bashrc:
> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
> in every one else's .bashrc:
> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>
> Or in /etc/profile
> if [ "$UID" = 0 ];then
> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
> else
> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
> fi
>
> \$ in a bash prompt turns into $ for mere mortals and into # for root
> \w expands to the current directory, with the user's home being shortened to
> ~
>
> Bye, Jojo
>
>

Also put "PROMPT_COMMAND=''" in /etc/bashrc, to eliminate the
default.

-Wayne

Re: Yikes! Where is my prompt config hiding?

am 16.04.2008 10:18:51 von Joachim Schmitz

Wayne wrote:
> Joachim Schmitz wrote:
>> W. D. wrote:
>>> On Apr 14, 2:26 pm, Wayne wrote:
>>>> 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 thepromptwill
>>>>> 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'sprompt; 34m is bluepromptfor 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
>>> OK. How would you avoid using "PROMPT_COMMAND"? Just
>>> not put it in any bashrc files?
>> in root's .bashrc:
>> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
>> in every one else's .bashrc:
>> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>>
>> Or in /etc/profile
>> if [ "$UID" = 0 ];then
>> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
>> else
>> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>> fi
>>
>> \$ in a bash prompt turns into $ for mere mortals and into # for root
>> \w expands to the current directory, with the user's home being
>> shortened to ~
>>
>> Bye, Jojo
>>
>>
>
> Also put "PROMPT_COMMAND=''" in /etc/bashrc, to eliminate the
> default.
The is no default (as long as it is not explicitly set). And rather than
setting it to be empty, in case it is set somewhere I'd just unset it to get
rid of it.

Bye, Jojo

Re: Yikes! Where is my prompt config hiding?

am 16.04.2008 10:57:46 von Dave B

On Tuesday 15 April 2008 09:30, Joachim Schmitz wrote:

> in root's .bashrc:
> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
> in every one else's .bashrc:
> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>
> Or in /etc/profile
> if [ "$UID" = 0 ];then
> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
> else
> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
> fi

FWIW, another way is to do

red="\[`tput setaf 1`\]"
blue="\[`tput setaf 4`\]"
etc.

to avoid hardcoding ansi escape sequences in the scripts.

--
D.

Re: Yikes! Where is my prompt config hiding?

am 16.04.2008 21:55:04 von cfajohnson

On 2008-04-16, Dave B wrote:
> On Tuesday 15 April 2008 09:30, Joachim Schmitz wrote:
>
>> in root's .bashrc:
>> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
>> in every one else's .bashrc:
>> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>>
>> Or in /etc/profile
>> if [ "$UID" = 0 ];then
>> PS1='\[\033[01;31m\]\u@\h \w \$\[\033[0m\] ' # red prompt
>> else
>> PS1='\[\033[01;34m\]\u@\h \w \$\[\033[0m\] ' # blue prompt
>> fi
>
> FWIW, another way is to do
>
> red="\[`tput setaf 1`\]"
> blue="\[`tput setaf 4`\]"
> etc.
>
> to avoid hardcoding ansi escape sequences in the scripts.

That may or may not work. On Linux, it does; on FreeBSD, it
doesn't.

Hardcoding the sequences is at least as portable as tput, but
putting the values in variables is a good idea.

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence