diff options
author | The Flying Rapist <admin@nosuck.org> | 2015-10-24 03:28:37 -0400 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-02-01 00:30:38 +0100 |
commit | 9ce8839a6363d43f2d6f9ce74feb2c21ee4fed41 (patch) | |
tree | 87db4e84923b0115fa249dd3eafd475b079edd11 /ranger | |
parent | cc8f5270fdb52714c4606ac62eea0de9c6aac04a (diff) | |
download | ranger-9ce8839a6363d43f2d6f9ce74feb2c21ee4fed41.tar.gz |
Add command for jumping to first non-directory/non-file
Fixes #409
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 44 | ||||
-rw-r--r-- | ranger/config/rc.conf | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index b200f500..a250f8a9 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -572,6 +572,50 @@ class delete(Command): self.fm.delete(files) +class jump_non(Command): + """:jump_non [-r] [-w] + + Jumps to first non-directory if highlighted file is a directory and vice versa. + + Options: + `-r` Jump in reverse order + `-w` Wrap around if reaching end of filelist + """ + @staticmethod + def _non(fobj, is_directory): + return fobj.is_directory if not is_directory else not fobj.is_directory + + def execute(self): + reverse = False + wrap = False + for arg in self.args: + if arg == '-r': + reverse = True + elif arg == '-w': + wrap = True + + tfile = self.fm.thisfile + passed = False + found_before = None + found_after = None + for fobj in self.fm.thisdir.files[::-1] if reverse else self.fm.thisdir.files: + if fobj.path == tfile.path: + passed = True + continue + + if passed: + if self._non(fobj, tfile.is_directory): + found_after = fobj.path + break + elif not found_before and self._non(fobj, tfile.is_directory): + found_before = fobj.path + + if found_after: + self.fm.select_file(found_after) + elif wrap and found_before: + self.fm.select_file(found_before) + + class mark_tag(Command): """:mark_tag [<tags>] diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 5de0b18f..e3cff565 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -336,6 +336,7 @@ map L history_go 1 map ] move_parent 1 map [ move_parent -1 map } traverse +map ) jump_non map gh cd ~ map ge cd /etc |