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

Re: Where is Bash Prompt Set??



Jon Dowland put forth on 2/17/2010 3:48 AM:
> On Thu, Feb 11, 2010 at 10:20:47PM -0600, Stan Hoeppner wrote:
>> 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
> 
> The problem with that is, you are only invoking it on login.

Why is this a problem?  If I'm not logged in, why does this shell setup code
need to be invoked.  Makes perfect sense to me that it is only invoked on login.
 Am I missing something?

> This together with
> 
>> CTRL-D is new to me.  Thanks for the trick.
> 
> suggests you are logging from your root user back into your
> normal user, never logging out of these shells, and the
> older shell processes are hanging around, like this:

I have no idea where you came up with that.  What do you see that "suggests"
this?  The shells are being properly logged out:

[04:39:21][root@greer]/$ ps
  PID TTY          TIME CMD
25938 pts/0    00:00:00 su
25939 pts/0    00:00:00 bash
25949 pts/0    00:00:00 ps
[04:39:34][root@greer]/$ exit
exit
[04:39:42][stan@greer]~$ ps
  PID TTY          TIME CMD
25867 pts/0    00:00:00 bash
25951 pts/0    00:00:00 ps

And when I exit su, the prompt colors properly change back to the stan user.
Believe me, of all people, if processes were left hanging around, _*I*_ would be
the first to notice and fix ir.  I run Samba from inet to cut down on needless
processes for Pete's sake. ;)  I'm a process efficiency freak.  As a matter of
fact I've been trying to figure out the last couple of days how to get my
dovecot-auth process count back down to 1 since upgrading to the Dovecot 1.2.10
backport.  For some reason it just doesn't want to run with less than 2 auth
processes.  I only need one. I'll get it figured out soon.

> What you really want to do is execute some code as root on
> logout. 

Why?  It works perfectly.  Well, except for an unrelated command line wrap
issue, but I'll work that out as soon as it bugs me enough.  It applies to both
user shells, something in my PS1 export probably as I don't recall the issue
before those changes to the PS1s.

> One hacky way to do it is to call reset in root's
> logout script:
> 
>     $ sudo su -
>     root promptroot@~# cat .bash_login
>     export PS1='root prompt\[\033[0;31m\u@\w\$\033[0;30m \]'
>     root promptroot@~# cat .bash_logout
>     reset
>     root promptroot@~# 
>     <screen clears>
>     $ 
> 
> This is a bit slow, mind, if you really want to change the
> text colour for the root user then you should "unwind" the
> control characters instead by preserving the older PS1 and
> keeping track of which control sequences you've "opened":
> 
>     ~root/.bash_login:
>         export OLDPS1="$PS1"
>         export PS1="whatever you want"
>     ~root/.bash_logout:
>         echo "control chars that reset the text colours"
>         export PS1="$OLDPS1"

Again, why would I want to do this when the coloring etc works properly already
when switching into and out of su?  I must be missing something in your madness. ;)

-- 
Stan


Reply to: