diff options
-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') |