about summary refs log tree commit diff stats
path: root/code/fm/fm.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-06-13 02:20:46 +0200
committerhut <hut@lavabit.com>2009-06-13 02:20:46 +0200
commit2887ca25fb58362d5d644ecda5f0bc51c80ec404 (patch)
treeb066f5542d97b1a4a9134d0910692b873fe32363 /code/fm/fm.rb
parent325ec37f65172b5b640d998eba300d86d1ddbfa5 (diff)
downloadranger-2887ca25fb58362d5d644ecda5f0bc51c80ec404.tar.gz
rewrite of the way files are executed, easier config
Diffstat (limited to 'code/fm/fm.rb')
-rw-r--r--code/fm/fm.rb49
1 files changed, 29 insertions, 20 deletions
diff --git a/code/fm/fm.rb b/code/fm/fm.rb
index 5033c161..91b17f2d 100644
--- a/code/fm/fm.rb
+++ b/code/fm/fm.rb
@@ -1,3 +1,5 @@
+require 'thread'
+
 OPTIONS = {
 	'hidden' => false,
 	'sort' => :name,
@@ -18,6 +20,8 @@ module Fm
 	def self.initialize(pwd=nil)
 		@bars = []
 		@bars_thread = nil
+
+		@entering_directory = true
 		
 		@buffer = ''
 		@pwd = nil
@@ -27,33 +31,28 @@ module Fm
 		@trash = File.expand_path('~/.trash')
 		pwd ||= Dir.getwd
 
-		# `' and `` are the original PWD unless overwritten by .fmrc
+		# `' and `` are the original PWD unless overwritten by .rangerrc
 		@memory = {
 			'`' => pwd,
 			'\'' => pwd
 		}
 
-		# Read the .fmrc
-		@fmrc = File.expand_path('~/.fmrc')
-		if (File.exists?(@fmrc))
-			loaded = Marshal.load(File.read(@fmrc)) rescue nil
-			if Hash === loaded
-				@memory.update(loaded)
+		# Read the .rangerrc
+		@rangerrc = File.expand_path('~/.rangerrc')
+		if (File.exists?(@rangerrc))
+			content = File.read(@rangerrc)
+			unless content.empty?
+				loaded = Marshal.load() rescue nil
+				if Hash === loaded
+					@memory.update(loaded)
+				end
 			end
 		end
+		@dump_config_on_exit = true
 
 		# `0 is always the original PWD
 		@memory['0'] = pwd
 
-		# Give me some way to redraw screen while waiting for
-		# input from CLI.geti
-
-#		for i in 1..20
-#			eval "Signal.trap(#{i}) do
-#				log #{i}
-#				exit if #{i} == 9 end"
-#		end
-
 		boot_up(pwd)
 	end
 
@@ -90,10 +89,15 @@ module Fm
 	end
 
 	def dump
-		remember_dir
-		dumped = Marshal.dump(@memory)
-		File.open(@fmrc, 'w') do |f|
-			f.write(dumped)
+		if defined? @dump_config_on_exit
+			begin
+				remember_dir
+				dumped = Marshal.dump(@memory)
+				File.open(@rangerrc, 'w') do |f|
+					f.write(dumped)
+				end
+			rescue Exception
+			end
 		end
 	end
 
@@ -198,6 +202,7 @@ module Fm
 			end
 		end
 
+		@entering_directory = true
 		Dir.chdir(@pwd.path)
 	end
 
@@ -270,5 +275,9 @@ module Fm
 			@bars_thread = nil
 		end
 	end
+
+	def getfiles()
+		@marked.empty? ? [currentfile] : @marked
+	end
 end