1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00
wting_autojump/tools/autojump_ipython.py

40 lines
856 B
Python
Raw Normal View History

2016-04-29 06:33:04 +00:00
# -*- coding: utf-8 -*-
"""
IPython autojump magic
2010-11-25 14:19:33 +00:00
Written by keith hughitt <keith.hughitt@gmail.com>, based on an earlier
version by Mario Pastorelli <pastorelli.mario@gmail.com>.
2010-11-25 14:33:53 +00:00
To install, create a new IPython user profile by running:
ipython profile create
And copy this file into the "startup" folder of your new profile (e.g.
"$HOME/.config/ipython/profile_default/startup/").
@TODO: extend %cd to call "autojump -a"
"""
from subprocess import PIPE
2016-04-29 06:33:04 +00:00
from subprocess import Popen
from IPython.core.magic import register_line_magic
2010-11-25 14:19:33 +00:00
ip = get_ipython() # noqa
2010-11-25 14:19:33 +00:00
@register_line_magic
def j(path):
cmd = ['autojump'] + path.split()
newpath = Popen(
2016-04-29 06:33:04 +00:00
cmd,
stdout=PIPE,
shell=False,
).communicate()[0].strip()
2010-11-25 14:33:53 +00:00
if newpath:
ip.magic('cd %s' % newpath.decode('utf-8'))
2010-11-25 14:19:33 +00:00
# remove from namespace
del j