Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

32 строки
976 B

14 лет назад
14 лет назад
  1. """
  2. IPython autojump magic
  3. Written by keith hughitt <keith.hughitt@gmail.com>, based on an earlier
  4. version by Mario Pastorelli <pastorelli.mario@gmail.com>.
  5. To install, `create a new IPython user profile <http://ipython.org/ipython-doc/stable/config/ipython.html#configuring-ipython>`_
  6. if you have not already done so by running:
  7. ipython profile create
  8. And copy this file into the "startup" folder of your new profile (e.g.
  9. "$HOME/.config/ipython/profile_default/startup/").
  10. @TODO: extend %cd to call "autojump -a"
  11. """
  12. import os
  13. import subprocess as sub
  14. from IPython.core.magic import (register_line_magic, register_cell_magic,
  15. register_line_cell_magic)
  16. ip = get_ipython()
  17. @register_line_magic
  18. def j(path):
  19. cmd = ['autojump'] + path.split()
  20. newpath = sub.Popen(cmd, stdout=sub.PIPE, shell=False).communicate()[0][:-1] # delete last '\n'
  21. if newpath:
  22. ip.magic('cd %s' % newpath)
  23. # remove from namespace
  24. del j