From e6faa222cafb154d47458e48dba533adff10dfdb 2008-08-14 21:13:29 From: Ville M. Vainio Date: 2008-08-14 21:13:29 Subject: [PATCH] use cd --foo instead of cd -foo. also cd -- works. changes.txt --- diff --git a/IPython/Extensions/ipy_completers.py b/IPython/Extensions/ipy_completers.py index 27139d3..d6a0aa6 100644 --- a/IPython/Extensions/ipy_completers.py +++ b/IPython/Extensions/ipy_completers.py @@ -318,6 +318,9 @@ def cd_completer(self, event): return ents return [] + if event.symbol.startswith('--'): + return ["--" + os.path.basename(d) for d in ip.user_ns['_dh']] + if relpath.startswith('~'): relpath = os.path.expanduser(relpath).replace('\\','/') found = [] diff --git a/IPython/Magic.py b/IPython/Magic.py index 8e906b3..18f1165 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -2693,7 +2693,7 @@ Defaulting color scheme to 'NoColor'""" cd -: changes to the n-th directory in the directory history. - cd -foo: change to directory that matches 'foo' in history + cd --foo: change to directory that matches 'foo' in history cd -b : jump to a bookmark set by %bookmark (note: cd is enough if there is no @@ -2714,7 +2714,6 @@ Defaulting color scheme to 'NoColor'""" oldcwd = os.getcwd() numcd = re.match(r'(-)(\d+)$',parameter_s) - wordcd = re.match(r'(-)(\w+)$',parameter_s) # jump in directory history by number if numcd: nn = int(numcd.group(2)) @@ -2725,18 +2724,18 @@ Defaulting color scheme to 'NoColor'""" return else: opts = {} - elif wordcd: + elif parameter_s.startswith('--'): ps = None fallback = None - pat = wordcd.group(2) + pat = parameter_s[2:] dh = self.shell.user_ns['_dh'] # first search only by basename (last component) for ent in reversed(dh): - if pat in os.path.basename(ent): + if pat in os.path.basename(ent) and os.path.isdir(ent): ps = ent break - if fallback is None and pat in ent: + if fallback is None and pat in ent and os.path.isdir(ent): fallback = ent # if we have no last part match, pick the first full path match diff --git a/docs/source/changes.txt b/docs/source/changes.txt index 03bbf91..3752fa3 100644 --- a/docs/source/changes.txt +++ b/docs/source/changes.txt @@ -53,6 +53,9 @@ New features the main usage of the script is for starting things on localhost. Eventually when ipcluster is able to start things on other hosts, we will put security back. + * 'cd --foo' searches directory history for string foo, and jumps to that dir. + Last part of dir name is checked first. If no matches for that are found, + look at the whole path. Bug fixes --------- @@ -64,6 +67,8 @@ Bug fixes * A few subpackages has missing `__init__.py` files. * The documentation is only created is Sphinx is found. Previously, the `setup.py` script would fail if it was missing. + * Greedy 'cd' completion has been disabled again (it was enabled in 0.8.4) + Backwards incompatible changes ------------------------------