about summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-20 02:48:56 +0200
committerhut <hut@lavabit.com>2009-07-20 02:48:56 +0200
commit8181da2ed29c1e14b2989caee4e68bd69db85a3f (patch)
treebf7880ded0d2151b9511e5a00e5ebc09c906d4d2 /code
parent1413a81544b42d55a942a00ec34f55a45d296627 (diff)
downloadranger-8181da2ed29c1e14b2989caee4e68bd69db85a3f.tar.gz
new command: grep
Diffstat (limited to 'code')
-rw-r--r--code/keys.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/code/keys.rb b/code/keys.rb
index 04e79e62..504e7691 100644
--- a/code/keys.rb
+++ b/code/keys.rb
@@ -301,6 +301,16 @@ module Fm
 				@pwd.schedule
 			end
 
+		when /^grep\s?(.*)$/
+			if_enter_pressed($1) do |arg|
+				files = @marked.empty? ? "*" : @marked.sh
+				grep = 'grep --color=always --line-number'
+				less = 'less'
+				externally do
+					system "#{grep} -e #{arg.sh} -r #{files} | #{less}"
+				end
+			end
+
 		when 'tar'
 			externally do
 				system('tar', 'cvvf', 'pack.tar', *selection.map{|x| x.basename})
@@ -539,6 +549,7 @@ module Fm
 			/r\d*\w*[^r]/
 			/(c[wmo]|cd|mv).*/
 			/b(l(o(c(k(.*)?)?)?)?)?/
+			/g(r(e(p(.*)?)?)?)?/
 			/m(k(d(i(r(.*)?)?)?)?)?/
 			/t(o(u(c(h(.*)?)?)?)?)?/
 			/r(e(n(a(m(e(.*)?)?)?)?)?)?/
@@ -668,6 +679,18 @@ module Fm
 
 	SORT_REGEXP = /^S (?i: ( [#{ SORT_KEYS.keys * '|' }] )) $/x
 
+	FINISHED = /^\s?(.*)(<cr>|<esc>)$/
+
+	def if_enter_pressed( text, &block )
+		return unless block_given?
+		if text =~ FINISHED
+			@buffer.clear
+			if $2 == '<cr>'
+				yield( $1 )
+			end
+		end
+	end
+	
 	def self.recalculate_key_combinations
 		@@key_combinations = nil
 		@@key_regexp = nil