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

color prompts



Hello!

I read in the Configuration HOWTO that RedHat & Slackware Linux can use
Escape control codes to add color support (and some default settings;
like LESS as a default pager) to the prompt line, see below:
_____
# /etc/profile

# System wide environment and startup programs
# Functions and aliases go in /etc/bashrc

# This file sets up the following features:
#
#   o path
#   o prompts
#   o a few environment variables
#   o colour ls
#   o less
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile

# set a decent path

echo $PATH | grep X11R6 > /dev/null
if [ $? = 1 ] ; then   # add entries to the path
  PATH="$PATH:/usr/X11R6/bin:$HOME/bin:."
fi

# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root's prompt is red.

USER=`whoami`
if [ $LOGNAME = $USER ] ; then
  COLOUR=44
else
  COLOUR=45
fi

if [ $USER = 'root' ] ; then
  COLOUR=41
fi

# put a real escape character instead of ^[. To do this:
# emacs: ^Q ESC   vi: ^V ESC   joe: ` 0 2 7   jed: ` ESC
# Remove `;1' if you don't like the `bold' attribute.
ESC=^[
PS1='$ESC[$COLOUR;37;1m$USER:$ESC[37;40;1m\w\$ '
PS2="Continue> "

# no core dumps, please

ulimit -c 0

# set umask

if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
  umask 002
else
  umask 022
fi

# a few variables

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
EDITOR=jed
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL EDITOR HOSTNAME HISTSIZE
HISTFILESIZE

# enable colour ls

eval `dircolors /etc/DIR_COLORS -b`
export LS_OPTIONS='-F -s -T 0 --color=tty'

# customise less

LESS='-M-Q'
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
VISUAL=jed
LESSCHARSET=latin1
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARSET

for i in /etc/profile.d/*.sh ; do
  if [ -x $i ]; then
    . $i
  fi
done

___

The important part is:

# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root's prompt is red.

USER=`whoami`
if [ $LOGNAME = $USER ] ; then
  COLOUR=44
else
  COLOUR=45
fi

if [ $USER = 'root' ] ; then
  COLOUR=41
fi

# put a real escape character instead of ^[. To do this:
# emacs: ^Q ESC   vi: ^V ESC   joe: ` 0 2 7   jed: ` ESC
# Remove `;1' if you don't like the `bold' attribute.
ESC=^[
PS1='$ESC[$COLOUR;37;1m$USER:$ESC[37;40;1m\w\$ '
PS2="Continue> "


I tried to make this work, so the prompt is in color, but instead it
outputs the PS1= line almost verbatim for a prompt.  Can this work in
debian?  Do I need to change something?

Thanks for any feedback

Dave Jones



--  
Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null


Reply to: