From 444cdce9f18a64761302623724380e55f59bd232 2008-05-27 14:44:59 From: Ville M. Vainio Date: 2008-05-27 14:44:59 Subject: [PATCH] cd completer does recursive path expansion (old behaviour caused readline to add spaces after directories, on some linux readline version) --- diff --git a/IPython/Extensions/ipy_completers.py b/IPython/Extensions/ipy_completers.py index ecc724a..1e88db4 100644 --- a/IPython/Extensions/ipy_completers.py +++ b/IPython/Extensions/ipy_completers.py @@ -331,7 +331,29 @@ def cd_completer(self, event): if os.path.isdir(relpath): return [relpath] raise IPython.ipapi.TryNext - return found + + + def single_dir_expand(matches): + "Recursively expand match lists containing a single dir." + + if len(matches) == 1 and os.path.isdir(matches[0]): + # Takes care of links to directories also. Use '/' + # explicitly, even under Windows, so that name completions + # don't end up escaped. + d = matches[0] + if d[-1] in ['/','\\']: + d = d[:-1] + + subdirs = [p for p in os.listdir(d) if os.path.isdir( d + '/' + p)] + if subdirs: + matches = [ (d + '/' + p) for p in subdirs ] + return single_dir_expand(matches) + else: + return matches + else: + return matches + + return single_dir_expand(found) def apt_get_packages(prefix): out = os.popen('apt-cache pkgnames') diff --git a/doc/ChangeLog b/doc/ChangeLog index d4e8a63..b29cf8c 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -6,6 +6,9 @@ * Magic.py: cpaste strips whitespace before >>> (allow pasting doctests) + * ipy_completers.py: cd completer now does recursive path expand + (old behaviour is buggy on some readline versions) + 2008-05-14 Ville Vainio * Extensions/ipy_greedycompleter.py: