From fbabb96be23ca2d66c65a63a5b91154c1ccc56b5 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 1 Jan 2010 22:46:02 +0100 Subject: commands: added grep command --- ranger/commands.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ranger/commands.py b/ranger/commands.py index dcc70dc7..95dfaf99 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -2,6 +2,7 @@ import os from ranger.shared import FileManagerAware from ranger.gui.widgets import console_mode as cmode from ranger.ext.command_parser import LazyParser as parse +from ranger import log class Command(FileManagerAware): """Abstract command class""" @@ -277,6 +278,22 @@ class filter(Command): self.fm.set_filter(line.rest(1)) +class grep(Command): + """ + :grep + + Looks for a string in all marked files or directories + """ + def execute(self): + from ranger.applications import run + line = parse(self.line) + if line.rest(1): + action = ['grep', '--color=always', '--line-number'] + action.extend(['-e', line.rest(1), '-r']) + action.extend(map(lambda x: x.path, self.fm.env.get_selection())) + run(fm=self.fm, action=action, flags='p') + + # -------------------------------- rest by_name = {} -- cgit 1.4.1-2-gfad0