From fedd072d5d7baaa7749e132dbdd5f3ffa9f930ba 2014-01-28 00:19:14 From: Thomas Kluyver Date: 2014-01-28 00:19:14 Subject: [PATCH] Improve matching files after script name for magic %run. Closes gh-3459 --- diff --git a/IPython/core/completerlib.py b/IPython/core/completerlib.py index 2dff862..bddd412 100644 --- a/IPython/core/completerlib.py +++ b/IPython/core/completerlib.py @@ -253,7 +253,11 @@ def magic_run_completer(self, event): """Complete files that end in .py or .ipy or .ipynb for the %run command. """ comps = arg_split(event.line, strict=False) - relpath = (len(comps) > 1 and comps[-1] or '').strip("'\"") + # relpath should be the current token that we need to complete. + if (len(comps) > 1) and (not event.line.endswith(' ')): + relpath = comps[-1].strip("'\"") + else: + relpath = '' #print("\nev=", event) # dbg #print("rp=", relpath) # dbg @@ -270,7 +274,7 @@ def magic_run_completer(self, event): # be arguments to the input script. if any(magic_run_re.match(c) for c in comps): - pys = [f.replace('\\','/') for f in lglob('*')] + pys = [f.replace('\\','/') for f in lglob(relpath+'*')] else: pys = [f.replace('\\','/') for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') +