ipython_notes
This is an old revision of the document!
Table of Contents
favorite configuration
configure prompts
Create a profile (~/.ipython/profile_default/ipython_config.py) if it is not already created by running
ipython profile create
Add the following to ~/.ipython/profile_default/ipython_config.py
#------------------------------------------------------------------------------ # Customize terminal prompts. # The goal here is to make it easy to copy paste stuff from/to ipython # sessions. This is achieved by # * adding an extra line to the input and output prompts # * removing the continuation prompt # To build the original prompt, I am using # https://github.com/ipython/ipython/blob/master/IPython/terminal/prompts.py from IPython.terminal.prompts import Prompts from pygments.token import Token class MyPrompt(Prompts): # keep the original input prompt but add an extra line def in_prompt_tokens(self): return [ (Token.Prompt, self.vi_mode() ), (Token.Prompt, 'In ['), (Token.PromptNum, str(self.shell.execution_count)), (Token.Prompt, ']: '), (Token.Prompt, '\n'), ] # remove the continuation prompt. def continuation_prompt_tokens(self, width=None): return [ (Token.Prompt, ''), ] # keep the original output prompt but add an extra line def out_prompt_tokens(self): return [ (Token.OutPrompt, 'Out['), (Token.OutPromptNum, str(self.shell.execution_count)), (Token.OutPrompt, ']: '), (Token.OutPrompt, '\n'), ] c.TerminalInteractiveShell.prompts_class = MyPrompt #------------------------------------------------------------------------------
tags | add a newline to ipython input prompt, change ipython terminal prompts
dummy
how is the default ipython prompt created?
See https://github.com/ipython/ipython/blob/master/IPython/terminal/prompts.py → Prompts class → in_prompt_tokens(), continuation_prompt_tokens(), rewrite_prompt_tokens(), out_prompt_tokens()
ipython_notes.1602709947.txt.gz · Last modified: 2020/10/14 21:12 by prasanthi