summary refs log tree commit diff stats
path: root/ranger.py
blob: 2ab5ee1d04d0b06167829ea584ed1774c26e706e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# coding=utf-8

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: 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

	finally:
		if cd_after_exit:
			try: sys.__stderr__.write(env.pwd.path)
			except: pass

if __name__ == "__main__": main()