diff options
author | hut <hut@lepus.uberspace.de> | 2016-04-03 23:08:10 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2016-04-03 23:59:54 +0200 |
commit | 3ae25fa5b14c224c699e572c31cd8c95dc3d9040 (patch) | |
tree | 78f0297e1218f8901c248d99507e53d48e99473d /ranger | |
parent | 46537efbf1959dcde3f0ad5fb29e0436b324aca2 (diff) | |
download | ranger-3ae25fa5b14c224c699e572c31cd8c95dc3d9040.tar.gz |
allow toggling options with `:set <option>!`
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/api/commands.py | 40 | ||||
-rwxr-xr-x | ranger/config/commands.py | 9 | ||||
-rw-r--r-- | ranger/config/rc.conf | 26 |
3 files changed, 60 insertions, 15 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index a20adecb..c3e0a59a 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -152,6 +152,27 @@ class Command(FileManagerAware): return ''.join([self._tabinsert_left, word, self._tabinsert_right]) def parse_setting_line(self): + """ + Parses the command line argument that is passed to the `:set` command. + Returns [option, value, name_complete]. + + Can parse incomplete lines too, and `name_complete` is a boolean + indicating whether the option name looks like it's completed or + unfinished. This is useful for generating tab completions. + + >>> Command("set foo=bar").parse_setting_line() + ['foo', 'bar', True] + >>> Command("set foo").parse_setting_line() + ['foo', '', False] + >>> Command("set foo=").parse_setting_line() + ['foo', '', True] + >>> Command("set foo ").parse_setting_line() + ['foo', '', True] + >>> Command("set myoption myvalue").parse_setting_line() + ['myoption', 'myvalue', True] + >>> Command("set").parse_setting_line() + ['', '', False] + """ if self._setting_line is not None: return self._setting_line match = _SETTINGS_RE.match(self.rest(1)) @@ -163,6 +184,25 @@ class Command(FileManagerAware): self._setting_line = result return result + def parse_setting_line_v2(self): + """ + Parses the command line argument that is passed to the `:set` command. + Returns [option, value, name_complete, toggle]. + + >>> Command("set foo=bar").parse_setting_line_v2() + ['foo', 'bar', True, False] + >>> Command("set foo!").parse_setting_line_v2() + ['foo', '', True, True] + """ + option, value, name_complete = self.parse_setting_line() + if len(option) >= 2 and option[-1] == '!': + toggle = True + option = option[:-1] + name_complete = True + else: + toggle = False + return [option, value, name_complete, toggle] + def parse_flags(self): """Finds and returns flags in the command diff --git a/ranger/config/commands.py b/ranger/config/commands.py index c41bfcb6..4d00b4c8 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -336,12 +336,17 @@ class set_(Command): """:set <option name>=<python expression> Gives an option a new value. + + Use `:set <option>!` to toggle or cycle it, e.g. `:set flush_input!` """ name = 'set' # don't override the builtin set class def execute(self): name = self.arg(1) - name, value, _ = self.parse_setting_line() - self.fm.set_option_from_string(name, value) + name, value, _, toggle = self.parse_setting_line_v2() + if toggle: + self.fm.toggle_option(name) + else: + self.fm.set_option_from_string(name, value) def tab(self, tabnum): from ranger.gui.colorscheme import get_all_colorschemes diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 44692d79..25972904 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -412,7 +412,7 @@ map <a-8> tab_open 8 map <a-9> tab_open 9 # Sorting -map or toggle_option sort_reverse +map or set sort_reverse! map oz set sort=random map os chain set sort=size; set sort_reverse=False map ob chain set sort=basename; set sort_reverse=False @@ -435,18 +435,18 @@ map oE chain set sort=extension; set sort_reverse=True map dc get_cumulative_size # Settings -map zc toggle_option collapse_preview -map zd toggle_option sort_directories_first -map zh toggle_option show_hidden -map <C-h> toggle_option show_hidden -map zI toggle_option flushinput -map zi toggle_option preview_images -map zm toggle_option mouse_enabled -map zp toggle_option preview_files -map zP toggle_option preview_directories -map zs toggle_option sort_case_insensitive -map zu toggle_option autoupdate_cumulative_size -map zv toggle_option use_preview_script +map zc set collapse_preview! +map zd set sort_directories_first! +map zh set show_hidden! +map <C-h> set show_hidden! +map zI set flushinput! +map zi set preview_images! +map zm set mouse_enabled! +map zp set preview_files! +map zP set preview_directories! +map zs set sort_case_insensitive! +map zu set autoupdate_cumulative_size! +map zv set use_preview_script! map zf console filter%space # Bookmarks |