summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/commands.py1
-rw-r--r--ranger/core/actions.py90
-rw-r--r--ranger/defaults/commands.py2
-rw-r--r--ranger/gui/widgets/console.py10
4 files changed, 52 insertions, 51 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index 74a8ff99..1941de2c 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -86,6 +86,7 @@ class Command(FileManagerAware):
 	name = None
 	allow_abbrev = True
 	resolve_macros = True
+	escape_macros_for_shell = False
 	quantifier = None
 	_shifted = 0
 
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index d0e21fbc..cde80431 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -98,35 +98,46 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def execute_console(self, string='', wildcards=[], quantifier=None):
 		"""Execute a command for the console"""
 		command_name = string.split()[0]
-		try:
-			cmd_class = self.commands.get_command(command_name)
-		except:
+		cmd_class = self.commands.get_command(command_name, abbrev=False)
+		if cmd_class is None:
 			self.notify("Command not found: `%s'" % command_name, bad=True)
-		else:
-			cmd = cmd_class(string)
-			if cmd.resolve_macros and _MacroTemplate.delimiter in string:
-				macros = dict(('any%d'%i, key_to_string(char)) \
-						for i, char in enumerate(wildcards))
-				if 'any0' in macros:
-					macros['any'] = macros['any0']
-				try:
-					string = self.substitute_macros(string, additional=macros)
-				except ValueError as e:
-					if ranger.arg.debug:
-						raise
-					else:
-						return self.notify(e)
+			return
+		cmd = cmd_class(string)
+		if cmd.resolve_macros and _MacroTemplate.delimiter in string:
+			macros = dict(('any%d'%i, key_to_string(char)) \
+					for i, char in enumerate(wildcards))
+			if 'any0' in macros:
+				macros['any'] = macros['any0']
 			try:
-				cmd_class(string, quantifier=quantifier).execute()
-			except Exception as e:
+				string = self.substitute_macros(string, additional=macros,
+						escape=cmd.escape_macros_for_shell)
+			except ValueError as e:
 				if ranger.arg.debug:
 					raise
 				else:
-					self.notify(e)
-
-	def substitute_macros(self, string, additional=dict()):
-		result = _MacroTemplate(string).safe_substitute(self._get_macros(),
-				**additional)
+					return self.notify(e)
+		try:
+			cmd_class(string, quantifier=quantifier).execute()
+		except Exception as e:
+			if ranger.arg.debug:
+				raise
+			else:
+				self.notify(e)
+
+	def substitute_macros(self, string, additional=dict(), escape=False):
+		macros = self._get_macros()
+		macros.update(additional)
+		if escape:
+			for key, value in macros.items():
+				if isinstance(value, list):
+					macros[key] = " ".join(shell_quote(s) for s in value)
+				elif value != MACRO_FAIL:
+					macros[key] = shell_quote(value)
+		else:
+			for key, value in macros.items():
+				if isinstance(value, list):
+					macros[key] = " ".join(value)
+		result = _MacroTemplate(string).safe_substitute(macros)
 		if MACRO_FAIL in result:
 			raise ValueError("Could not apply macros to `%s'" % string)
 		return result
@@ -134,25 +145,22 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def _get_macros(self):
 		macros = {}
 
-		macros['rangerdir'] = shell_quote(ranger.RANGERDIR)
+		macros['rangerdir'] = ranger.RANGERDIR
 
 		if self.fm.env.cf:
-			macros['f'] = shell_quote(self.fm.env.cf.basename)
+			macros['f'] = self.fm.env.cf.basename
 		else:
 			macros['f'] = MACRO_FAIL
 
-		macros['s'] = ' '.join(shell_quote(fl.basename) \
-				for fl in self.fm.env.get_selection())
+		macros['s'] = [fl.basename for fl in self.fm.env.get_selection()]
 
-		macros['c'] = ' '.join(shell_quote(fl.path)
-				for fl in self.fm.env.copy)
+		macros['c'] = [fl.path for fl in self.fm.env.copy]
 
-		macros['t'] = ' '.join(shell_quote(fl.basename)
-				for fl in self.fm.env.cwd.files
-				if fl.realpath in self.fm.tags)
+		macros['t'] = [fl.basename for fl in self.fm.env.cwd.files
+				if fl.realpath in self.fm.tags]
 
 		if self.fm.env.cwd:
-			macros['d'] = shell_quote(self.fm.env.cwd.path)
+			macros['d'] = self.fm.env.cwd.path
 		else:
 			macros['d'] = '.'
 
@@ -165,11 +173,10 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				continue
 			tab_dir = self.fm.env.get_directory(tab_dir_path)
 			i = str(i)
-			macros[i + 'd'] = shell_quote(tab_dir_path)
-			macros[i + 's'] = ' '.join(shell_quote(fl.path)
-				for fl in tab_dir.get_selection())
+			macros[i + 'd'] = tab_dir_path
+			macros[i + 's'] = [fl.path for fl in tab_dir.get_selection()]
 			if tab_dir.pointed_obj:
-				macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
+				macros[i + 'f'] = tab_dir.pointed_obj.path
 			else:
 				macros[i + 'f'] = MACRO_FAIL
 
@@ -189,13 +196,12 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 			next_tab_path = self.fm.tabs[first_tab]
 		next_tab = self.fm.env.get_directory(next_tab_path)
 
-		macros['D'] = shell_quote(next_tab)
+		macros['D'] = next_tab
 		if next_tab.pointed_obj:
-			macros['F'] = shell_quote(next_tab.pointed_obj.path)
+			macros['F'] = next_tab.pointed_obj.path
 		else:
 			macros['F'] = MACRO_FAIL
-		macros['S'] = ' '.join(shell_quote(fl.path)
-			for fl in next_tab.get_selection())
+		macros['S'] = [fl.path for fl in next_tab.get_selection()]
 
 		return macros
 
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index 55de33c1..cd76896c 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -171,6 +171,8 @@ class search_inc(Command):
 
 
 class shell(Command):
+	escape_macros_for_shell = True
+
 	def execute(self):
 		line = parse(self.line)
 		if line.chunk(1) and line.chunk(1)[0] == '-':
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 5fcea9d3..ce801a7f 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -294,15 +294,7 @@ class Console(Widget):
 
 	def execute(self, cmd=None):
 		self.allow_close = True
-		if cmd is None:
-			cmd = self._get_cmd()
-
-		if cmd:
-			try:
-				cmd.execute()
-			except Exception as error:
-				self.fm.notify(error)
-
+		self.fm.execute_console(self.line)
 		if self.allow_close:
 			self.close(trigger_cancel_function=False)
 
65361948 ^





672e3e50 ^





65361948 ^
c5ffb6e1 ^

65361948 ^



672e3e50 ^




65361948 ^
672e3e50 ^
672e3e50 ^



65361948 ^


672e3e50 ^
672e3e50 ^

65361948 ^





672e3e50 ^





c5ffb6e1 ^
65361948 ^
c5ffb6e1 ^

65361948 ^



672e3e50 ^




65361948 ^
672e3e50 ^
672e3e50 ^



65361948 ^


672e3e50 ^
672e3e50 ^

65361948 ^







672e3e50 ^





65361948 ^





672e3e50 ^




65361948 ^
672e3e50 ^
672e3e50 ^
672e3e50 ^



65361948 ^


672e3e50 ^
672e3e50 ^
672e3e50 ^
65361948 ^






c5ffb6e1 ^







672e3e50 ^



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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231