summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/commands.py31
-rw-r--r--ranger/help/console.py4
2 files changed, 35 insertions, 0 deletions
diff --git a/ranger/commands.py b/ranger/commands.py
index a6fc77fb..b3625037 100644
--- a/ranger/commands.py
+++ b/ranger/commands.py
@@ -315,6 +315,37 @@ class edit(Command):
 		return self._tab_directory_content()
 
 
+class eval_(Command):
+	"""
+	:eval <python code>
+
+	Evaluates the python code.
+	`fm' is a reference to the FM instance.
+	To display text, use the function `p'.
+
+	Examples:
+	:eval fm
+	:eval len(fm.env.directories)
+	:eval p("Hello World!")
+	"""
+	name = 'eval'
+
+	def execute(self):
+		code = parse(self.line).rest(1)
+		fm = self.fm
+		p = fm.notify
+		try:
+			try:
+				result = eval(code)
+			except SyntaxError:
+				exec(code)
+			else:
+				if result:
+					p(result)
+		except Exception as err:
+			p(err)
+
+
 class rename(Command):
 	"""
 	:rename <newname>
diff --git a/ranger/help/console.py b/ranger/help/console.py
index 1ea06f90..cd382d2e 100644
--- a/ranger/help/console.py
+++ b/ranger/help/console.py
@@ -77,6 +77,10 @@ it conflicts with ":cd".
 :edit <filename>
       Opens the specified file in the text editor.
 
+:eval <python_code>
+      Evaluates the given code inside ranger. `fm' is a reference to
+      the filemanager instance, `p' is a function to print text.
+
 :filter <string>
       Displays only files which contain <string> in their basename.
 
n138'>138 139 140 141 142 143 144 145
















































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
a>
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79