From 0a2145ca07908f8334b84fe74b581f8980e95cbd 2007-06-11 17:07:21 From: vivainio Date: 2007-06-11 17:07:21 Subject: [PATCH] compress 'head' of dhist on store --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 26a93e9..26c6a8f 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 2423 2007-06-11 16:47:22Z vivainio $""" +$Id: Magic.py 2425 2007-06-11 17:07:21Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -66,6 +66,20 @@ def on_off(tag): class Bunch: pass +def compress_dhist(dh): + head, tail = dh[:-10], dh[-10:] + + newhead = [] + done = set() + for h in head: + if h in done: + continue + newhead.append(h) + done.add(h) + + return newhead + tail + + #*************************************************************************** # Main class implementing Magic functionality class Magic: @@ -2463,7 +2477,11 @@ Defaulting color scheme to 'NoColor'""" except OSError: print sys.exc_info()[1] else: - self.shell.user_ns['_dh'].append(os.getcwd()) + cwd = os.getcwd() + dhist = self.shell.user_ns['_dh'] + dhist.append(cwd) + self.db['dhist'] = compress_dhist(dhist[-100:]) + else: os.chdir(self.shell.home_dir) if self.shell.rc.term_title: