summary refs log tree commit diff stats
path: root/ranger.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-27 21:52:23 +0100
committerhut <hut@lavabit.com>2009-11-27 21:52:23 +0100
commit0b5c4cbe45f18bb9b5cd412b3afbee59ae8d5a7b (patch)
treea022f8542a57eaf7bcfa4530248a797bd6e37ee6 /ranger.py
parentdd7a4f636fcc3c68b061d5af265aeaf38f70e45b (diff)
downloadranger-0b5c4cbe45f18bb9b5cd412b3afbee59ae8d5a7b.tar.gz
cd-after-exit
Diffstat (limited to 'ranger.py')
-rwxr-xr-xranger.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/ranger.py b/ranger.py
index cfac83c3..2ab5ee1d 100755
--- a/ranger.py
+++ b/ranger.py
@@ -1,13 +1,21 @@
 #!/usr/bin/python
 # coding=utf-8
 
-# TODO: cd after exit
+import sys, os
+
+# 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
+	sys.stderr = sys.stdout
+	del sys.argv[1]
+except:
+	cd_after_exit = False
 
 from ranger import debug, fm, options, environment, command, keys
 from ranger.defaultui import DefaultUI as UI
 
-# TODO: find out the real name of this script and include files relative to here
-
 # TODO: Parse arguments
 
 # TODO: load config
@@ -32,7 +40,12 @@ def main():
 	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()