Coloured Terminal Prompt

We live in a world of colour and most of us have colour monitors. Why then should we put up with boring terminals? Check out this coloured prompt code.

terminal

I could have sworn I blogged about this ages ago but I can’t find it. Anyway, this is a short one. I have a range of boards from Raspberry Pi through NEOs, Beaglebones and many others and at one time or another I end up using the terminal – usually using WinSCP. In some setups the prompt is already pretty coloured – in other cases it is depressingly boring.

Here’s a quick fix  - different setups may vary and how you wish to do this may vary.

So your terminal prompt in Debian and Ubuntu (maybe others for all I know) is controlled by a simple variable called PS1.

Try it… go to this link… http://bashrcgenerator.com/

coloured prompt generator

The page is great fun – you can decide what you want in your prompt – and what colour you want for each bit.

So the string you see in the right (white) box above right.  If you just drop everything right of “export” into your terminal – your prompt will immediately change, but you’ll lose it on power up.

In my case I found that /etc/bash.bashrc has one of these and I just replaced it. Then for the users I want the colour to work – I went to /root or /home/pi and edited the .bashrc file – un-commenting the line that says “

force_color_prompt=yes

and commenting out everything after that to do with the prompt… here is (and this will vary) what I commented out. It comes just after that variable assignment.

#if [ -n "$force_color_prompt" ]; then
# if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
#   color_prompt=yes
# else
#   color_prompt=
# fi
#fi
#if [ "$color_prompt" = yes ]; then
# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#else
# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
#i
#unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
# PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
## ;;
#*)
# ;;
#esac

And that’s it. Simple, trivial you may say but if you like a colourful world…

Facebooktwittergoogle_pluspinterestlinkedin

10 thoughts on “Coloured Terminal Prompt

    1. Before even that I was running a "bulletin board" - which had a nice dark blue graphic screensaver... in ascii coloured text (256 colour limit) 🙂 Sat there 24 hours a day synchronising email for people - and then at night someone would ring in and sync and sent it off to London - who would exchange mail overseas and then all the way back up. All I believe at 300 baud. That's 30 characters a second 🙂 This was necessary to keep telephone costs low - and people complain about telephones - before it was opened to competition - the British phone system was horrendous.

  1. I knew there had to be a way of spicing up this program. Thanks for all of the insight guys. I've never really done any searching for these types of changes. Stare at the ugly black on white, even green on black needs a little tweaking.

    Thanks for the info.

Leave a Reply

Your email address will not be published. Required fields are marked *