From 4ab0172d609bcb3f0157dc4403afb525dde507cd Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 27 Dec 2009 03:36:01 +0100 Subject: allow to filter contents of a directory --- ranger/actions.py | 6 ++++++ ranger/commands.py | 6 ++++++ ranger/defaults/keys.py | 1 + ranger/fsobject/directory.py | 9 +++++++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ranger/actions.py b/ranger/actions.py index aa2cc311..e1005201 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -205,6 +205,12 @@ class Actions(EnvironmentAware, SettingsAware): if cf is not None: cf.force_load = True + def set_filter(self, fltr): + try: + self.env.pwd.filter = fltr + except: + pass + # ------------------------------------ filesystem operations def copy(self): diff --git a/ranger/commands.py b/ranger/commands.py index 07fa1679..19e02b76 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -235,6 +235,12 @@ class rename(Command): def tab(self): return self._tab_directory_content() + + +class filter(Command): + def execute(self): + line = parse(self.line) + self.fm.set_filter(line.rest(1)) # -------------------------------- rest diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index fcd6591e..dd17903d 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -84,6 +84,7 @@ def initialize_commands(command_list): bind('term', do('spawn', 'x-terminal-emulator')) bind('du', do('runcmd', 'du --max-depth=1 -h | less')) + bind('tf', do('open_console', cmode.COMMAND, 'filter ')) # key combinations which change the current directory def cd(path): diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 12e687bc..f263aa74 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -31,6 +31,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): old_directories_first = None old_reverse = None old_sort = None + old_filter = None sort_dict = { 'basename': sort_by_basename, @@ -54,6 +55,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.old_show_hidden = self.settings.show_hidden self.old_directories_first = self.settings.directories_first self.old_sort = self.settings.sort + self.old_filter = self.filter self.old_reverse = self.settings.reverse def get_list(self): @@ -122,7 +124,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): for fname in listdir(self.path): if not self.settings.show_hidden and fname[0] == '.': continue - if isinstance(self.filter, str) and self.filter in fname: + if isinstance(self.filter, str) and self.filter \ + and self.filter not in fname: continue filenames.append(join(self.path, fname)) yield @@ -298,7 +301,9 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): if self.load_content_once(*a, **k): return True - if self.old_show_hidden != self.settings.show_hidden: + if self.old_show_hidden != self.settings.show_hidden or \ + self.old_filter != self.filter: + self.old_filter = self.filter self.old_show_hidden = self.settings.show_hidden self.load_content(*a, **k) return True -- cgit 1.4.1-2-gfad0