diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-08 01:04:33 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-08 01:04:33 -0400 |
commit | 89b5c20e1cb524502dae1069e3beb1422aedbc45 (patch) | |
tree | b3cb269fd1ac816920ba670d5f225d2485a79262 /cmd2/cmd2.py | |
parent | 35311cebc81c52f1e5f334df0dec6226d07755c1 (diff) | |
download | cmd2-git-89b5c20e1cb524502dae1069e3beb1422aedbc45.tar.gz |
Small refactors to tab completion function
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 0fe27a0a..9282c811 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1519,18 +1519,19 @@ class Cmd(cmd.Cmd): # Check if any portion of the display matches appears in the tab completion display_prefix = os.path.commonprefix(self.display_matches) - # For delimited matches, we check what appears before the display - # matches (common_prefix) as well as the display matches themselves. - if (' ' in common_prefix) or (display_prefix and ' ' in ''.join(self.display_matches)): + # For delimited matches, we check for a space in what appears before the display + # matches (common_prefix) as well as in the display matches themselves. + if (' ' in common_prefix) or (display_prefix and + any(' ' in match for match in self.display_matches)): add_quote = True # If there is a tab completion and any match has a space, then add an opening quote - elif common_prefix and ' ' in ''.join(self.completion_matches): + elif common_prefix and any(' ' in match for match in 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 ''.join(self.completion_matches): + if any('"' in match for match in self.completion_matches): unclosed_quote = "'" else: unclosed_quote = '"' @@ -1540,7 +1541,7 @@ class Cmd(cmd.Cmd): # Check if we need to remove text from the beginning of tab completions elif text_to_remove: self.completion_matches = \ - [m.replace(text_to_remove, '', 1) for m in self.completion_matches] + [match.replace(text_to_remove, '', 1) for match in self.completion_matches] # Check if we need to restore a shortcut in the tab completions # so it doesn't get erased from the command line |