From 3d6c30d0cdc272257cb69002d11abf397f98388d 2007-09-07 16:12:42 From: vivainio Date: 2007-09-07 16:12:42 Subject: [PATCH] cd -TAB pads zeros, %clear dhist, some doc changes --- diff --git a/IPython/Extensions/clearcmd.py b/IPython/Extensions/clearcmd.py index 7fdd0e0..49fbd59 100644 --- a/IPython/Extensions/clearcmd.py +++ b/IPython/Extensions/clearcmd.py @@ -13,6 +13,7 @@ def clear_f(self,arg): %clear in - clear input history %clear shadow_compress - Compresses shadow history (to speed up ipython) %clear shadow_nuke - permanently erase all entries in shadow history + %clear dhist - clear dir history """ api = self.getapi() @@ -50,10 +51,15 @@ def clear_f(self,arg): print "Erased all keys from shadow history " for k in ip.db.keys('shadowhist/*'): del ip.db[k] + elif target == 'dhist': + print "Clearing directory history" + del ip.user_ns['_dh'][:] + ip.expose_magic("clear",clear_f) import ipy_completers -ipy_completers.quick_completer('%clear','in out shadow_nuke shadow_compress') +ipy_completers.quick_completer( + '%clear','in out shadow_nuke shadow_compress dhist') diff --git a/IPython/Extensions/ipy_completers.py b/IPython/Extensions/ipy_completers.py index ddf7d54..e294ffd 100644 --- a/IPython/Extensions/ipy_completers.py +++ b/IPython/Extensions/ipy_completers.py @@ -318,10 +318,12 @@ def cd_completer(self, event): bkms = self.db.get('bookmarks',{}) return bkms.keys() - + if event.symbol == '-': + width_dh = str(len(str(len(ip.user_ns['_dh']) + 1))) # jump in directory history by number - ents = ['-%d [%s]' % (i,s) for i,s in enumerate(ip.user_ns['_dh'])] + fmt = '-%0' + width_dh +'d [%s]' + ents = [ fmt % (i,s) for i,s in enumerate(ip.user_ns['_dh'])] if len(ents) > 1: return ents return [] diff --git a/IPython/Magic.py b/IPython/Magic.py index cfe4ece..1db9f19 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 2723 2007-09-07 07:44:16Z fperez $""" +$Id: Magic.py 2728 2007-09-07 16:12:42Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -2709,7 +2709,12 @@ Defaulting color scheme to 'NoColor'""" This history is automatically maintained by the %cd command, and always available as the global list variable _dh. You can use %cd - - to go to directory number .""" + to go to directory number . + + Note that most of time, you should view directory history by entering + cd -. + + """ dh = self.shell.user_ns['_dh'] if parameter_s: @@ -2938,6 +2943,8 @@ Defaulting color scheme to 'NoColor'""" def magic_r(self, parameter_s=''): """Repeat previous input. + Note: Consider using the more powerfull %rep instead! + If given an argument, repeats the previous command which starts with the same string, otherwise it just repeats the previous input.