about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2018-08-23 13:54:49 +0200
committertoonn <toonn@toonn.io>2018-09-06 15:20:54 +0200
commit0ae55822c4f353438d548a4ee63185a59702ccd2 (patch)
treed956b82fda13580946453bf9d1ed768915a3dcf3
parentcc6d9a0b19d250215b822342436e8e81e71c4b4d (diff)
downloadranger-0ae55822c4f353438d548a4ee63185a59702ccd2.tar.gz
Add the %any_path macro
The `%any` macro is very useful for commands that know about bookmarks.
Bookmarks are just short names for paths really, so it'd be nice if they
could be used with any commands that take paths as arguments.

Now they can! `%any_pathX` where `X` refers to the which `<any>` the
macro corresponds to (`%any_path` is synonymous with `%any_path0`) is
replaced with the path of the bookmark entered if that bookmark exists.

Fixes #1277
-rw-r--r--ranger/core/actions.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 83cfcc08..4ee69504 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -240,10 +240,23 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         cmd = cmd_class(string, quantifier=quantifier)
 
         if cmd.resolve_macros and _MacroTemplate.delimiter in cmd.line:
-            macros = dict(('any%d' % i, key_to_string(char))
-                          for i, char in enumerate(wildcards if wildcards is not None else []))
+            f1 = lambda i, c: ('any{:d}'.format(i), key_to_string(c)) 
+            def f2(i, c):
+                try:
+                    val = self.fm.bookmarks[key_to_string(c)]
+                except KeyError:
+                    self.notify('No bookmark defined for `{}`'.format(
+                        key_to_string(c)), bad=True)
+                    val = MACRO_FAIL
+                return ('any_path{:d}'.format(i), val)
+
+            macros = dict(f(i, char) for f in (f1, f2) for i, char
+                          in enumerate(wildcards if wildcards
+                              is not None else []))
             if 'any0' in macros:
                 macros['any'] = macros['any0']
+                if 'any_path0' in macros:
+                    macros['any_path'] = macros['any_path0']
             try:
                 line = self.substitute_macros(cmd.line, additional=macros,
                                               escape=cmd.escape_macros_for_shell)