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

Re: ANSI Color Escapes in $PS1.. heh.



maximill@shelob.classrooms.washington.edu writes:

> How would one check to make sure the terminal is capable of ANSI escape
> sequences?
> 
> -brad

I'd do this by not coding in the escape sequences directly, but by using 
tput:
export PS1="\[`tput setaf 1`\]\u@\h\[`tput sgr0`\]:\[`tput setaf 4`\]\w\[`tput sgr0`\]\$ "

"tput" is a command-line interface into the terminfo database - if
your terminal is known to be able to handle colors, it'll generate
escape codes and if not it'll generate nothing.  Thus, this prompt
line works just as well on a color-capable xterm as it does on an old
Wyse terminal (which not only can't do color, but barfs if handed
VT-style escape codes).


Reply to: