##// END OF EJS Templates
add ipy_workdir
add ipy_workdir

File last commit:

r814:43841114
r814:43841114
Show More
ipy_workdir.py
31 lines | 640 B | text/x-python | PythonLexer
#!/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)