about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2017-06-08 23:19:02 +0200
committerhut <hut@lepus.uberspace.de>2017-06-08 23:19:02 +0200
commit88e0bc0540fb963b3cf638217dd578b127fd6a3a (patch)
treecea1d65d99f4b00b928a29b342b698956e53a197
parent6f9367826ff430558cb1429cac58992fba787688 (diff)
parent48db8b597814a1f94b3f99f86bf1e242fd8c7a5e (diff)
downloadranger-88e0bc0540fb963b3cf638217dd578b127fd6a3a.tar.gz
Merge branch 'choosedir-821' of https://github.com/randynobx/ranger
-rwxr-xr-xranger/config/commands.py14
-rw-r--r--ranger/container/directory.py24
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/core/main.py4
4 files changed, 29 insertions, 14 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index f28b5553..be0bbe3e 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1496,22 +1496,12 @@ class filter_inode_type(Command):
         f display files
         l display links
     """
-    # pylint: disable=bad-whitespace
-    FILTER_DIRS  = 'd'
-    FILTER_FILES = 'f'
-    FILTER_LINKS = 'l'
-    # pylint: enable=bad-whitespace
 
     def execute(self):
         if not self.arg(1):
-            self.fm.thisdir.inode_type_filter = None
+            self.fm.thisdir.inode_type_filter = ""
         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.inode_type_filter = self.arg(1)
         self.fm.thisdir.refilter()
 
 
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index b50279cc..fbbf4d22 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -93,6 +93,12 @@ def mtimelevel(path, level):
     return mtime
 
 
+class InodeFilterConstants(object):  # pylint: disable=too-few-public-methods
+    DIRS = 'd'
+    FILES = 'f'
+    LINKS = 'l'
+
+
 class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public-methods
         FileSystemObject, Accumulator, Loadable):
     is_directory = True
@@ -260,11 +266,25 @@ class Directory(  # pylint: disable=too-many-instance-attributes,too-many-public
             # 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.settings.global_inode_type_filter or self.inode_type_filter:
+            def inode_filter_func(obj):
+                # Use local inode_type_filter if present, global otherwise
+                inode_filter = self.inode_type_filter or self.settings.global_inode_type_filter
+                # Apply filter
+                if InodeFilterConstants.DIRS in inode_filter and \
+                        obj.is_directory:
+                    return True
+                elif InodeFilterConstants.FILES in inode_filter and \
+                        obj.is_file and not obj.is_link:
+                    return True
+                elif InodeFilterConstants.LINKS in inode_filter and \
+                        obj.is_link:
+                    return True
+                return False
+            filters.append(inode_filter_func)
         if self.filter:
             filter_search = self.filter.search
             filters.append(lambda fobj: filter_search(fobj.basename))
-        if self.inode_type_filter:
-            filters.append(self.inode_type_filter)
         if self.temporary_filter:
             temporary_filter_search = self.temporary_filter.search
             filters.append(lambda fobj: temporary_filter_search(fobj.basename))
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 70e299c7..00563772 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -41,6 +41,7 @@ ALLOWED_SETTINGS = {
     'draw_borders': bool,
     'draw_progress_bar_in_status_bar': bool,
     'flushinput': bool,
+    'global_inode_type_filter': str,
     'hidden_filter': str,
     'idle_delay': int,
     'line_numbers': str,
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 9a0fe59f..69fd6909 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -119,6 +119,10 @@ def main(
         FileManagerAware.fm_set(fm)
         load_settings(fm, args.clean)
 
+        if args.choosedir:
+            from ranger.container.directory import InodeFilterConstants
+            fm.settings.global_inode_type_filter = InodeFilterConstants.DIRS
+
         if args.list_unused_keys:
             from ranger.ext.keybinding_parser import (special_keys,
                                                       reversed_special_keys)