[Cialug] wish list for ssh/gnome terminal

Nathan Stien nathanism at gmail.com
Fri Nov 2 16:25:42 CDT 2007


On Nov 2, 2007 3:59 PM, Nathan Stien <nathanism at gmail.com> wrote:
> Anyways, these days I just color-code my bash prompt on each machine
> in the .bashrc, and then it kicks in even if I connect somewhere else
> mid-session, or if I connect from somewhere else.  Low tech, but it
> works for me.
>
> In fact, here's a little page about it:
> http://www.linuxfocus.org/English/May2004/article335.shtml

Hmm, on second thought, that page is wrong.  You need to enclose
non-printing sequences in \[ \] pairs so that bash can calculate how
wide your prompt is.  It will be subtly screwy if you don't enclose
each ANSI sequence in \[ \].

I do it like this:

# color defs
PLAIN="\[\e[00m\]"
GREEN="\[\e[32m\]"
YELLOW="\[\e[33m\]"
BLUE="\[\e[34m\]"
BRIGHTBLUE="\[\e[01;34m\]"
# etc...

case "$TERM" in
xterm-color|xterm|cygwin)
    PS1="${GREEN}\u${YELLOW}@${GREEN}\h${PLAIN}:${BRIGHTBLUE}\w${PLAIN}$ "
    ;;
*)
    PS1="\u@\h:\w$ "
   ;;
esac


- Nathan


More information about the Cialug mailing list