How to include your hostname in the IPython 5 prompt?
<p>In previous version of IPython it was easy to include your hostname in the prompt, by including the following in your config:</p>

<pre><code>c.PromptManager.in_template = '(\H) In [\\#]: '
</code></pre>

<p>(the <code>\H</code> would be substituted with your hostname).</p>

<p>However, the <code>PromptManager</code> config has been removed in IPython 5.  I see the following warning when I try to use it:</p>

<pre><code>/env/lib/python2.7/site-packages/IPython/core/interactiveshell.py:448: UserWarning: As of IPython 5.0 `PromptManager` config will have no effect and has been replaced by TerminalInteractiveShell.prompts_class
  warn('As of IPython 5.0 `PromptManager` config will have no effect'
</code></pre>

<p>So how do I achieve a similar effect with IPython 5?</p>

<p>As the warning indicates, you should use the new <code>TerminalInteractiveShell.prompts_class</code>.  So to include your hostname in your prompt you can drop the following in your config:</p>

<pre><code>from IPython.terminal.prompts import Prompts, Token
import socket

class MyPrompt(Prompts):
    def __init__(self, *args, **kwargs):
        hn = socket.gethostname()
        self._in_txt = '({}) In ['.format(hn)
        self._out_txt = '({}) Out['.format(hn)
        super(MyPrompt, self).__init__(*args, **kwargs)

    def in_prompt_tokens(self, cli=None):
        return [
            (Token.Prompt, self._in_txt),
            (Token.PromptNum, str(self.shell.execution_count)),
            (Token.Prompt, ']: '),
        ]

    def out_prompt_tokens(self):
        return [
            (Token.OutPrompt, self._out_txt),
            (Token.OutPromptNum, str(self.shell.execution_count)),
            (Token.OutPrompt, ']: '),
        ]
</code></pre>

<p>Results in the following prompt:</p>

<pre><code>(marv) In [1]: 'hello, world'
(marv) Out[1]: 'hello, world'
</code></pre>

python ipython