diff --git a/xonsh/aliases.py b/xonsh/aliases.py index 104eec6aa..1915079ce 100644 --- a/xonsh/aliases.py +++ b/xonsh/aliases.py @@ -23,7 +23,13 @@ from xonsh.platform import ( from xonsh.tools import unthreadable, print_color from xonsh.replay import replay_main from xonsh.timings import timeit_alias -from xonsh.tools import argvquote, escape_windows_cmd_string, to_bool, swap_values +from xonsh.tools import ( + argvquote, + escape_windows_cmd_string, + to_bool, + swap_values, + strip_simple_quotes, +) from xonsh.xontribs import xontribs_main from xonsh.ast import isexpression @@ -118,7 +124,7 @@ class Aliases(cabc.MutableMapping): if isexpression(val): # expansion substitution lexer = __xonsh__.execer.parser.lexer - self._raw[key] = lexer.split(val) + self._raw[key] = list(map(strip_simple_quotes, lexer.split(val))) else: # need to exec alias f = "" diff --git a/xonsh/tools.py b/xonsh/tools.py index a3394d36e..687b331d7 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -1979,6 +1979,38 @@ def RE_COMPLETE_STRING(): return re.compile(ptrn, re.DOTALL) +def strip_simple_quotes(s): + """Gets rid of single quotes, double quotes, single triple quotes, and + single double quotes from a string, if present front and back of a string. + Otherwiswe, does nothing. + """ + starts_single = s.startswith("'") + starts_double = s.startswith('"') + if not starts_single and not starts_double: + return s + elif starts_single: + ends_single = s.endswith("'") + if not ends_single: + return s + elif s.startswith("'''") and s.endswith("'''") and len(s) >= 6: + return s[3:-3] + elif len(s) >= 2: + return s[1:-1] + else: + return s + else: + # starts double + ends_double = s.endswith('"') + if not ends_double: + return s + elif s.startswith('"""') and s.endswith('"""') and len(s) >= 6: + return s[3:-3] + elif len(s) >= 2: + return s[1:-1] + else: + return s + + def check_for_partial_string(x): """Returns the starting index (inclusive), ending index (exclusive), and starting quote string of the most recent Python string found in the input.