From 09702594a133e68167726e5da7d1a7f088b5b053 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Sat, 5 Dec 2015 12:37:56 -0500 Subject: [PATCH] move completion wrap expression to separate function --- xonsh/completer.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xonsh/completer.py b/xonsh/completer.py index f9e7e3b7d..54f8432d7 100644 --- a/xonsh/completer.py +++ b/xonsh/completer.py @@ -80,6 +80,18 @@ def _normpath(p): return p +def completionwrap(s): + """ Returns the repr of input string s if that string contains + a 'problem' token that will confuse the xonsh parser + """ + space = ' ' + slash = '/' + return (_normpath(repr(s + (slash if os.path.isdir(s) else ''))) + if COMPLETION_WRAP_TOKENS.intersection(s) else + s + space + if s[-1:].isalnum() else + s) + class Completer(object): """This provides a list of optional completions for the xonsh shell.""" @@ -317,13 +329,7 @@ class Completer(object): except subprocess.CalledProcessError: out = '' - space = ' ' - slash = '/' - rtn = {_normpath(repr(s + (slash if os.path.isdir(s) else ''))) - if COMPLETION_WRAP_TOKENS.intersection(s) else - s + space - if s[-1:].isalnum() else - s for s in out.splitlines()} + rtn = set(map(completionwrap, out.splitlines())) return rtn def _source_completions(self):