From 82d3e14c1f7f4e9a7246ae8194cc7924afb47b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Schaerer?= Date: Thu, 25 Nov 2010 15:19:33 +0100 Subject: [PATCH] initial version of script for ipython --- .gitignore | 1 + tools/autojump_ipython.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tools/autojump_ipython.py diff --git a/.gitignore b/.gitignore index 6e92f57..b8d9103 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ tags +*.pyc diff --git a/tools/autojump_ipython.py b/tools/autojump_ipython.py new file mode 100644 index 0000000..358f160 --- /dev/null +++ b/tools/autojump_ipython.py @@ -0,0 +1,33 @@ +# This module was contributed by Mario Pastorelli +# It is released in the public domain + +import os +import subprocess as sub +from IPython.ipapi import get +from IPython.iplib import InteractiveShell + +# Export the environment variable pointing to the autojump storage dir +ip = get() +ip.magic('env AUTOJUMP_DATA_DIR=/home/rief/.local/share/autojump') + +def magic_j(self,parameter_s=''): + cmd = ['autojump']+parameter_s.split() +# print 'executing autojump with args %s' % str(cmd) + newpath=sub.Popen(cmd,stdout=sub.PIPE,shell=False).communicate()[0][:-1] # delete last '\n' +# print 'Autojump answer: \'%s\'' % newpath + ip.magic('cd \'%s\'' % newpath) + +def cd_decorator(f): + def autojump_cd_monitor(self,parameter_s=''): + f(self,parameter_s) +# print 'Calling autojump -a '+str(parameter_s.split()) + sub.call(['autojump','-a']+parameter_s.split()) + return autojump_cd_monitor + +# Add the new magic function to the class dict and decorate magic_cd: +InteractiveShell.magic_j = magic_j +InteractiveShell.magic_cd = cd_decorator(InteractiveShell.magic_cd) + +# And remove the global name to keep global namespace clean. +del magic_j +del cd_decorator