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 | |
parent | cc8f5270fdb52714c4606ac62eea0de9c6aac04a (diff) | |
download | ranger-9ce8839a6363d43f2d6f9ce74feb2c21ee4fed41.tar.gz |
Add command for jumping to first non-directory/non-file
Fixes #409
-rw-r--r-- | doc/ranger.1 | 11 | ||||
-rw-r--r-- | doc/ranger.pod | 9 | ||||
-rw-r--r-- | doc/rifle.1 | 2 | ||||
-rwxr-xr-x | ranger/config/commands.py | 44 | ||||
-rw-r--r-- | ranger/config/rc.conf | 1 |
5 files changed, 65 insertions, 2 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1 index 16c7256e..454ed9df 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.8.1" "2017-01-29" "ranger manual" +.TH RANGER 1 "ranger-1.8.1" "2017-02-01" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -910,6 +910,7 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i \& flat level \& grep pattern \& help +\& jump_non [\-r] [\-w] \& linemode linemodename \& load_copy_buffer \& map key command @@ -1075,6 +1076,14 @@ Looks for a string in all marked files or directories. .IP "help" 2 .IX Item "help" Provides a quick way to view ranger documentations. +.IP "jump_non [\fI\-r\fR] [\fI\-w\fR]" 2 +.IX Item "jump_non [-r] [-w]" +Jumps to first non-directory if highlighted file is a directory and vice versa. +.Sp +.Vb 2 +\& \-r Jump in reverse order +\& \-w Wrap around if reaching end of filelist +.Ve .IP "linemode \fIlinemodename\fR" 2 .IX Item "linemode linemodename" Sets the linemode of all files in the current directory. The linemode may be: diff --git a/doc/ranger.pod b/doc/ranger.pod index 0a6bc2c4..a61ae657 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -928,6 +928,7 @@ ranger. For your convenience, this is a list of the "public" commands including flat level grep pattern help + jump_non [-r] [-w] linemode linemodename load_copy_buffer map key command @@ -1118,6 +1119,14 @@ Looks for a string in all marked files or directories. Provides a quick way to view ranger documentations. +=item jump_non [I<-r>] [I<-w>] + +Jumps to first non-directory if highlighted file is a directory and vice versa. + + -r Jump in reverse order + -w Wrap around if reaching end of filelist + + =item linemode I<linemodename> Sets the linemode of all files in the current directory. The linemode may be: diff --git a/doc/rifle.1 b/doc/rifle.1 index cc062f02..14b03794 100644 --- a/doc/rifle.1 +++ b/doc/rifle.1 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "RIFLE 1" -.TH RIFLE 1 "rifle-1.8.1" "2017-01-29" "rifle manual" +.TH RIFLE 1 "rifle-1.8.1" "2017-02-01" "rifle manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l 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 |