[IPython-User] configuring prompts for custom substitutions

Thomas Kluyver takowl@gmail....
Thu Aug 23 16:58:08 CDT 2012

Hi Skipper,

On 23 August 2012 19:13, Skipper Seabold <jsseabold@gmail.com> wrote:
> I'm having some trouble working through the code. Is there anyway to inject
> user-defined (callable) substitutions into the prompts. E.g., something like

I don't have time to test at the moment, but I think you need to add
it using the IPython.core.prompts.LazyEvaluate wrapper, something like

def am_at_home():
    import os
    if os.path.expanduser('~') == os.path.abspath(os.path.curdir):
        return "(home)"
    return ""

get_ipython().prompt_manager.lazy_evaluate_fields['amathome'] = am_at_home
get_ipython().prompt_manager.in_template = '[\#]: {amathome}'

Note the new-style formatting syntax, rather than \amathome.

This example is written for a startup script -
PromptManager.lazy_evaluate_fields is not currently configurable (and
adding values to lists or dicts in configuration is awkward anyway.

Hope that helps,

More information about the IPython-User mailing list