diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-04-14 22:39:43 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-04-14 22:39:43 -0400 |
commit | 9393380ed3068c8dc790d1dbcaa55f10e40eb4b5 (patch) | |
tree | f5cfd8de9c8e9ad582c93b0cfcced8ce314ed2b4 /cmd2.py | |
parent | 5786a961c9c86f060c296fd4db385a9c01585319 (diff) | |
download | cmd2-git-9393380ed3068c8dc790d1dbcaa55f10e40eb4b5.tar.gz |
Still hammering out adding an opening quote
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -2078,26 +2078,28 @@ class Cmd(cmd.Cmd): # If self.display_matches is empty, then set it to self.completion_matches # before we alter them. That way the suggestions will reflect how we parsed # the token being completed and not how readline did. + display_matches_delimited = True if not self.display_matches: + display_matches_delimited = False self.display_matches = copy.copy(self.completion_matches) # Check if we need to add an opening quote if not unclosed_quote: - # Get the common prefix of the matches. This is the actual tab completion. - # Use display_matches instead of completion_matches to support cases of delimited - # match strings since only the final part of those matches matter in these checks. - common_prefix = os.path.commonprefix(self.display_matches) + common_prefix = os.path.commonprefix(self.completion_matches) - # Join all matches into 1 string for ease of searching - all_matches_str = ''.join(self.display_matches) - - # If there is a tab completion and any of the matches have a space, - # then we will add an opening quote to the completion matches. - if common_prefix and ' ' in all_matches_str: + add_quote = False + if display_matches_delimited: + display_prefix = os.path.commonprefix(self.display_matches) + if (' ' in common_prefix) or (display_prefix and ' ' in ''.join(self.display_matches)): + add_quote = True + else: + if common_prefix and ' ' in ''.join(self.completion_matches): + add_quote = True + if add_quote: # Figure out what kind of quote to add and save it as the unclosed_quote - if '"' in all_matches_str: + if '"' in ''.join(self.completion_matches): unclosed_quote = "'" else: unclosed_quote = '"' |