diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-31 02:58:30 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-03-31 02:58:30 -0400 |
| commit | fd546ec1a4e0927cfc09b1b778456f26054e629f (patch) | |
| tree | cf96c6a66fa7c04cf2bede70a890e97679d1008f | |
| parent | cba3dd190b7d8cdcc5a2a0dbf25a0aa2d754df90 (diff) | |
| download | cmd2-git-fd546ec1a4e0927cfc09b1b778456f26054e629f.tar.gz | |
Sorting matches earlier
| -rwxr-xr-x | cmd2.py | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -2065,6 +2065,13 @@ class Cmd(cmd.Cmd): if len(self.completion_matches) > 0: + # Eliminate duplicates + matches_set = set(self.completion_matches) + self.completion_matches = list(matches_set) + + display_matches_set = set(self.display_matches) + self.display_matches = list(display_matches_set) + # Get the token being completed as it appears on the command line raw_completion_token = raw_tokens[-1] @@ -2103,15 +2110,6 @@ class Cmd(cmd.Cmd): strs_to_match = alias_names + visible_commands self.completion_matches = self.basic_complete(text, line, begidx, endidx, strs_to_match) - # Eliminate duplicates and sort - matches_set = set(self.completion_matches) - self.completion_matches = list(matches_set) - self.completion_matches.sort() - - display_matches_set = set(self.display_matches) - self.display_matches = list(display_matches_set) - self.display_matches.sort() - # Handle single result if len(self.completion_matches) == 1: str_to_append = '' @@ -2126,6 +2124,11 @@ class Cmd(cmd.Cmd): self.completion_matches[0] += str_to_append + # Otherwise sort matches + elif len(self.completion_matches) > 0: + self.completion_matches.sort() + self.display_matches.sort() + try: return self.completion_matches[state] except IndexError: |
