@@ -182,14 +182,15 @@ def flag_based_complete(text, line, begidx, endidx, flag_dict, default_completer
182182 being completed
183183 :return: List[str] - a list of possible tab completions
184184 """
185- completions = []
186185
187186 # Get all tokens prior to text being completed
188187 try :
189188 tokens = shlex .split (line [:begidx ], posix = POSIX_SHLEX )
190189 except ValueError :
191190 # Invalid syntax for shlex (Probably due to missing closing quote)
192- return completions
191+ return []
192+
193+ completions = []
193194
194195 # Must have at least the command and one argument
195196 if len (tokens ) > 1 :
@@ -218,6 +219,7 @@ def flag_based_complete(text, line, begidx, endidx, flag_dict, default_completer
218219 elif default_completer is not None :
219220 completions = default_completer (text , line , begidx , endidx )
220221
222+ completions .sort ()
221223 return completions
222224
223225
@@ -238,14 +240,15 @@ def index_based_complete(text, line, begidx, endidx, index_dict, default_complet
238240 any index in index_dict
239241 :return: List[str] - a list of possible tab completions
240242 """
241- completions = []
242243
243244 # Get all tokens prior to text being completed
244245 try :
245246 tokens = shlex .split (line [:begidx ], posix = POSIX_SHLEX )
246247 except ValueError :
247248 # Invalid syntax for shlex (Probably due to missing closing quote)
248- return completions
249+ return []
250+
251+ completions = []
249252
250253 # Must have at least the command
251254 if len (tokens ) > 0 :
@@ -274,6 +277,7 @@ def index_based_complete(text, line, begidx, endidx, index_dict, default_complet
274277 elif default_completer is not None :
275278 completions = default_completer (text , line , begidx , endidx )
276279
280+ completions .sort ()
277281 return completions
278282
279283
@@ -350,8 +354,8 @@ def path_complete(text, line, begidx, endidx, dir_exe_only=False, dir_only=False
350354 elif os .path .isdir (path_completions [0 ]) and add_sep_after_tilde :
351355 completions [0 ] = os .path .sep + completions [0 ]
352356
353- # If there are multiple completions, then sort them alphabetically
354- return sorted ( completions )
357+ completions . sort ()
358+ return completions
355359
356360
357361class OptionParser (optparse .OptionParser ):
@@ -1336,14 +1340,15 @@ def complete_help(self, text, line, begidx, endidx):
13361340 """
13371341 Override of parent class method to handle tab completing subcommands
13381342 """
1339- completions = []
13401343
13411344 # Get all tokens prior to text being completed
13421345 try :
13431346 tokens = shlex .split (line [:begidx ], posix = POSIX_SHLEX )
13441347 except ValueError :
13451348 # Invalid syntax for shlex (Probably due to missing closing quote)
1346- return completions
1349+ return []
1350+
1351+ completions = []
13471352
13481353 # If we have "help" and a completed command token, then attempt to match subcommands
13491354 if len (tokens ) == 2 :
@@ -1362,6 +1367,7 @@ def complete_help(self, text, line, begidx, endidx):
13621367 if len (completions ) == 1 and endidx == len (line ) and self .get_subcommands (completions [0 ]) is not None :
13631368 completions [0 ] += ' '
13641369
1370+ completions .sort ()
13651371 return completions
13661372
13671373 def precmd (self , statement ):
@@ -2067,8 +2073,8 @@ def _shell_command_complete(text, line, begidx, endidx):
20672073 if len (exes ) == 1 and endidx == len (line ):
20682074 exes [0 ] += ' '
20692075
2070- # If there are multiple completions, then sort them alphabetically
2071- return sorted ( exes )
2076+ exes . sort ()
2077+ return exes
20722078
20732079 def complete_shell (self , text , line , begidx , endidx ):
20742080 """Handles tab completion of executable commands and local file system paths.
0 commit comments