[Gllug] Changing the text colour at the command line
Pete Ryland
pdr at pdr.cx
Sun Dec 8 16:46:23 UTC 2002
On Sun, Dec 08, 2002 at 04:27:37PM +0000, Stig Brautaset wrote:
> On Dec 08 2002, Laurie wrote:
> > Hi
> >
> > I have playing around with my PS1 and PS2 enviroment variables.
> > I have created a more interesting command line prompt, which is
> > different for users and root It also means that when I enter commands
> > at the command line the commands are in red when it is root and green
> > when i'm a user
> > I'm quite happy about that and think it looks cool What I have a
> > problem with is that when I logout The login prompt is in the colour
> > of the last person i.e green text if the last person was a user red
> > text if the last person was root
> > I want the logging prompt to go back to being white and only change
> > colour when I login Is there a text enviroment variable?
> > also is there anything like a "unprofile" script which runs when you
> > logout?
> > I was thinking I could make a script change the variable when I logout
> > or shutdown?
>
> try to put this in your ~/.bash_logout:
>
> PS1=""
> PS2=""
> export PS1 PS2
echo \033[0;37m
is a more likely candidate. These are basically ANSI escape sequences. The
thing is, the way they work is that when you set the foreground colour it
will stay that way (in the terminal) until you set it to something else.
The escape sequence above will change it back to grey.
I use colours as well, but also to signify whether I have an appropriate
DISPLAY env var (that is, whether I can run X programs from that prompt).
In case you're interested, my PS1 is set like such:
COLORNORMAL="\[\033[0;37m\]"
U="\u"
H="\h"
if ! [ -z "$DISPLAY" ]; then
if [ "$DISPLAY" = ":0.0" ] || [ "$DISPLAY" = ":1.0" ]; then
# Local
H="\[\033[0;32m\]\h\[\033[0;37m\]"
else
# Remote connection
H="\[\033[0;36m\]\h\[\033[0;37m\]"
fi
fi
if [ "$UID" = "0" ]; then
U="\[\033[0;31m\]\u$COLORNORMAL"
fi
export PS1="$U@$H:\w\\$ "
I can't remember how much of this is Debian defaults - possibly all of it.
Note, though, that I set the colour back to normal after each coloured bit,
and that the format (username at host:directory) is still cut and pastable into
commands like rsync.
Pete
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list