1

How to make ipdb prompt colored?

It's difficult to navigate between prints:

enter image description here

warvariuc
  • 57,116
  • 41
  • 173
  • 227

1 Answers1

2

There doesn’t appear to be an official way to support this, but it can be easily done by editing the source file in your installation. Go to your site packages directory and

grep -r "ipdb>" *

You’ll see something like this:

ipython-2.1.0-py27_2/lib/python2.7/site-packages/IPython/core/debugger.py:42:prompt = 'ipdb> '

Make a backup of that file, then replace the line with what you’d like the prompt to be, including standard color codes. This will make the prompt green, for example:

prompt = '\x1b[32mipdb> \x1b[0m'

There are many places where you can look up more codes for more customization, e.g. http://www.linuxhowtos.org/Tips%20and%20Tricks/ansi_escape_sequences.htm.

Of course, you will have to repeat these steps with any iPython update.

Demitri
  • 13,134
  • 4
  • 40
  • 41
  • I accepted the answer, though I don't like this hack. I have many virtual environments, so I need to do this in all of them. Or make a fork and `pip install` it. Or use system site packages, which is also ugly... – warvariuc Sep 21 '14 at 17:13
  • 1
    Yes, it’s a hack, and I’m not thrilled with it either. I just didn’t see an “official” supported way to do it, but this is a simple patch that works until then. Then again, this is what’s great about open source software! – Demitri Sep 21 '14 at 18:45