diff options
-rw-r--r-- | doc/ranger.1 | 84 | ||||
-rw-r--r-- | doc/ranger.pod | 72 | ||||
-rwxr-xr-x | ranger/config/commands.py | 25 | ||||
-rw-r--r-- | ranger/core/actions.py | 3 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 4 |
5 files changed, 138 insertions, 50 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1 index b251edbe..d050b3b2 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.9.2" "2019-05-19" "ranger manual" +.TH RANGER 1 "ranger-1.9.2" "2019-05-20" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -155,9 +155,9 @@ ranger \- visual file manager ranger is a console file manager with \s-1VI\s0 key bindings. .SH "RESOURCES" .IX Header "RESOURCES" -\&\fIThis manual\fR contains instructions on how to use and configure ranger. +This \fImanual\fR contains instructions on how to use and configure ranger. .PP -\&\fIInside ranger\fR, you can press \fI?\fR for a list of key bindings, commands or +Inside \fIranger\fR, you can press \fI?\fR for a list of key bindings, commands or settings. .PP The \fI\s-1README\s0\fR contains install instructions. @@ -383,13 +383,45 @@ are in different directories: Macros for file paths are generally shell-escaped so they can be used in the \&\f(CW\*(C`shell\*(C'\fR command. .PP -Additionally, if you create a key binding that uses <any>, a special statement -which accepts any key, then the macro \f(CW%any\fR (or \f(CW%any0\fR, \f(CW%any1\fR, \f(CW%any2\fR, ...) can be -used in the command to get the key that was pressed. +When mapping keys you can use the placeholder <any>, the key entered in that +position can be used through the \f(CW%any\fR and \f(CW%any_path\fR macros. (When using +multiple <any> placeholders you can index the macros: \f(CW%any0\fR, \f(CW%any_path0\fR, \f(CW%any1\fR, +\&\f(CW%any_path1\fR...) The macro \f(CW%any\fR will be replaced with the key pressed in the +position of the <any> placeholder. The macro \f(CW%any_path\fR will be replaced with +the path of the bookmark mapped to the key pressed in the position of the +<any> placeholder. For example this macro can be used to echo the key that was +pressed after \*(L"c\*(R": +.PP +.Vb 1 +\& map c<any> echo %any +.Ve +.PP +\&\f(CW%any\fR is used in the ranger configuration to create a keybinding for adding a +bookmark. c<set_bookmark> creates a bookmark for the current directory and the +key for the bookmark is the first supplied argument. In this case the key +pressed after \*(L"m\*(R": +.PP +.Vb 1 +\& map m<any> set_bookmark %any +.Ve +.PP +The \f(CW%any_path\fR macro can be used to echo the path of the bookmark that is set to +the key pressed after \*(L"c\*(R": +.PP +.Vb 1 +\& map c<any> echo %any_path +.Ve +.PP +A practical example of the use of \f(CW%any_path\fR is the pasting of cut/copied files +to a bookmarked directory: +.PP +.Vb 1 +\& map p\*(Aq<any> paste dest=%any_path +.Ve .PP The macro \f(CW%rangerdir\fR expands to the directory of ranger's python library, you can use it for something like this command: - alias show_commands shell less \f(CW%rangerdir\fR/config/commands.py + alias show_commands shell less \f(CW%rangerdir\fR/config/commands.py .PP \&\f(CW%confdir\fR expands to the directory given by \fB\-\-confdir\fR. .PP @@ -1301,19 +1333,27 @@ Flags: .IX Item "linemode linemodename" Sets the linemode of all files in the current directory. The linemode may be: .Sp -.Vb 12 -\& "filename": display each line as "<basename>...<size>" -\& "fileinfo": display each line as "<basename>...<file(1) output>" -\& "mtime": display each line as "<basename>...<mtime>" in ISO format -\& "humanreadablemtime": display each line as "<basename>...<mtime>" in a human -\& readable format, more precise the more recent -\& "permissions": display each line as "<permissions> <owner> <group> <basename>" -\& "sizemtime": display each line as "<basename>...<size> <mtime>" in ISO format -\& "humanreadablesizemtime": display each line as "<basename>...<size> <mtime>" -\& in a human readable format, more precise the more recent -\& "metatitle": display metadata from .metadata.json files if -\& available, fall back to the "filename" linemode if no -\& metadata was found. See :meta command. +.Vb 10 +\& "filename": +\& display each line as "<basename>...<size>" +\& "fileinfo": +\& display each line as "<basename>...<file(1) output>" +\& "mtime": +\& display each line as "<basename>...<mtime>" in ISO format +\& "humanreadablemtime": +\& display each line as "<basename>...<mtime>" in a human readable +\& format, more precise the more recent. +\& "sizemtime": +\& display each line as "<basename>...<size> <mtime>" in ISO format +\& "humanreadablesizemtime": +\& display each line as "<basename>...<size> <mtime>" in a human +\& readable format, more precise the more recent. +\& "permissions": +\& display each line as "<permissions> <owner> <group> <basename>" +\& "metatitle": +\& display metadata from .metadata.json files if available, fall back +\& to the "filename" linemode if no metadata was found. +\& See :meta command. .Ve .Sp The custom linemodes may be added by subclassing the \fILinemodeBase\fR class. @@ -1637,7 +1677,7 @@ Defines the terminal emulator command that ranger is going to use with the .IP "\s-1PYGMENTIZE_STYLE\s0" 8 .IX Item "PYGMENTIZE_STYLE" Specifies the theme to be used for syntax highlighting when \fIpygmentize\fR is -installed unless \fIhighlight\fR is also installed. Find out possible values by +installed, unless \fIhighlight\fR is also installed. Find out possible values by running: python \-c 'import pygments.styles; [print(stl) for stl in pygments.styles.\fBget_all_styles()\fR]' @@ -1652,7 +1692,7 @@ Specifies the number of spaces to use to replace tabs in \fIhighlight\fRed files .IX Item "HIGHLIGHT_OPTIONS" \&\fIhighlight\fR will pick up command line options specified in this variable. A \&\f(CW\*(C`\-\-style=\*(C'\fR option specified here will override \f(CW\*(C`HIGHLIGHT_STYLE\*(C'\fR. Similarly, -\&\f(CW\*(C`\-\-replace\-tabs=\*(C'\fR will override \f(CW\*(C`HIGHLIGHT_TABWIDTH\*(C'\fR.. +\&\f(CW\*(C`\-\-replace\-tabs=\*(C'\fR will override \f(CW\*(C`HIGHLIGHT_TABWIDTH\*(C'\fR. .IP "\s-1XDG_CONFIG_HOME\s0" 8 .IX Item "XDG_CONFIG_HOME" Specifies the directory for configuration files. Defaults to \fI\f(CI$HOME\fI/.config\fR. diff --git a/doc/ranger.pod b/doc/ranger.pod index 1c87c675..7a414df6 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -28,9 +28,9 @@ ranger is a console file manager with VI key bindings. =head1 RESOURCES -I<This manual> contains instructions on how to use and configure ranger. +This I<manual> contains instructions on how to use and configure ranger. -I<Inside ranger>, you can press I<?> for a list of key bindings, commands or +Inside I<ranger>, you can press I<?> for a list of key bindings, commands or settings. The F<README> contains install instructions. @@ -286,13 +286,37 @@ are in different directories: Macros for file paths are generally shell-escaped so they can be used in the C<shell> command. -Additionally, if you create a key binding that uses <any>, a special statement -which accepts any key, then the macro %any (or %any0, %any1, %any2, ...) can be -used in the command to get the key that was pressed. +When mapping keys you can use the placeholder <any>, the key entered in that +position can be used through the %any and %any_path macros. (When using +multiple <any> placeholders you can index the macros: %any0, %any_path0, %any1, +%any_path1...) The macro %any will be replaced with the key pressed in the +position of the <any> placeholder. The macro %any_path will be replaced with +the path of the bookmark mapped to the key pressed in the position of the +<any> placeholder. For example this macro can be used to echo the key that was +pressed after "c": + + map c<any> echo %any + +%any is used in the ranger configuration to create a keybinding for adding a +bookmark. c<set_bookmark> creates a bookmark for the current directory and the +key for the bookmark is the first supplied argument. In this case the key +pressed after "m": + + map m<any> set_bookmark %any + +The %any_path macro can be used to echo the path of the bookmark that is set to +the key pressed after "c": + + map c<any> echo %any_path + +A practical example of the use of %any_path is the pasting of cut/copied files +to a bookmarked directory: + + map p'<any> paste dest=%any_path The macro %rangerdir expands to the directory of ranger's python library, you can use it for something like this command: - alias show_commands shell less %rangerdir/config/commands.py + alias show_commands shell less %rangerdir/config/commands.py %confdir expands to the directory given by B<--confdir>. @@ -869,7 +893,7 @@ Draw borders around or between the columns? Possible values are: outline draw an outline around all the columns separators draw only vertical lines between columns both both of the above - + =item draw_progress_bar_in_status_bar [bool] Draw a progress bar in the status bar which displays the average state of all @@ -1385,18 +1409,26 @@ Flags: Sets the linemode of all files in the current directory. The linemode may be: - "filename": display each line as "<basename>...<size>" - "fileinfo": display each line as "<basename>...<file(1) output>" - "mtime": display each line as "<basename>...<mtime>" in ISO format - "humanreadablemtime": display each line as "<basename>...<mtime>" in a human - readable format, more precise the more recent - "permissions": display each line as "<permissions> <owner> <group> <basename>" - "sizemtime": display each line as "<basename>...<size> <mtime>" in ISO format - "humanreadablesizemtime": display each line as "<basename>...<size> <mtime>" - in a human readable format, more precise the more recent - "metatitle": display metadata from .metadata.json files if - available, fall back to the "filename" linemode if no - metadata was found. See :meta command. + "filename": + display each line as "<basename>...<size>" + "fileinfo": + display each line as "<basename>...<file(1) output>" + "mtime": + display each line as "<basename>...<mtime>" in ISO format + "humanreadablemtime": + display each line as "<basename>...<mtime>" in a human readable + format, more precise the more recent. + "sizemtime": + display each line as "<basename>...<size> <mtime>" in ISO format + "humanreadablesizemtime": + display each line as "<basename>...<size> <mtime>" in a human + readable format, more precise the more recent. + "permissions": + display each line as "<permissions> <owner> <group> <basename>" + "metatitle": + display metadata from .metadata.json files if available, fall back + to the "filename" linemode if no metadata was found. + See :meta command. The custom linemodes may be added by subclassing the I<LinemodeBase> class. See the I<ranger.core.linemode> module for some examples. @@ -1784,7 +1816,7 @@ Defines the terminal emulator command that ranger is going to use with the =item PYGMENTIZE_STYLE Specifies the theme to be used for syntax highlighting when I<pygmentize> is -installed unless I<highlight> is also installed. Find out possible values by +installed, unless I<highlight> is also installed. Find out possible values by running: python -c 'import pygments.styles; [print(stl) for stl in pygments.styles.get_all_styles()]' diff --git a/ranger/config/commands.py b/ranger/config/commands.py index cb2207ce..2b1f4940 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1064,7 +1064,8 @@ class bulkrename(Command): After you close it, it will be executed. """ - def execute(self): # pylint: disable=too-many-locals,too-many-statements + def execute(self): + # pylint: disable=too-many-locals,too-many-statements,too-many-branches import sys import tempfile from ranger.container.file import File @@ -1093,11 +1094,23 @@ class bulkrename(Command): # Generate script cmdfile = tempfile.NamedTemporaryFile() script_lines = [] - script_lines.append("# This file will be executed when you close the editor.\n") - script_lines.append("# Please double-check everything, clear the file to abort.\n") - script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new)) - for old, new in zip(filenames, new_filenames) if old != new) - script_content = "".join(script_lines) + script_lines.append("# This file will be executed when you close the" + " editor.") + script_lines.append("# Please double-check everything, clear the file" + " to abort.") + new_dirs = [] + for old, new in zip(filenames, new_filenames): + if old != new: + basepath, _ = os.path.split(new) + if (basepath is not None and basepath not in new_dirs + and not os.path.isdir(basepath)): + script_lines.append("mkdir -vp -- {dir}".format( + dir=esc(basepath))) + new_dirs.append(basepath) + script_lines.append("mv -vi -- {old} {new}".format( + old=esc(old), new=esc(new))) + # Make sure not to forget the ending newline + script_content = "\n".join(script_lines) + "\n" if py3: cmdfile.write(script_content.encode("utf-8")) else: diff --git a/ranger/core/actions.py b/ranger/core/actions.py index e7be0c65..435fcf13 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -960,7 +960,8 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m except IndexError: self.ui.browser.draw_info = [] return - programs = [program for program in self.rifle.list_commands([target.path], None)] + programs = [program for program in self.rifle.list_commands([target.path], None, + skip_ask=True)] if programs: num_digits = max((len(str(program[0])) for program in programs)) program_info = ['%s | %s' % (str(program[0]).rjust(num_digits), program[1]) diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index ad7d0049..a55e14c7 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -277,7 +277,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes filenames = "' '".join(f.replace("'", "'\\\''") for f in files if "\x00" not in f) return "set -- '%s'; %s" % (filenames, action) - def list_commands(self, files, mimetype=None): + def list_commands(self, files, mimetype=None, skip_ask=False): """List all commands that are applicable for the given files Returns one 4-tuple for all currently applicable commands @@ -292,6 +292,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self._skip = None self._app_flags = '' self._app_label = None + if skip_ask and cmd == ASK_COMMAND: + continue for test in tests: if not self._eval_condition(test, files, None): break |