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

Re: color prompts



Dave Jones said
> Hello!
Hello Dave!

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

Here are my comments to your configurations - I've deleted lines that I  don't
have questions or comments regarding.

> _____
> # /etc/profile
> 
> echo $PATH | grep X11R6 > /dev/null
> if [ $? = 1 ] ; then   # add entries to the path
>   PATH="$PATH:/usr/X11R6/bin:$HOME/bin:."
> fi
> 
Why not just add the directories to the path initially?  I set all environment
variables in /etc/environment and play some tricks so it can be read from
bash-like shells as well as csh-like shells.  I do the same for ~/.env.

This way there is one and only one location for system-wide environment
variables and one and only one place for user-specific variables.

> # 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
> 
I've tried running the fllowing from login and non-login shells
	bash > echo $USER $LOGNAME
	stick stick

The results have always been the same - are we using the same terminology?


> ESC=^[
> PS1='$ESC[$COLOUR;37;1m$USER:$ESC[37;40;1m\w\$ '
> PS2="Continue> "
> 
Here's my PS1 line from /etc/environment:
	${_envcmd_} PS1${_enveq_}"\[^[[33;1m\]\u@\h\[^[[0m\]: "

Where bash-like shells set:
	_envcmd_="export" & _enveq_="="
While csh-like shells set:
	+envcmd_="setenv" & _enveq_=" "

Note: The "\[" and "\]" are bash specific escape sequences that 'hide" the
enclosed characters so they aren't counted in determining the cursor's location.
a better explanation is included in bash's man page.  To be honest, this
PS1 should be set in a bash-specific location until such time as I can get
tcsh to handle color prompts...

> 
> if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
>   umask 002
> else
>   umask 022
> fi
> 
I think that 002 is a fine umask for all users - Debian handles groups in
such a way as to make twiddling umask values unnessesary.  BTW, I'm paraniod
and have umasks of 007 for the default.

> # 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'
> 
I typically use --color=always...or at least have been for the past couple
of weeks...

> # customise less
> 
> LESS='-M-Q'
> 
Setting the '-r' option on less allows for paging color output.
Try this command:
	bash > ls -l --color=always | less -r

When I do this I get paged color output...YMMV.

> # notify the user: login or non-login shell. If login, the prompt is
> # coloured in blue; otherwise in magenta. Root's prompt is red.
> 
Is there a better way to determine whether or not their shell is a login
shell or not?  This seems akward at best...though I'm not convinced that
it's all that needed...

> 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?
> 
Looking at that line again, I'd say try adding "{" and "}" around your
variables, like this:

PS1='${ESC}[${COLOR};37;1m${USER}:${ESC}[37;40;1m\w\# '

> Thanks for any feedback
> 
I hope this helps.

> Dave Jones
> 

BTW, I also set the following for xterms:

PROMPT_COMMAND='echo -ne "\033]2;$TERM: $USER@$HOSTNAME:/$PWD/ \007\033]1;$PWD\007"

This changes the title bar of my xterm to show user, host and cwd.

Stick
-- 
Chuck Stickelman, Owner			E-Mail:	<stick@richnet.net>
Practical Network Design		Voice:	+1-419-529-3841
9 Chambers Road				FAX:	+1-419-529-3625
Mansfield, OH 44906-1301 USA


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


Reply to: