For a while now I've used colored prompts in bash. I typically make the machine name one color, the path another color, and the username bright red if I'm root. On some systems I show the date and time, the exit code of the previous command, whether I'm inside screen, or the ssh status. Other people have put the git branch, number of processes, job count, tty, system load, disk space, working files, or mailbox status into their prompts.
On the Mac though, once I upgraded to Leopard, the prompts interacted badly with the line-editing. I tried various things but just couldn't get them to work, and I really wanted line editing, so I gave up on the colored prompts.
However, I recently figured out a fix: set the language environment variable. Which one? I tried a few and ended up with this:
Does anyone know why this helps?
Here's how I set my bash prompt (from
# Username (if root or remote) if [ "$(whoami)" = "root" ]; then PS1="\[\e[41;1;37m\] root" elif [ -n "$SSH_CLIENT" ]; then PS1="\[\e[30;107m\]\u" else PS1="" fi # Machine (if remote) if [ -n "$SSH_CLIENT" ]; then PS1="$PS1@$hostname:" fi # Current directory PS1="$PS1\[\e[34m\]\w/ \[\e[0m\]\$ " # Current date and time PS1="\[\e[0;90m\] \d \[\e[1m\]\t\[\e[0m\]\r\n$PS1" # Screen name (if inside a screen) if [ -n "$STY" ]; then PS1=" \[\e[32m\]$STY\[\e[0m\]$PS1" fi # Display a smiley for success/failure PS1="\`if [ \$? = 0 ]; then echo \[\e[42\;37m\]:\\);\ else echo \[\e[41\;37m\]:\\(; fi\`\[\e[0m\] $PS1"
Now that I have colors working again, I'll probably read what other people have done and adopt interesting features.