Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fedd072

Browse files
committed
Improve matching files after script name for magic %run.
Closes gh-3459
1 parent 05e0343 commit fedd072

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

IPython/core/completerlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ def magic_run_completer(self, event):
253253
"""Complete files that end in .py or .ipy or .ipynb for the %run command.
254254
"""
255255
comps = arg_split(event.line, strict=False)
256-
relpath = (len(comps) > 1 and comps[-1] or '').strip("'\"")
256+
# relpath should be the current token that we need to complete.
257+
if (len(comps) > 1) and (not event.line.endswith(' ')):
258+
relpath = comps[-1].strip("'\"")
259+
else:
260+
relpath = ''
257261

258262
#print("\nev=", event) # dbg
259263
#print("rp=", relpath) # dbg
@@ -270,7 +274,7 @@ def magic_run_completer(self, event):
270274
# be arguments to the input script.
271275

272276
if any(magic_run_re.match(c) for c in comps):
273-
pys = [f.replace('\\','/') for f in lglob('*')]
277+
pys = [f.replace('\\','/') for f in lglob(relpath+'*')]
274278
else:
275279
pys = [f.replace('\\','/')
276280
for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') +

0 commit comments

Comments
 (0)