From 43841114f4403b46e0ef077be6e0832ce690dfb2 2007-08-29 10:51:58 From: vivainio Date: 2007-08-29 10:51:58 Subject: [PATCH] add ipy_workdir --- diff --git a/IPython/Extensions/ipy_workdir.py b/IPython/Extensions/ipy_workdir.py new file mode 100644 index 0000000..b1a07fa --- /dev/null +++ b/IPython/Extensions/ipy_workdir.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import IPython.ipapi +ip = IPython.ipapi.get() + +import os + +workdir = None +def workdir_f(line): + global workdir + dummy,cmd = line.split(None,1) + if os.path.isdir(cmd): + workdir = cmd + print "Set workdir",workdir + elif workdir is None: + print "Please set workdir first by doing e.g. 'workdir q:/'" + else: + print "Execute command in",workdir + cwd = os.getcwd() + os.chdir(workdir) + try: + ip.runlines(cmd) + finally: + os.chdir(cwd) + +ip.defalias("workdir",workdir_f) + + + + +