Tuesday Terminal Tip: add some colour to your prompt

03 December 2013

It’s the little things that make all the difference. I often find myself with a few terminal windows open, jumping between hosts, getting rather lost as to where I am. Accidentally running things in production instead of a development environment makes me unhappy, so I wanted an easy, in-your-face-but-not-too-much way of seeing what environment I was in. We actually did this ages ago, but it’s a little tricky to get right so thought it still worth a quick write-up.

painting the prompt red

I’ve seen people who have coloured the entire terminal background according to the environment they were in, but that fails the “not-too-much” part of the requirement. Instead I went for the more subtle option of colouring the prompt:


In my face, but not too in my face.

It’s made problematic because you need to escape the colour codes. If you don’t, you get some weird behaviour when the line wraps then you delete as the terminal gets confused about line length. I can’t remember whose advice I followed at the time, so I can’t credit them, but I did get there with the help of others to arrive at something like this in /etc/bashrc:

I’ll spare you the complexity of how we incorporated this into our Puppet set-up, but let’s just assume you have a file /etc/env simply containing prod, stage, or dev.

If you’ve got any little tips like this that make your life easier, do let me know.

blog comments powered by Disqus