@@ -1341,15 +1341,21 @@ def path_complete(line):
1341
1341
dirname , rest = os .path .split (path )
1342
1342
real_dir = os .path .expanduser (dirname )
1343
1343
1344
+ # Find all matching path completions
1344
1345
path_completions = glob .glob (os .path .join (real_dir , rest ) + '*' )
1345
1346
1346
- # Strip off everything but the final part of the completion
1347
+ # Strip off everything but the final part of the completion because that's the way readline works
1347
1348
completions = [os .path .basename (c ) for c in path_completions ]
1349
+
1350
+ # If there is a single completion and it is a directory, add the final separator for convenience
1351
+ if len (completions ) == 1 and os .path .isdir (path_completions [0 ]):
1352
+ completions [0 ] += os .path .sep
1353
+
1348
1354
return completions
1349
1355
1350
1356
# noinspection PyUnusedLocal
1351
1357
def complete_shell (self , text , line , begidx , endidx ):
1352
- """Handles completion of arguments for the shell command .
1358
+ """Handles tab completion of local file system paths .
1353
1359
1354
1360
:param text: str - the string prefix we are attempting to match (all returned matches must begin with it)
1355
1361
:param line: str - the current input line with leading whitespace removed
@@ -1359,6 +1365,11 @@ def complete_shell(self, text, line, begidx, endidx):
1359
1365
"""
1360
1366
return self .path_complete (line )
1361
1367
1368
+ # Enable tab completion of paths for other commands in an identical fashion
1369
+ complete_edit = complete_shell
1370
+ complete_load = complete_shell
1371
+ complete_save = complete_shell
1372
+
1362
1373
def do_py (self , arg ):
1363
1374
"""
1364
1375
py <command>: Executes a Python command.
@@ -1583,18 +1594,6 @@ def help_edit(self):
1583
1594
pyparsing .Optional (pyparsing .Word (legalChars + '/\\ ' ))("fname" ) +
1584
1595
pyparsing .stringEnd )
1585
1596
1586
- # noinspection PyUnusedLocal
1587
- def complete_edit (self , text , line , begidx , endidx ):
1588
- """Handles completion of arguments for the edit command.
1589
-
1590
- :param text: str - the string prefix we are attempting to match (all returned matches must begin with it)
1591
- :param line: str - the current input line with leading whitespace removed
1592
- :param begidx: str - the beginning indexe of the prefix text
1593
- :param endidx: str - the ending index of the prefix text
1594
- :return: List[str] - a list of possible tab completions
1595
- """
1596
- return self .path_complete (line )
1597
-
1598
1597
def do_save (self , arg ):
1599
1598
"""Saves command(s) from history to file.
1600
1599
@@ -1732,18 +1731,6 @@ def help_load(self):
1732
1731
Script should contain one command per line, just like command would be typed in console."""
1733
1732
self .stdout .write ("{}\n " .format (help_str ))
1734
1733
1735
- # noinspection PyUnusedLocal
1736
- def complete_load (self , text , line , begidx , endidx ):
1737
- """Handles completion of arguments for the load command.
1738
-
1739
- :param text: str - the string prefix we are attempting to match (all returned matches must begin with it)
1740
- :param line: str - the current input line with leading whitespace removed
1741
- :param begidx: str - the beginning indexe of the prefix text
1742
- :param endidx: str - the ending index of the prefix text
1743
- :return: List[str] - a list of possible tab completions
1744
- """
1745
- return self .path_complete (line )
1746
-
1747
1734
def do_run (self , arg ):
1748
1735
"""run [arg]: re-runs an earlier command
1749
1736
0 commit comments