On Tue, Feb 09, 2010 at 08:39:49AM -0900, Britton Kerin wrote: > Well ok its not just a plain colored prompt, what I would like to use is > this: > > txtred='\e[0;31m' # Red > bldgrn='\e[1;32m' # Green > txtrst='\e[0m' # Text Reset > PROMPT_COMMAND=' \ > if [ $? -eq 0 ]; then \ > PROMPT_PREFIX="$txtred"; \ > else \ > PROMPT_PREFIX="$bldgrn$? "; \ > fi ' > > PS1='$(echo -ne "$PROMPT_PREFIX")'"\$\[$txtrst\] "
Mixing PROMPT_COMMAND and PS1 is usually a bad idea. You can do this using PS1 alone. Remember that all non-printing bytes must be enclosed in literal \[ \] pairs. red=$(tput setaf 1) green=$(tput setaf 2) reset=$(tput sgr0) color=("$red" "$green") PS1='\[${color[$?==0]}\...@\h:\w\$\[$reset\] ' (A bit confusing, using C-like evaluation where true is 1 and false is 0, which is the opposite of bash... hence red being mapped to color[0] instead of color[1]. But I hope you can understand it without further explanation.)