diff options
author | hut <hut@lepus.uberspace.de> | 2013-10-25 18:51:29 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2013-10-25 18:55:06 +0200 |
commit | 093c8b1a7b7656c82923539a4286606fd7ded4b5 (patch) | |
tree | 2196472d60a37b362b5478f524d06dcba1781b13 /ranger | |
parent | ee35f41d6b41dbf71cb558ecd8c69883738ff98a (diff) | |
download | ranger-093c8b1a7b7656c82923539a4286606fd7ded4b5.tar.gz |
api.commands: improved tab-completion of :rename and others
The list of items that you tab through is now constrained to non-hidden files and the order is the same as visible on the screen - starting from the current file.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/api/commands.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 305bab75..98b0a23a 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -273,22 +273,41 @@ class Command(FileManagerAware): rel_dirname = dirname(rel_dest) try: + directory = self.fm.get_directory(abs_dest) + # are we at the end of a directory? if rel_dest.endswith('/') or rel_dest == '': - _, dirnames, filenames = next(os.walk(abs_dest)) - names = dirnames + filenames + if directory.content_loaded: + # Take the order from the directory object + names = [f.basename for f in directory.files] + if self.fm.thisfile.basename in names: + i = names.index(self.fm.thisfile.basename) + names = names[i:] + names[:i] + else: + # Fall back to old method with "os.walk" + _, dirnames, filenames = next(os.walk(abs_dest)) + names = dirnames + filenames + names.sort() # are we in the middle of the filename? else: - _, dirnames, filenames = next(os.walk(abs_dirname)) - names = [name for name in (dirnames + filenames) \ - if name.startswith(rel_basename)] + if directory.content_loaded: + # Take the order from the directory object + names = [f.basename for f in directory.files \ + if f.basename.startswith(rel_basename)] + if self.fm.thisfile.basename in names: + i = names.index(self.fm.thisfile.basename) + names = names[i:] + names[:i] + else: + # Fall back to old method with "os.walk" + _, dirnames, filenames = next(os.walk(abs_dirname)) + names = [name for name in (dirnames + filenames) \ + if name.startswith(rel_basename)] + names.sort() except (OSError, StopIteration): # os.walk found nothing pass else: - names.sort() - # no results, return None if len(names) == 0: return |