Merge pull request #1897 from mitnk/fix-complete

Make readline completes to max prefix
This commit is contained in:
Gil Forsyth 2016-11-08 10:24:25 -05:00 committed by GitHub
commit a797a9d804
2 changed files with 21 additions and 3 deletions

14
news/quotes-paths.rst Normal file
View file

@ -0,0 +1,14 @@
**Added:** None
**Changed:**
* Quote all paths when completion if any of the paths needs be quoted,
so that bash can automatically complete to the max prefix of the paths.
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -134,12 +134,16 @@ def _quote_paths(paths, start, end):
slash = xt.get_sep()
orig_start = start
orig_end = end
# quote on all or none, to make readline completes to max prefix
need_quotes = any(
re.search(PATTERN_NEED_QUOTES, x) or
(backslash in x and slash != backslash)
for x in paths)
for s in paths:
start = orig_start
end = orig_end
if (start == '' and
(re.search(PATTERN_NEED_QUOTES, s) is not None or
(backslash in s and slash != backslash))):
if start == '' and need_quotes:
start = end = _quote_to_use(s)
if os.path.isdir(expand_path(s)):
_tail = slash