@@ -2055,14 +2055,12 @@ def complete(self, text, state):
20552055 self .completion_matches = []
20562056 return None
20572057
2058- # readline still performs word breaks in quotes. Therefore quoted search text with
2059- # a space would have resulted in begidx pointing to the middle of the token we want
2060- # to complete. Figure out where that token actually begins.
2058+ # readline still performs word breaks after a quote. Therefore something like quoted search
2059+ # text with a space would have resulted in begidx pointing to the middle of the token we
2060+ # we want to complete. Figure out where that token actually begins and save the beginning
2061+ # portion of it that was not part of the text readline gave us. We will remove it from the
2062+ # completions later since readline expects them to start with the original text.
20612063 actual_begidx = line [:endidx ].rfind (tokens [- 1 ])
2062-
2063- # If actual_begidx is different than what readline gave us, save the beginning portion
2064- # of the completion token that does not belong in text. We will remove it from the
2065- # completions later since readline expects our completions to start with the original text.
20662064 text_to_remove = ''
20672065
20682066 if actual_begidx != begidx :
@@ -2073,9 +2071,6 @@ def complete(self, text, state):
20732071 text = text_to_remove + text
20742072 begidx = actual_begidx
20752073
2076- # Get the tokens with preserved quotes
2077- raw_completion_token = raw_tokens [- 1 ]
2078-
20792074 # Check if a valid command was entered
20802075 if command in self .get_all_commands ():
20812076 # Get the completer function for this command
@@ -2107,9 +2102,12 @@ def complete(self, text, state):
21072102
21082103 if len (self .completion_matches ) > 0 :
21092104
2105+ # Get the token being completed as it appears on the command line
2106+ raw_completion_token = raw_tokens [- 1 ]
2107+
21102108 # Add an opening quote if needed
21112109 if self ._handle_completion_token_quote (raw_completion_token ):
2112- # An opening quote was added and the screen was updated. Return no results
2110+ # An opening quote was added and the screen was updated. Return no results.
21132111 self .completion_matches = []
21142112 return None
21152113
@@ -2131,17 +2129,9 @@ def complete(self, text, state):
21312129 self .completion_matches = \
21322130 [shortcut_to_restore + match for match in self .completion_matches ]
21332131
2134- # Check if the token being completed has an unclosed quote
2135- if len (raw_completion_token ) == 1 :
2136- first_char = raw_completion_token [0 ]
2137- if first_char in QUOTES :
2138- unclosed_quote = first_char
2139-
2140- elif len (raw_completion_token ) > 1 :
2141- first_char = raw_completion_token [0 ]
2142- last_char = raw_completion_token [- 1 ]
2143- if first_char in QUOTES and first_char != last_char :
2144- unclosed_quote = first_char
2132+ # If the token being completed starts with a quote then we know it has an unclosed quote
2133+ if len (raw_completion_token ) > 0 and raw_completion_token [0 ] in QUOTES :
2134+ unclosed_quote = raw_completion_token [0 ]
21452135
21462136 else :
21472137 # Complete token against aliases and command names
0 commit comments