Update to the newly release ipython5 today. Started up the interactive prompt and received:
/usr/local/lib/python3.5/site-packages/IPython/core/interactivesh
Simple example showing how to color the prompt in red:
from IPython.terminal.prompts import Token
ipy_config = get_config()
ipy_config.TerminalInteractiveShell.highlighting_style_overrides = {
Token.Prompt: '#ff0000',
}
More advanced example that changes prompt color according to environment variable (useful if you play alot with staging/live systems):
# Example showing how to change color of prompt and prompt string in specific environments.
# put into ~/.ipython/profile_${YOURPROFILE}/ipython_config.py and start ipython with:
# PROFILE_LIVE ipython --profile ${YOURPROFILE}
import os
from IPython.terminal.prompts import Prompts, Token
ipy_config = get_config()
class MyPrompt(Prompts):
environment = None
def in_prompt_tokens(self, cli=None):
return [
(Token.Prompt, '{} ['.format(MyPrompt.environment)),
(Token.PromptNum, str(self.shell.execution_count)),
(Token.Prompt, ']: ')
]
if 'PROFILE_LIVE' in os.environ:
ipy_config.TerminalInteractiveShell.highlighting_style_overrides = {
Token.Prompt: '#ff0000',
}
MyPrompt.environment = 'LIVE'
ipy_config.TerminalInteractiveShell.prompts_class = MyPrompt