FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 02-17-2010, 08:57 AM
Jon Dowland
 
Default Where is Bash Prompt Set??

On Wed, Feb 17, 2010 at 09:48:32AM +0000, Jon Dowland wrote:
> 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":

Working example of this:

~root/.bash_login
OLDPS1="$PS1"
PS1='[e[0;1;31m]$ '

~root/.bash_logout
echo -en 'e[0m'
PS1="$OLDPS1"
 
Old 02-17-2010, 09:59 AM
Stan Hoeppner
 
Default 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[33[0;31mu@w$33[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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4B7BCC15.3030907@hardwarefreak.com">http://lists.debian.org/4B7BCC15.3030907@hardwarefreak.com
 
Old 02-17-2010, 11:30 AM
Jon Dowland
 
Default Where is Bash Prompt Set??

On Wed, Feb 17, 2010 at 04:59:33AM -0600, Stan Hoeppner
wrote:
> 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?

I should clarify. This is only a problem if you are trying
to colour (or otherwise influence) the formatting of the
text you type at the root prompt. One of the OPs is trying
this. You are not.

For the poster who wanted to colour their root text by
opening an escape and not resetting it again, they will
need to ensure that there is a reset at some point between
their root prompt and their user prompt.

In your case, your user PS1 begins by resetting/closing the
formatting: that's one of the effects of the output of
$(tput setaf 2).

If you were trying to do this, and your user's PS1 had some
text that came before your call to tput, it would be
coloured according to whatever formatting you had applied in
your root PS1.

> I have no idea where you came up with that. What do you
> see that "suggests" this?

I have misunderstood what you were saying. When you revealed
you were not aware of CTRL+D I believed you must have been
switching authorisations by repeating 'su'. So you were
typing 'exit' or 'logout' every time instead?

> 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.

Well, your user and root PS1s are invoking three tput(1)
processes for every command you enter. If you replace them
with raw escape sequences as in some of the other examples,
you'll save rather a lot of processes. (at the expense of
tying your PS1 to a particular terminal type. Do you
regularly use myriad terminal emulators?)


--
Jon Dowland
 

Thread Tools




All times are GMT. The time now is 04:00 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org