summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2014-12-05 16:40:42 +0100
committerhut <hut@lepus.uberspace.de>2014-12-05 16:40:42 +0100
commitc82a8a76989c87381a4e7a676f93ad4bf701c58b (patch)
tree78e41853574af9e5fcfa8fed2df8357b355d5f9b /ranger
parent5b6901f8067d783fd3e91efe32553339b4746c52 (diff)
parentf9b4e8c0a31d38fb48ee0e61e17a9534f00fdd82 (diff)
downloadranger-c82a8a76989c87381a4e7a676f93ad4bf701c58b.tar.gz
Merge branch 'filter_by_filetype' of https://github.com/tex/ranger
Conflicts:
	ranger/config/commands.py
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/commands.py27
-rw-r--r--ranger/container/directory.py26
2 files changed, 44 insertions, 9 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 4e82fb0f..1f59ee90 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1187,6 +1187,33 @@ class scout(Command):
         return count == 1
 
 
+class filter_inode_type(Command):
+    """
+    :filter_inode_type [dfl]
+
+    Displays only the files of specified inode type. Parameters
+    can be combined.
+
+        d display directories
+        f display files
+        l display links
+    """
+
+    FILTER_DIRS  = 'd'
+    FILTER_FILES = 'f'
+    FILTER_LINKS = 'l'
+
+    def execute(self):
+        if not self.arg(1):
+            self.fm.thisdir.inode_type_filter = None
+        else:
+            self.fm.thisdir.inode_type_filter = lambda file: (
+                    True if ((self.FILTER_DIRS  in self.arg(1) and file.is_directory) or
+                             (self.FILTER_FILES in self.arg(1) and file.is_file and not file.is_link) or
+                             (self.FILTER_LINKS in self.arg(1) and file.is_link)) else False)
+        self.fm.thisdir.refilter()
+
+
 class grep(Command):
     """:grep <string>
 
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 7bef379d..7d39daaf 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -36,13 +36,18 @@ def sort_naturally(path):
 def sort_naturally_icase(path):
     return path.basename_natural_lower
 
-def accept_file(fname, directory, hidden_filter, name_filter):
-    if hidden_filter and hidden_filter.search(fname):
-        return False
-    if name_filter and not name_filter.search(fname):
-        return False
-    if directory.temporary_filter and not directory.temporary_filter.search(fname):
-        return False
+def accept_file(file, filters):
+    """
+    Returns True if file shall be shown, otherwise False.
+    Parameters:
+        file - an instance of FileSystemObject
+        filters - an array of lambdas, each expects a file and
+                  returns True if file shall be shown,
+                  otherwise False.
+    """
+    for filter in filters:
+        if filter and not filter(file):
+            return False
     return True
 
 def walklevel(some_dir, level):
@@ -78,6 +83,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
     files_all = None
     filter = None
     temporary_filter = None
+    inode_type_filter = None
     marked_items = None
     scroll_begin = 0
 
@@ -197,8 +203,10 @@ class Directory(FileSystemObject, Accumulator, Loadable):
         else:
             hidden_filter = None
 
-        self.files = [f for f in self.files_all if accept_file(
-            f.basename, self, hidden_filter, self.filter)]
+        filters = [(lambda file: not hidden_filter.search(file.basename)) if hidden_filter else None,
+                   (lambda file: self.filter.search(file.basename)) if self.filter else None,
+                   self.inode_type_filter]
+        self.files = [f for f in self.files_all if accept_file(f, filters)]
         self.move_to_obj(self.pointed_obj)
 
     # XXX: Check for possible race conditions
b7263a47d67a0cf67e'>df0485ae ^
79ca54b3 ^






df0485ae ^
79ca54b3 ^



5b698455 ^
79ca54b3 ^


6195ab7d ^
79ca54b3 ^



df0485ae ^
79ca54b3 ^




5b698455 ^
79ca54b3 ^

5b698455 ^
79ca54b3 ^

5b698455 ^
4ca73eb6 ^

5b698455 ^
79ca54b3 ^




df0485ae ^
79ca54b3 ^
df0485ae ^
79ca54b3 ^

4ca73eb6 ^
79ca54b3 ^
5b698455 ^
79ca54b3 ^



f3060715 ^
47588257 ^
0c145043 ^
47588257 ^









14a1649c ^
0c145043 ^

47588257 ^
188206bd ^
47588257 ^









188206bd ^

14a1649c ^


188206bd ^

47588257 ^
188206bd ^
47588257 ^









14a1649c ^


188206bd ^

47588257 ^
33d602db ^
47588257 ^

f7a26719 ^

47588257 ^






f7a26719 ^

47588257 ^



33d602db ^


8799371a ^
cc36784d ^
33d602db ^









8799371a ^
445a1494 ^

47588257 ^
445a1494 ^
47588257 ^

47588257 ^


f7a26719 ^
47588257 ^






f7a26719 ^
47588257 ^















445a1494 ^


8799371a ^
cc36784d ^
445a1494 ^









8799371a ^
33d602db ^
47588257 ^
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239