Guest User

Untitled

a guest
Jul 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class ipython(Command):
  2. """:ipython
  3.  
  4. Runs IPython configured such that it behaves similar to a system shell.
  5.  
  6. The currently selected files are exported via the 'rg_selected_files' variable.
  7. """
  8.  
  9. # The execute method is called when you run this command in ranger.
  10. def execute(self):
  11. ipython_static_prelude = """
  12. import IPython
  13.  
  14. if IPython.version_info[0] >= 5:
  15. import os
  16. from IPython.terminal.prompts import Prompts, Token
  17.  
  18. class ShellPrompt(Prompts):
  19. def in_prompt_tokens(self, cli=None):
  20. return [(Token.Text, '['),
  21. (Token.Digraph, os.getlogin()),
  22. (Token.Text, '@'),
  23. (Token.Text, os.uname()[1]),
  24. (Token.Text, ' '),
  25. (Token.PromptNum, os.getcwd()),
  26. (Token.OutPromptNum, ' (IPy)'),
  27. (Token.Text, '] ')]
  28. ip = get_ipython()
  29. ip.prompts = ShellPrompt(ip)
  30. del(ShellPrompt)
  31. else:
  32. ip = get_ipython()
  33. ip.prompt_manager.in_template=r"{color.White}[{color.LightBlue}\u{color.White}@\h {color.LightGreen}{cwd} {color.Red}(IPy){color.White}] "
  34. ip.prompt_manager.justify = False
  35.  
  36. del(ip)
  37. del(IPython)
  38.  
  39. """
  40.  
  41. ipython_dynamic_prelude = """
  42. rg_selected_files = {selected_files:s}
  43. """.format(selected_files = [str(f) for f in self.fm.thistab.get_selection()])
  44.  
  45. command = ['ipython3', '-i', '-c', ipython_static_prelude + ipython_dynamic_prelude]
  46. self.fm.run(command)
Add Comment
Please, Sign In to add comment