@@ -2075,27 +2075,34 @@ def complete(self, text, state):
20752075 display_matches_set = set (self .display_matches )
20762076 self .display_matches = list (display_matches_set )
20772077
2078- # If self.display_matches is empty, then set it to self.completion_matches
2079- # before we alter them. That way the suggestions will reflect how we parsed
2080- # the token being completed and not how readline did.
2081- display_matches_delimited = True
2082- if not self .display_matches :
2083- display_matches_delimited = False
2078+ # Check if display_matches has been used. If so, then matches
2079+ # on delimited strings like paths was done.
2080+ if self .display_matches :
2081+ matches_delimited = True
2082+ else :
2083+ matches_delimited = False
2084+
2085+ # Since self.display_matches is empty, then set it to self.completion_matches
2086+ # before we alter them. That way the suggestions will reflect how we parsed
2087+ # the token being completed and not how readline did.
20842088 self .display_matches = copy .copy (self .completion_matches )
20852089
20862090 # Check if we need to add an opening quote
20872091 if not unclosed_quote :
20882092
2093+ add_quote = False
2094+
2095+ # This is the tab completion text that will appear on the command line.
20892096 common_prefix = os .path .commonprefix (self .completion_matches )
20902097
2091- add_quote = False
2092- if display_matches_delimited :
2098+ if matches_delimited :
20932099 display_prefix = os .path .commonprefix (self .display_matches )
20942100 if (' ' in common_prefix ) or (display_prefix and ' ' in '' .join (self .display_matches )):
20952101 add_quote = True
2096- else :
2097- if common_prefix and ' ' in '' .join (self .completion_matches ):
2098- add_quote = True
2102+
2103+ # If there is a tab completion and any match has a space, then add an opening quote
2104+ elif common_prefix and ' ' in '' .join (self .completion_matches ):
2105+ add_quote = True
20992106
21002107 if add_quote :
21012108 # Figure out what kind of quote to add and save it as the unclosed_quote
0 commit comments