Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ipython(Command):
- """:ipython
- Runs IPython configured such that it behaves similar to a system shell.
- The currently selected files are exported via the 'rg_selected_files' variable.
- """
- # The execute method is called when you run this command in ranger.
- def execute(self):
- ipython_static_prelude = """
- import IPython
- if IPython.version_info[0] >= 5:
- import os
- from IPython.terminal.prompts import Prompts, Token
- class ShellPrompt(Prompts):
- def in_prompt_tokens(self, cli=None):
- return [(Token.Text, '['),
- (Token.Digraph, os.getlogin()),
- (Token.Text, '@'),
- (Token.Text, os.uname()[1]),
- (Token.Text, ' '),
- (Token.PromptNum, os.getcwd()),
- (Token.OutPromptNum, ' (IPy)'),
- (Token.Text, '] ')]
- ip = get_ipython()
- ip.prompts = ShellPrompt(ip)
- del(ShellPrompt)
- else:
- ip = get_ipython()
- ip.prompt_manager.in_template=r"{color.White}[{color.LightBlue}\u{color.White}@\h {color.LightGreen}{cwd} {color.Red}(IPy){color.White}] "
- ip.prompt_manager.justify = False
- del(ip)
- del(IPython)
- """
- ipython_dynamic_prelude = """
- rg_selected_files = {selected_files:s}
- """.format(selected_files = [str(f) for f in self.fm.thistab.get_selection()])
- command = ['ipython3', '-i', '-c', ipython_static_prelude + ipython_dynamic_prelude]
- self.fm.run(command)
Add Comment
Please, Sign In to add comment