User Tools

Site Tools


ipython_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ipython_notes [2020/10/14 21:14] – [configure prompts] prasanthiipython_notes [2022/03/18 22:36] (current) – [command history] raju
Line 1: Line 1:
 ===== favorite configuration ===== ===== favorite configuration =====
 ==== configure prompts ==== ==== configure prompts ====
- +* [[Configure ipython terminal prompts]] 
-Create profile (~/.ipython/profile_default/ipython_config.py) if it is not already created by running+===== dummy ===== 
 +==== command history ==== 
 +IPython stores the history in SQLite database located at ~/.ipython/profile_default/history.sqlite . 
 +This can be exported into a file by running
 <code> <code>
-ipython profile create+%history -g -f filename
 </code> </code>
-Add the following to ~/.ipython/profile_default/ipython_config.py +When using Windows 10 Enterprise + git bash 2.22.0 + ipython 7.16.1 
-<code+<WRAP indent
-#------------------------------------------------------------------------------ +Examples of valid filenames 
-# Customize terminal prompts+  * ipython_history_asof_20220318_1753.txt 
-# The goal here is to make it easy to copy paste stuff from/to ipython +  * x/ipython_history_asof_20220318_1755.txt 
-# sessionsThis is achieved by +  c:/Users/raju/x/ipython_history_asof_20220318_1756.txt
-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): +Examples of invalid filenames 
- +  * ~/x/ipython_history_asof_20220318_1755.txt 
-    # keep the original input prompt but add an extra line +  * /c/Users/raju/x/ipython_history_asof_20220318_1756.txt 
-    def in_prompt_tokens(self): +</WRAP> 
-        return [ +Ref:- 
-            (Token.Prompt, self.vi_mode() ), +  * https://stackoverflow.com/questions/30629390/where-is-the-history-file-for-ipython 
-            (Token.Prompt, 'In ['), +  * ~/.ipython/profile_default/history.sqlite - 
-            (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 +
-#------------------------------------------------------------------------------ +
-</code> +
- +
-tags | add a newline to ipython input prompt, change ipython terminal prompts, ipython paste without the dots +
-===== dummy =====+
 ==== how is the default ipython prompt created? ==== ==== 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() 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.1602710070.txt.gz · Last modified: 2020/10/14 21:14 by prasanthi