GDB Prompt in Colour

Just because you can.

gdb colour prompt

Yeah, I know, why bother when you can use a nice front end like Eclipse, or DDD, or CGDB or blah blah blah.

If you just like to use it in its raw form on the command line (which, let’s face it, is the best way), you can pretty-up your GDB prompt with a really simple command.

Just load up GDB and type the following:

set prompt \033[0;32m(gdb) \033[0m

to set the prompt to a lovely green colour.

Or try this:

set prompt \033[0;34m(gdb) \033[0m

to change it to a nice, eye-catching blue.

You could even add the above line to the .gdbinit file in your home directory, so you always get a nice colourful prompt without having to think about it (see here for a brief guide to using .gdbinit files).

How does that work then?

It just uses the ANSI escape sequences (essentially a collection of non-printed text formatters) for colours – I might write up the escape sequences, and fun things you can do with them, in a future post, but for now the command above breaks down as follows:

\033 – this is the “escape” character
[ – escape is always followed by an open square bracket
0;34m – this is the colour. The zero is for bold (0 for off, 1 for on). The m indicates graphics mode.
(gdb) – this is your standard prompt
\033 – another escape sequence follows
[ – with the usual square bracket
0m – this reverts the graphics mode back to the default colour

For more colours, see the list here.