Colouring in bash for OS-X

This blog post is more than 5 years old, so the content may be out of date.

I like colours. I like things to stand out. Most of all, I like to be very very clear which computer I'm using when I'm typing in commands (init 0; wait-no-that wasn't the production server, was it?!)

So I want my bash-prompt to look something like this:

deimos:~ marcus$

And production servers are even more apparent:

web1:~ marcus$

(OK, you probably shouldn't ever have to manually ssh into production servers...but just in case).

The bash prompt is controlled by the variable PS1. And OS-X reads the file ~/.profile when starting a new bash session. So you simply set PS1 in ~/.profile, and you're away.

echo "PS1='\[\e[1;32;40m\]\h\[\e[0m\]:\W \u\$ '" | cat >> ~/.profile

Blog tags:

Comments

Get some git love on your CLI

source ~/.bash_addons/git-completion.bash
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\W\[\033[00m\]$(__git_ps1 "(%s)") \$ '

@TODO Man, I need to fix my theme :-(

Nice tool tho!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.