diff options
author | nfnty <git@nfnty.se> | 2017-01-24 05:14:46 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-01-24 05:21:03 +0100 |
commit | 94dc542c80d56afd2edf9c80e5f4031770920f94 (patch) | |
tree | 8908e3e80908b7f321f7175138d940714bdb95ba /ranger | |
parent | 14f6e996305933d2a37d02c3a3ed87dc4a66b5e3 (diff) | |
download | ranger-94dc542c80d56afd2edf9c80e5f4031770920f94.tar.gz |
config.commands: `setlocal`: Properly parse path with spaces
Added proper quote parsing Fixes #753
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 35 | ||||
-rw-r--r-- | ranger/container/settings.py | 2 |
2 files changed, 23 insertions, 14 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index eba94e19..cd9e0444 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -387,25 +387,34 @@ class setlocal(set_): Gives an option a new value. """ - PATH_RE = re.compile(r'^\s*path="?(.*?)"?\s*$') + PATH_RE_DQUOTED = re.compile(r'^setlocal\s+path="(.*?)"') + PATH_RE_SQUOTED = re.compile(r"^setlocal\s+path='(.*?)'") + PATH_RE_UNQUOTED = re.compile(r'^path=(.*?)$') + + def _re_shift(self, match): + if not match: + return None + path = os.path.expanduser(match.group(1)) + for _ in range(len(path.split())): + self.shift() + return path def execute(self): - match = self.PATH_RE.match(self.arg(1)) - if match: - path = os.path.normpath(os.path.expanduser(match.group(1))) - self.shift() - elif self.fm.thisdir: + path = self._re_shift(self.PATH_RE_DQUOTED.match(self.line)) + if path is None: + path = self._re_shift(self.PATH_RE_SQUOTED.match(self.line)) + if path is None: + path = self._re_shift(self.PATH_RE_UNQUOTED.match(self.arg(1))) + if path is None and self.fm.thisdir: path = self.fm.thisdir.path - else: - path = None + if not path: + return - if path: - name = self.arg(1) - name, value, _ = self.parse_setting_line() - self.fm.set_option_from_string(name, value, localpath=path) + name, value, _ = self.parse_setting_line() + self.fm.set_option_from_string(name, value, localpath=path) -class setintag(setlocal): +class setintag(set_): """:setintag <tag or tags> <option name>=<option value> Sets an option for directories that are tagged with a specific tag. diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 012b5a2c..4744de4d 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -167,7 +167,7 @@ class Settings(SignalDispatcher, FileManagerAware): try: localpath = self.fm.thisdir.path except AttributeError: - localpath = path + localpath = None if localpath: for pattern, regex in self._localregexes.items(): |