@@ -939,6 +939,7 @@ def complete_submenu(_self, text, line, begidx, endidx):
939
939
submenu .allow_appended_space = True
940
940
submenu .allow_closing_quote = True
941
941
submenu .display_matches = []
942
+ submenu .matches_delimited = False
942
943
943
944
return _complete_from_cmd (submenu , text , line , begidx , endidx )
944
945
finally :
@@ -949,6 +950,7 @@ def complete_submenu(_self, text, line, begidx, endidx):
949
950
_self .allow_appended_space = submenu .allow_appended_space
950
951
_self .allow_closing_quote = submenu .allow_closing_quote
951
952
_self .display_matches = copy .copy (submenu .display_matches )
953
+ _self .matches_delimited = submenu .matches_delimited
952
954
953
955
original_do_help = cmd_obj .do_help
954
956
original_complete_help = cmd_obj .complete_help
@@ -1174,13 +1176,16 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
1174
1176
# will be added if there is an unmatched opening quote
1175
1177
self .allow_closing_quote = True
1176
1178
1177
- # Use this list if you are completing strings that contain a common delimiter and you only want to
1178
- # display the final portion of the matches as the tab-completion suggestions. The full matches
1179
- # still must be returned from your completer function. For an example, look at path_complete()
1180
- # which uses this to show only the basename of paths as the suggestions. delimiter_complete() also
1181
- # populates this list.
1179
+ # If the tab-completion suggestions should be displayed in a way that is different than the actual match values,
1180
+ # then place those results in this list. The full matches still must be returned from your completer function.
1181
+ # For an example, look at path_complete() which uses this to show only the basename of paths as the
1182
+ # suggestions. delimiter_complete() also populates this list.
1182
1183
self .display_matches = []
1183
1184
1185
+ # Used by functions like path_complete() and delimiter_complete() to properly
1186
+ # quote matches that are completed in a delimited fashion
1187
+ self .matches_delimited = False
1188
+
1184
1189
# ----- Methods related to presenting output to the user -----
1185
1190
1186
1191
@property
@@ -1380,6 +1385,7 @@ def reset_completion_defaults(self):
1380
1385
self .allow_appended_space = True
1381
1386
self .allow_closing_quote = True
1382
1387
self .display_matches = []
1388
+ self .matches_delimited = False
1383
1389
1384
1390
if rl_type == RlType .GNU :
1385
1391
readline .set_completion_display_matches_hook (self ._display_matches_gnu_readline )
@@ -1557,6 +1563,8 @@ def delimiter_complete(self, text, line, begidx, endidx, match_against, delimite
1557
1563
1558
1564
# Display only the portion of the match that's being completed based on delimiter
1559
1565
if matches :
1566
+ # Set this to True for proper quoting of matches with spaces
1567
+ self .matches_delimited = True
1560
1568
1561
1569
# Get the common beginning for the matches
1562
1570
common_prefix = os .path .commonprefix (matches )
@@ -1758,6 +1766,9 @@ def complete_users():
1758
1766
search_str = os .path .join (os .getcwd (), search_str )
1759
1767
cwd_added = True
1760
1768
1769
+ # Set this to True for proper quoting of paths with spaces
1770
+ self .matches_delimited = True
1771
+
1761
1772
# Find all matching path completions
1762
1773
matches = glob .glob (search_str )
1763
1774
@@ -2147,13 +2158,7 @@ def complete(self, text, state):
2147
2158
display_matches_set = set (self .display_matches )
2148
2159
self .display_matches = list (display_matches_set )
2149
2160
2150
- # Check if display_matches has been used. If so, then matches
2151
- # on delimited strings like paths was done.
2152
- if self .display_matches :
2153
- matches_delimited = True
2154
- else :
2155
- matches_delimited = False
2156
-
2161
+ if not self .display_matches :
2157
2162
# Since self.display_matches is empty, set it to self.completion_matches
2158
2163
# before we alter them. That way the suggestions will reflect how we parsed
2159
2164
# the token being completed and not how readline did.
@@ -2167,7 +2172,7 @@ def complete(self, text, state):
2167
2172
# This is the tab completion text that will appear on the command line.
2168
2173
common_prefix = os .path .commonprefix (self .completion_matches )
2169
2174
2170
- if matches_delimited :
2175
+ if self . matches_delimited :
2171
2176
# Check if any portion of the display matches appears in the tab completion
2172
2177
display_prefix = os .path .commonprefix (self .display_matches )
2173
2178
0 commit comments