summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2017-06-08 23:07:48 +0200
committerhut <hut@lepus.uberspace.de>2017-06-08 23:07:48 +0200
commit6f9367826ff430558cb1429cac58992fba787688 (patch)
tree4a0da0c84dd330c6737428d15fa58928445dde6a
parent23e7376fc699d28f7539dd3280b599399419c2ff (diff)
parente2575f6aec18c7236923ee4560f50c48fec9e9ee (diff)
downloadranger-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.conf1
-rwxr-xr-xranger/config/commands.py16
-rw-r--r--ranger/container/directory.py8
-rw-r--r--ranger/gui/widgets/statusbar.py6
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')
tml?h=main&id=34fda13bfd12204f1fc0145005d9df08f31a1b73'>^
608a7fa8 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159