Fix bash quote completion strip calculation

`xonsh.completers.bash_completion.bash_completions` was returning incorrect
prefix lengths depending on whether or not a user had typed a leading quote. Now
it should be agnostic to how the prefix is started (no quote, single quote, or
double quote).
This commit is contained in:
Gil Forsyth 2018-07-04 19:43:43 -04:00
parent 2349472f29
commit 3f9bb89614

View file

@ -344,14 +344,14 @@ def bash_completions(prefix, line, begidx, endidx, env=None, paths=None,
# Ensure input to `commonprefix` is a list (now required by Python 3.6) # Ensure input to `commonprefix` is a list (now required by Python 3.6)
commprefix = os.path.commonprefix(list(out)) commprefix = os.path.commonprefix(list(out))
strip_len = 0 strip_len = 0
strip_prefix = prefix.strip("\"'")
while strip_len < len(prefix): while strip_len < len(prefix):
if commprefix.startswith(prefix[strip_len:]): if commprefix.startswith(strip_prefix[strip_len:]):
break break
strip_len += 1 strip_len += 1
if '-o noquote' not in complete_stmt: if '-o noquote' not in complete_stmt:
out, need_quotes = quote_paths(out, '', '') out, need_quotes = quote_paths(out, '', '')
strip_len += int(need_quotes)
if '-o nospace' in complete_stmt: if '-o nospace' in complete_stmt:
out = set([x.rstrip() for x in out]) out = set([x.rstrip() for x in out])