about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--code/action.rb31
-rw-r--r--code/entry.rb3
-rw-r--r--code/fm/keys.rb21
-rw-r--r--code/runcontext.rb47
-rw-r--r--data/apps.rb52
-rw-r--r--data/types.rb19
-rwxr-xr-xranger.rb14
7 files changed, 126 insertions, 61 deletions
diff --git a/code/action.rb b/code/action.rb
index 34a07242..7a0a9ac7 100644
--- a/code/action.rb
+++ b/code/action.rb
@@ -27,22 +27,13 @@ module Action
 		rc ||= RunContext.new(Fm.getfiles)
 		assert rc, RunContext
 
-		cf       = Fm.currentfile
-		
 		all      = rc.all.or true
-		files    = rc.files.or(all ? Fm.selection : [cf])
+		files    = rc.files
 		mode     = rc.mode.or 0
-		newway   = rc.newway.or false
 
-		return false if files.nil?
+		return false if files.nil? or files.empty?
 
-		if newway
-#			logpp files.first.handler
-#			rc = Fm.filehandler(files, struct)
-			handler = rc.exec
-		else
-			handler, wait = Fm.getfilehandler(*files)
-		end
+		handler = rc.exec
 
 		return false unless handler
 
@@ -52,15 +43,15 @@ module Action
 
 		log handler
 		if detach
-			run_detached(handler, new_term)
+			run_detached(handler, rc)
 		else
-			run_inside(handler, wait)
+			run_inside(handler, rc)
 		end
 		return true
 	end
 
-	def run_detached(what, new_term)
-		if new_term
+	def run_detached(what, rc)
+		if rc.new_term
 			p = fork { exec('x-terminal-emulator', '-e', 'bash', '-c', what) }
 #			Process.detach(p)
 		else
@@ -69,11 +60,11 @@ module Action
 		end
 	end
 
-	def run_inside(what, wait)
-		close_interface
+	def run_inside(what, rc)
+		close_interface unless rc.console
 		system(*what)
-		wait_for_enter if wait
-		start_interface
+		wait_for_enter if rc.wait
+		start_interface unless rc.console
 	end
 
 	def wait_for_enter
diff --git a/code/entry.rb b/code/entry.rb
index bc0d2d7b..7a17bb65 100644
--- a/code/entry.rb
+++ b/code/entry.rb
@@ -27,7 +27,6 @@ class Directory::Entry
 			@basename = File.basename(dirname)
 		end
 		@name, @ext = @basename.split_at_last_dot
-#			@ext = @basename.from_last('.') || ''
 		@movie = MOVIE_EXTENSIONS.include?(@ext)
 		@size = 0
 		@exists = false
@@ -65,7 +64,7 @@ class Directory::Entry
 
 	def handler()
 		## get_handler has to be defined in another file
-		@handler = catch(:use) do
+		@handler ||= catch(:use) do
 			get_handler
 		end
 	end
diff --git a/code/fm/keys.rb b/code/fm/keys.rb
index 4e3af766..f5854dc9 100644
--- a/code/fm/keys.rb
+++ b/code/fm/keys.rb
@@ -513,23 +513,18 @@ module Fm
 				starti
 			end
 
-		when '<cr>', 'l', ';', 'L', '<right>'
-			ascend(@buffer=='L', @buffer=='l')
-
-		# a = run all
-		# d or e = detach
-		# t = run in a terminal
-		# w = wait for <enter> after execution
-		# capital letter inverts
+		when '<cr>', 'l', 'L', '<right>'
+			if currentfile.dir?
+				enter_dir_safely(currentfile.path)
+			else
+				mode = @buffer == 'L' ? 1 : 0
+				Action.run(RunContext.new(getfiles, mode))
+			end
+
 		when /^[ri](\d*)([adetw]*)[ri]$/
 			run_context = RunContext.new(getfiles, $1, $2)
 			Action.run(run_context)
 		
-#		when 'ra'
-#			unless File.directory?(currentfile.path)
-#				Action.run(:all=>true)
-#			end
-
 		when 'ZZ', '<c-d>', ':q<cr>', 'Q'
 			exit
 			
diff --git a/code/runcontext.rb b/code/runcontext.rb
index 1e10aa8d..ce62e60f 100644
--- a/code/runcontext.rb
+++ b/code/runcontext.rb
@@ -1,7 +1,16 @@
 class RunContext
+	# mode is a number from 0 to infinity
+	#
+	# flags are a string or array containing:
+	# * a = run all
+	# * d or e = detach
+	# * t = run in a terminal
+	# * w = wait for <enter> after execution
+	# * c = run from ./ranger.rb <filename> (not usable from inside ranger)
+	# * capital letter inverts
 	## accessors {{{
 	attr_accessor( *%w[
-		all detach wait new_term
+		all detach wait new_term console
 		files handlers paths
 		mode
 		exec
@@ -26,7 +35,11 @@ class RunContext
 
 	def initialize(files, mode=0, flags='')
 		@mode = mode.to_i
-		@files = files.dup
+		if files.is_a? Array
+			@files = files.dup
+		else
+			@files = [files.dup]
+		end
 		self.flags = flags
 		
 		@files.reject! {|file|
@@ -38,7 +51,11 @@ class RunContext
 
 		@multi = (@files.size > 1 and @handlers.uniq.size == 1)
 
-		@exec = Application.send(@handler, self)
+		if @handler
+			@exec = Application.send(@handler, self)
+		else
+			@exec = nil
+		end
 	end
 
 	def has_flag? x
@@ -68,6 +85,9 @@ class RunContext
 		if has_flag? 'w'
 			@wait = true
 		end
+		if has_flag? 'c'
+			@console = true
+		end
 
 		## Negative flags
 		if has_flag? 'A'
@@ -82,10 +102,11 @@ class RunContext
 		if has_flag? 'W'
 			@wait = false
 		end
+		if has_flag? 'C'
+			@console = false
+		end
 	end
 
-	def newway() true end
-
 	def no_mode?()
 		@mode == 0
 	end
@@ -98,7 +119,21 @@ class RunContext
 		if @flagstring.empty?
 			self.flags = x
 		end
-		x
+		return x
+	end
+
+	def base_flags=(x)
+		newflags = (x.is_a? Array) ? x : x.split(//)
+
+		for flag in newflags
+			unless @flags.include? flag.upcase or
+					@flags.include? flag.downcase
+				@flags << flag
+			end
+		end
+
+		self.flags = @flags
+		return x
 	end
 
 	## set the mode and return self.
diff --git a/data/apps.rb b/data/apps.rb
index dc65d1a7..1a9b65d0 100644
--- a/data/apps.rb
+++ b/data/apps.rb
@@ -2,16 +2,16 @@ module Application
 	def mplayer(rc)
 		check rc
 
-		rc.default_flags = 'd'
+		rc.base_flags = 'd'
 
-		if rc.no_mode?
-			rc.mode = (rc.name =~ /720p/) ? 2 : 1
-		end
+#		if rc.no_mode?
+#			rc.mode = (rc.name =~ /720p/) ? 2 : 1
+#		end
 
 		case rc.mode
-		when 1; "mplayer -fs -sid 0 #{~rc}"
-		when 2; "mplayer -sid 0 #{~rc}"
-		when 3; "mplayer -vm sdl -sid 0 #{~rc}"
+		when 0; "mplayer -fs -sid 0 #{~rc}"
+		when 1; "mplayer -sid 0 #{~rc}"
+		when 2; "mplayer -vm sdl -sid 0 #{~rc}"
 		else nil end
 	end
 
@@ -23,13 +23,13 @@ module Application
 	def feh(rc)
 		check rc
 		case rc.mode
-		when 4; "feh --bg-scale #{rc.one}"
-		when 5; "feh --bg-tile #{rc.one}"
-		when 6; "feh --bg-center #{rc.one}"
-		when 2; "gimp #{~rc}"
-		when 1; "feh -F #{~rc}"
-		else "feh #{~rc}"
-		end
+		when 0; "feh #{~rc}"
+		when 1; "feh --bg-scale #{rc.one}"
+		when 2; "feh --bg-tile #{rc.one}"
+		when 3; "feh --bg-center #{rc.one}"
+		when 4; "gimp #{~rc}"
+		when 5; "feh -F #{~rc}"
+		else nil end
 	end
 
 	def interpreted_language(rc)
@@ -54,5 +54,29 @@ module Application
 
 		"vi #{commands} #{~rc}"
 	end
+
+	def javac(rc)
+		"javac #{~rc}"
+	end
+
+	def java(rc)
+		"java #{rc.files.map{|x| ~x.before_last('.')}.join(' ')}"
+	end
+
+	def firefox(rc)
+		"firefox #{~rc}"
+	end
+
+	def make(rc)
+		case rc.mode
+		when 0; "make"
+		when 1; "make install"
+		when 2; "make clear"
+		else nil end
+	end
+	
+	def rake(rc)
+		"rake"
+	end
 end
 
diff --git a/data/types.rb b/data/types.rb
index 84f8295a..02c9cc1e 100644
--- a/data/types.rb
+++ b/data/types.rb
@@ -6,6 +6,14 @@ class Directory::Entry
 		## directories or sockets don't have any handler
 		use.no_handler if dir? or socket?
 
+		case @basename
+		when 'Makefile'
+			log "i use make"
+			use.make
+		when /^[Rr]akefile(.rb)?$/
+			use.rake
+		end
+
 		## at first, look at the mime type
 		case @mimetype
 		when /^video|audio/
@@ -17,9 +25,18 @@ class Directory::Entry
 		when /^image/
 			use.feh
 
-		when /^(text|application).x-(#{INTERPRETED_LANGUAGES.join('|')})$/
+		when /^(text|application)\/x-(#{INTERPRETED_LANGUAGES.join('|')})$/
 			use.interpreted_language
 
+		when 'text/x-java'
+			use.javac
+
+		when 'application/java-vm'
+			use.java
+
+		when 'text/html', 'application/x-shockwave-flash'
+			use.firefox
+
 		end
 
 		## second, look at the extension
diff --git a/ranger.rb b/ranger.rb
index 6f3f3aa2..3d930d4e 100755
--- a/ranger.rb
+++ b/ranger.rb
@@ -39,11 +39,6 @@ load 'data/apps.rb'
 load 'data/colorscheme/default.rb'
 load 'data/screensaver/clock.rb'
 
-unless ARGV.empty? or File.directory?(pwd)
-	exec(Fm.getfilehandler_frompath(pwd))
-end
-
-include CLI
 include Debug
 
 Debug.setup( :name   => 'nyuron',
@@ -52,6 +47,15 @@ Debug.setup( :name   => 'nyuron',
 
 ERROR_STREAM = File.open('/tmp/errorlog', 'a')
 
+if pwd and !ARGV.empty? and !File.directory?(pwd)
+	file = Directory::Entry.new(pwd)
+	file.get_data
+	Action.run(RunContext.new(file, 0, 'c'))
+	exit
+end
+
+include CLI
+
 Signal.trap(Scheduler::UPDATE_SIGNAL) do
 	Fm.refresh
 end