@@ -2065,6 +2065,13 @@ def complete(self, text, state):
20652065
20662066 if len (self .completion_matches ) > 0 :
20672067
2068+ # Eliminate duplicates
2069+ matches_set = set (self .completion_matches )
2070+ self .completion_matches = list (matches_set )
2071+
2072+ display_matches_set = set (self .display_matches )
2073+ self .display_matches = list (display_matches_set )
2074+
20682075 # Get the token being completed as it appears on the command line
20692076 raw_completion_token = raw_tokens [- 1 ]
20702077
@@ -2103,15 +2110,6 @@ def complete(self, text, state):
21032110 strs_to_match = alias_names + visible_commands
21042111 self .completion_matches = self .basic_complete (text , line , begidx , endidx , strs_to_match )
21052112
2106- # Eliminate duplicates and sort
2107- matches_set = set (self .completion_matches )
2108- self .completion_matches = list (matches_set )
2109- self .completion_matches .sort ()
2110-
2111- display_matches_set = set (self .display_matches )
2112- self .display_matches = list (display_matches_set )
2113- self .display_matches .sort ()
2114-
21152113 # Handle single result
21162114 if len (self .completion_matches ) == 1 :
21172115 str_to_append = ''
@@ -2126,6 +2124,11 @@ def complete(self, text, state):
21262124
21272125 self .completion_matches [0 ] += str_to_append
21282126
2127+ # Otherwise sort matches
2128+ elif len (self .completion_matches ) > 0 :
2129+ self .completion_matches .sort ()
2130+ self .display_matches .sort ()
2131+
21292132 try :
21302133 return self .completion_matches [state ]
21312134 except IndexError :
0 commit comments