about summary refs log tree commit diff stats
path: root/ranger.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-28 17:29:57 +0100
committerhut <hut@lavabit.com>2009-11-28 17:29:57 +0100
commit3d566884280b1db24cb9fa13adde3985f0e7c5a2 (patch)
tree4e84f707b965d1a7bbebf84858a15df6d8c3ef92 /ranger.py
parent419e4aa53fc99c29dce66cd46b7f894efd2d57a8 (diff)
downloadranger-3d566884280b1db24cb9fa13adde3985f0e7c5a2.tar.gz
restructuration
Diffstat (limited to 'ranger.py')
-rwxr-xr-xranger.py66
1 files changed, 33 insertions, 33 deletions
diff --git a/ranger.py b/ranger.py
index a7a1a864..9e8dbd70 100755
--- a/ranger.py
+++ b/ranger.py
@@ -4,6 +4,9 @@
 # An embedded shell script. Assuming this file is /usr/bin/ranger,
 # this hack allows you to use the cd-after-exit feature by typing:
 # source ranger ranger
+# Now when you quit ranger, it should change the directory of the
+# parent shell to where you have last been in ranger.
+# Works with at least bash and zsh.
 """":
 if [ $1 ]; then
 	cd "`$1 --cd-after-exit $@ 3>&1 1>&2 2>&3 3>&-`"
@@ -12,11 +15,14 @@ else
 fi
 return 1
 """
+from ranger.fm import FM
+from ranger.environment import Environment
+from ranger.command import CommandList
+from ranger.conf import keys, options
+from ranger.gui.defaultui import DefaultUI as UI
 
-import sys, os
+import sys, os, locale
 
-# Change the directory of the parent shell after exiting Ranger.
-# Read the comments in wrapper.sh for more info.
 try:
 	assert sys.argv[1] == '--cd-after-exit'
 	cd_after_exit = True
@@ -25,39 +31,33 @@ try:
 except:
 	cd_after_exit = False
 
-from ranger import debug, fm, options, environment, command, keys
-from ranger.defaultui import DefaultUI as UI
-
 # TODO: Parse arguments
 
 # TODO: load config
 
-def main():
-	import locale, os
-	os.stat_float_times(True)
-	locale.setlocale(locale.LC_ALL, 'en_US.utf8')
-
-	try:
-		path = os.path.abspath('.')
-		opt = options.dummy()
-		env = environment.Environment(opt)
-		commandlist = command.CommandList()
-		keys.initialize_commands(commandlist)
-
-		my_ui = UI(env, commandlist)
-		my_fm = fm.FM(env)
-		my_fm.feed(path, my_ui)
-		my_fm.run()
-
-	except BaseException as original_error:
-		try: my_ui.exit()
-		except: pass
-	
-		raise original_error
+os.stat_float_times(True)
+locale.setlocale(locale.LC_ALL, 'en_US.utf8')
 
-	finally:
-		if cd_after_exit:
-			try: sys.__stderr__.write(env.pwd.path)
-			except: pass
+try:
+	path = os.path.abspath('.')
+	opt = options.dummy()
+	env = Environment(opt)
+	commandlist = CommandList()
+	keys.initialize_commands(commandlist)
+
+	my_ui = UI(env, commandlist)
+	my_fm = FM(env)
+	my_fm.feed(path, my_ui)
+	my_fm.run()
+
+except BaseException as original_error:
+	try: my_ui.exit()
+	except: pass
+
+	raise original_error
+
+finally:
+	if cd_after_exit:
+		try: sys.__stderr__.write(env.pwd.path)
+		except: pass
 
-if __name__ == "__main__": main()