diff options
author | hut <hut@lavabit.com> | 2010-04-08 18:49:34 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-08 18:49:34 +0200 |
commit | e8faa101b6e59239e5bea2d52eba7b1d2ed707b0 (patch) | |
tree | 65f41e5b098a8c3040e2f3988411d9dc49e40036 /ranger | |
parent | 1c09037cb7484bdd101c07f8373e2ea6fc9f91fd (diff) | |
download | ranger-e8faa101b6e59239e5bea2d52eba7b1d2ed707b0.tar.gz |
added :set <name>=<value> command
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/defaults/commands.py | 33 | ||||
-rw-r--r-- | ranger/ext/command_parser.py | 16 | ||||
-rw-r--r-- | ranger/shared/settings.py | 12 |
3 files changed, 61 insertions, 0 deletions
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index c0e1ccf1..c364fda0 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -236,6 +236,39 @@ class find(Command): return self.count == 1 +class set(Command): + """ + :set <option name>=<python expression> + + Gives an option a new value. + """ + def execute(self): + line = parse(self.line) + name = line.chunk(1) + try: + value = eval(line.rest(2)) + except: + return + self.fm.settings[name] = value + + def tab(self): + line = parse(self.line) + name, value, name_done = line.parse_setting_line() + settings = self.fm.settings + if not name: + return (line + setting for setting in settings) + if not value and not name_done: + return (line + setting for setting in settings \ + if setting.startswith(name)) + if not value: + return line + repr(settings[name]) + if bool in settings.types_of(name): + if 'true'.startswith(value.lower()): + return line + 'True' + if 'false'.startswith(value.lower()): + return line + 'False' + + class quit(Command): """ :quit diff --git a/ranger/ext/command_parser.py b/ranger/ext/command_parser.py index a6971631..3a676e8f 100644 --- a/ranger/ext/command_parser.py +++ b/ranger/ext/command_parser.py @@ -13,12 +13,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import re +SETTINGS_RE = re.compile(r'^([^\s]+?)=(.*)$') + class LazyParser(object): """Parse commands and extract information""" def __init__(self, line): self.line = line self._chunks = None self._rests = None + self._setting_line = None self._rests_loaded = 0 self._rests_gen_instance = None @@ -62,5 +66,17 @@ class LazyParser(object): lastrest = lastrest[n:] n = 0 + def parse_setting_line(self): + if self._setting_line is not None: + return self._setting_line + match = SETTINGS_RE.match(self.rest(1)) + if match: + self.firstpart += match.group(1) + '=' + result = [match.group(1), match.group(2), True] + else: + result = [self.chunk(1), self.rest(2), ' ' in self.rest(1)] + self._setting_line = result + return result + def __add__(self, newpart): return self.firstpart + newpart diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index 9a8a0000..c5544a47 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -95,6 +95,18 @@ class SettingObject(SignalDispatcher): for x in self._settings: yield x + def types_of(self, name): + try: + typ = ALLOWED_SETTINGS[name] + except KeyError: + return tuple() + else: + if isinstance(typ, tuple): + return typ + else: + return (typ, ) + + def _check_type(self, name, value): from inspect import isfunction typ = ALLOWED_SETTINGS[name] |