##// END OF EJS Templates
dir stack simplification, uses UsageError now
vivainio -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 2744 2007-09-08 12:58:56Z vivainio $"""
4 $Id: Magic.py 2747 2007-09-08 14:01:45Z vivainio $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -2668,34 +2668,24 b' Defaulting color scheme to \'NoColor\'"""'
2668
2668
2669 Usage:\\
2669 Usage:\\
2670 %pushd ['dirname']
2670 %pushd ['dirname']
2671
2672 %pushd with no arguments does a %pushd to your home directory.
2673 """
2671 """
2674 if parameter_s == '': parameter_s = '~'
2672
2675 dir_s = self.shell.dir_stack
2673 dir_s = self.shell.dir_stack
2676 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2674 tgt = os.path.expanduser(parameter_s)
2677 os.path.expanduser(self.shell.dir_stack[0]):
2675 cwd = os.getcwd().replace(self.home_dir,'~')
2678 try:
2676 if tgt:
2679 cwd = os.getcwd().replace(self.home_dir,'~')
2677 self.magic_cd(parameter_s)
2680 self.magic_cd(parameter_s)
2678 dir_s.insert(0,cwd)
2681 # print "Pushed:",cwd #dbg
2679 return self.magic_dirs()
2682 dir_s.insert(0,cwd)
2683 return self.magic_dirs()
2684 except:
2685 print 'Invalid directory'
2686 else:
2687 print 'You are already there!'
2688
2680
2689 def magic_popd(self, parameter_s=''):
2681 def magic_popd(self, parameter_s=''):
2690 """Change to directory popped off the top of the stack.
2682 """Change to directory popped off the top of the stack.
2691 """
2683 """
2692 if len (self.shell.dir_stack) > 1:
2684 if not self.shell.dir_stack:
2693 top = self.shell.dir_stack.pop(0)
2685 raise IPython.ipapi.UsageError("%popd on empty stack")
2694 self.magic_cd(top)
2686 top = self.shell.dir_stack.pop(0)
2695 print "popd ->",top
2687 self.magic_cd(top)
2696 else:
2688 print "popd ->",top
2697 print "You can't remove the starting directory from the stack:",\
2698 self.shell.dir_stack
2699
2689
2700 def magic_dirs(self, parameter_s=''):
2690 def magic_dirs(self, parameter_s=''):
2701 """Return the current directory stack."""
2691 """Return the current directory stack."""
General Comments 0
You need to be logged in to leave comments. Login now