diff options
author | toonn <toonn@toonn.io> | 2021-09-05 21:29:52 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2021-09-05 21:29:52 +0200 |
commit | c9483afe890ad3efb7c76212512aa0e587116ebf (patch) | |
tree | 3a73018fd0240d3c4189768a170cbd3c2be723bf /ranger | |
parent | d75dd6971ee8f67eebedfc797ae57154ae1ffb69 (diff) | |
download | ranger-c9483afe890ad3efb7c76212512aa0e587116ebf.tar.gz |
commands: Implement setinregex
The original behavior of `setlocal` allowed to pass in a regular expression that would be matched to paths. This was confusing for some users because many paths contain regular expression metacharacters and these would affect in which directories the settings apply in unexpected ways. To remedy this we decided to escape all metacharacters by default but this came at the cost of being unable to specify precisely which directories would match, as this made use of the `$` metacharacter with the original behavior. The behavior has been fixed to never match subdirectories but changing back to the original behavior and introducing a second backwards incompatible change was deemed a bad idea. So we decided to make `setlocal` an alias for the new `setinpath` and implement a `setinregex` that exhibits the original `setlocal` behavior, allowing for complex regular expressions.
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 5af41723..deda44bd 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -571,6 +571,23 @@ class setlocal(setinpath): pass +class setinregex(_setlocal): + """:setinregex re=<regex> <option name>=<python expression> + + Sets an option when in a specific directory. If the <regex> contains + whitespace it needs to be quoted and nested quotes need to be + backslash-escaped. Special characters need to be escaped if they are + intended to match literally as documented in the ``re`` library + documentation. The "re" argument can also be named "regex" or "pattern," + which allows for easier switching with ``setinpath``. + """ + def _arg(self): + return "(?:re(?:gex)?|pattern)" + + def _format_arg(self, arg): + return arg + + class setintag(set_): """:setintag <tag or tags> <option name>=<option value> |