about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-01 22:46:02 +0100
committerhut <hut@lavabit.com>2010-01-01 22:46:02 +0100
commitfbabb96be23ca2d66c65a63a5b91154c1ccc56b5 (patch)
tree465a0a954eaabf386671de3d1373c5bc736692cc
parent36e4e71ee5643fc0b2c501956086434389ec5384 (diff)
downloadranger-fbabb96be23ca2d66c65a63a5b91154c1ccc56b5.tar.gz
commands: added grep command
-rw-r--r--ranger/commands.py17
1 files changed, 17 insertions, 0 deletions
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 <string>
+
+	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 = {}