diff options
author | hut <hut@lepus.uberspace.de> | 2017-06-08 23:07:48 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2017-06-08 23:07:48 +0200 |
commit | 6f9367826ff430558cb1429cac58992fba787688 (patch) | |
tree | 4a0da0c84dd330c6737428d15fa58928445dde6a | |
parent | 23e7376fc699d28f7539dd3280b599399419c2ff (diff) | |
parent | e2575f6aec18c7236923ee4560f50c48fec9e9ee (diff) | |
download | ranger-6f9367826ff430558cb1429cac58992fba787688.tar.gz |
Merge branch 'vifon/867/filter_command_to_only_show_marked_files' of https://github.com/Vifon/ranger
-rw-r--r-- | examples/rc_emacs.conf | 1 | ||||
-rwxr-xr-x | ranger/config/commands.py | 16 | ||||
-rw-r--r-- | ranger/container/directory.py | 8 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 6 |
4 files changed, 30 insertions, 1 deletions
diff --git a/examples/rc_emacs.conf b/examples/rc_emacs.conf index d3707a12..26074a42 100644 --- a/examples/rc_emacs.conf +++ b/examples/rc_emacs.conf @@ -406,6 +406,7 @@ map <C-x>zs toggle_option sort_case_insensitive map <C-x>zu toggle_option autoupdate_cumulative_size map <C-x>zv toggle_option use_preview_script map <C-x>zf console filter%space +map <C-x>nn narrow # Bookmarks map <C-x>rb<any> enter_bookmark %any diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 832a33a6..f28b5553 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1469,6 +1469,22 @@ class scout(Command): return count == 1 +class narrow(Command): + """ + :narrow + + Show only the files selected right now. If no files are selected, + disable narrowing. + """ + def execute(self): + if self.fm.thisdir.marked_items: + selection = [f.basename for f in self.fm.thistab.get_selection()] + self.fm.thisdir.narrow_filter = selection + else: + self.fm.thisdir.narrow_filter = None + self.fm.thisdir.refilter() + + class filter_inode_type(Command): """ :filter_inode_type [dfl] diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 168a46c7..b50279cc 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -108,6 +108,7 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public files_all = None filter = None temporary_filter = None + narrow_filter = None inode_type_filter = None marked_items = None scroll_begin = 0 @@ -252,6 +253,13 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public return False return True filters.append(hidden_filter_func) + if self.narrow_filter: + # pylint: disable=unsupported-membership-test + + # Pylint complains that self.narrow_filter is by default + # None but the execution won't reach this line if it is + # still None. + filters.append(lambda fobj: fobj.basename in self.narrow_filter) if self.filter: filter_search = self.filter.search filters.append(lambda fobj: filter_search(fobj.basename)) diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index eb2250ae..980945dc 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -234,7 +234,7 @@ class StatusBar(Widget): # pylint: disable=too-many-instance-attributes except KeyError: return str(gid) - def _get_right_part(self, bar): # pylint: disable=too-many-branches + def _get_right_part(self, bar): # pylint: disable=too-many-branches,too-many-statements right = bar.right if self.column is None: return @@ -256,6 +256,10 @@ class StatusBar(Widget): # pylint: disable=too-many-instance-attributes right.add(str(self.fm.thisdir.flat), base, 'flat') right.add(", ", "space") + if self.fm.thisdir.narrow_filter: + right.add("narrowed") + right.add(", ", "space") + if self.fm.thisdir.filter: right.add("f=`", base, 'filter') right.add(self.fm.thisdir.filter.pattern, base, 'filter') |