[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Where is Bash Prompt Set??



Tony van der Hoff put forth on 2/11/2010 11:53 AM:

> So, I've set my PS1 in /root/.bashrc as suggested.
> From my user shell, I do 'su', and the prompt, and everything following
> is in red - good!
> CTRL-D returns me to my user shell, and everything is still red - bad!

CTRL-D is new to me.  Thanks for the trick.

> So, I figured that export PS1='\[\033[0;31m\u@\w$\033[0;30m \]' would
> return it back to black after the prompt - which it does, and I can live
> with that, but ideally, I'd like to save away the present colour, and
> restore it.
> Can anyone suggest how to do that?

It works for me.  I use this:

/root/.bashrc
export PS1="$(tput setaf 1)[\T]$(tput setaf 1)[\u@\h]$(tput sgr0)\w$ "

/home/stan/.bashrc
if [ "$PS1" ]; then
   PS1="$(tput setaf 2)[\T]$(tput setaf 2)[\u@\h]$(tput sgr0)\w$ "
fi

When I from su the prompt color is back to that defined directly above for user
stan.

> PS - where are these escape sequences documented, please?

I use this as my reference.  Not a bash manual, but works for me:

http://news.softpedia.com/news/How-to-Customize-the-Shell-Prompt-40033.shtml

-- 
Stan


Reply to: