File: cwd_prompt.py

package info (click to toggle)
ipython 5.8.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,600 kB
  • sloc: python: 34,423; makefile: 174; sh: 143
file content (26 lines) | stat: -rw-r--r-- 616 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""This is an example that shows how to create new prompts for IPython
"""

from IPython.terminal.prompts import Prompts, Token
import os

class MyPrompt(Prompts):

     def in_prompt_tokens(self, cli=None):
         return [(Token, os.getcwd()),
                 (Token.Prompt, '>>>')]

def load_ipython_extension(shell):
    new_prompts = MyPrompt(shell)
    new_prompts.old_prompts = shell.prompts
    shell.prompts = new_prompts

def unload_ipython_extension(shell):
    if not hasattr(shell.prompts, 'old_prompts'):
        print("cannot unload")
    else:
        shell.prompts = shell.prompts.old_prompts