summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-24 16:46:59 +0100
committerhut <hut@lavabit.com>2010-02-24 23:54:17 +0100
commit8f2f1767a970422c104761b1666c718c54c29d91 (patch)
tree3a625798abdc293f523754d952f0f59d4c1bf482 /ranger
parentc5450bd180efd57f9cbd9d3315391b8cc8238be3 (diff)
downloadranger-8f2f1767a970422c104761b1666c718c54c29d91.tar.gz
finished #52, special characters in tab completion
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/shell_escape.py14
-rw-r--r--ranger/fsobject/fsobject.py9
-rw-r--r--ranger/gui/widgets/console.py4
3 files changed, 25 insertions, 2 deletions
diff --git a/ranger/ext/shell_escape.py b/ranger/ext/shell_escape.py
index 8a78fc53..682cd86f 100644
--- a/ranger/ext/shell_escape.py
+++ b/ranger/ext/shell_escape.py
@@ -16,5 +16,19 @@
 A function to escape metacharacters of arguments for shell commands.
 """
 
+META_CHARS = (' ', "'", '"', '`', '&', '|', ';',
+		'$', '!', '(', ')', '[', ']', '<', '>')
+META_DICT = dict([(mc, '\\' + mc) for mc in META_CHARS])
+
 def shell_escape(string):
+	"""Escapes by quoting"""
 	return "'" + str(string).replace("'", "'\\''") + "'"
+
+
+def shell_escape2(arg):
+	"""Escapes by adding backslashes"""
+	arg = str(arg)
+	arg = arg.replace('\\', '\\\\') # make sure this comes at the start
+	for k, v in META_DICT.items():
+		arg = arg.replace(k, v)
+	return arg
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 3721aa54..4b734e8a 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -18,6 +18,8 @@ DOCUMENT_BASENAMES = 'README TODO LICENSE COPYING INSTALL'.split()
 
 from . import T_FILE, T_DIRECTORY, T_UNKNOWN, T_NONEXISTANT, BAD_INFO
 from ranger.shared import MimeTypeAware, FileManagerAware
+from ranger.ext.shell_escape import shell_escape2
+
 class FileSystemObject(MimeTypeAware, FileManagerAware):
 	is_file = False
 	is_directory = False
@@ -26,6 +28,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 	path = None
 	basename = None
 	basename_lower = None
+	_shell_escaped_basename = None
 	dirname = None
 	extension = None
 	exists = False
@@ -76,6 +79,12 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 		self.set_mimetype()
 		self.use()
 
+	@property
+	def shell_escaped_basename(self):
+		if self._shell_escaped_basename is None:
+			self._shell_escaped_basename = shell_escape2(self.basename)
+		return self._shell_escaped_basename
+
 	def get_description(self):
 		return "Loading " + str(self)
 
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 5439b2a8..34c8abf5 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -413,9 +413,9 @@ class OpenConsole(ConsoleWithTab):
 			return self.line + '%s '
 		else:
 			before_word, start_of_word = self.line.rsplit(' ', 1)
-			return (before_word + ' ' + file.basename \
+			return (before_word + ' ' + file.shell_escaped_basename \
 					for file in self.fm.env.pwd.files \
-					if file.basename.startswith(start_of_word))
+					if file.shell_escaped_basename.startswith(start_of_word))
 
 	def _substitute_metachars(self, command):
 		dct = {}
cab826b16d78b3f8689fd0b5f9'>^
0a57c4de ^
5bc38b6b ^
25a6252a ^
883dbe19 ^
0a57c4de ^
9b177a9e ^
32da6548 ^

0a57c4de ^
9b177a9e ^
acd2d230 ^

32da6548 ^
0fb27dc4 ^



ba286c54 ^
a2726b6a ^
ba286c54 ^

ac410445 ^
ba286c54 ^

bc9e6b79 ^
a2726b6a ^
ba286c54 ^
e043029a ^






ba286c54 ^
88f423af ^
ba286c54 ^

32da6548 ^
8e9bf083 ^

a2726b6a ^
de8975c0 ^

8e9bf083 ^
bfa4a2ef ^
883dbe19 ^
ad926352 ^

8e9bf083 ^


2b7894cc ^
d853284f ^
a2726b6a ^
acd2d230 ^
9b177a9e ^
a2726b6a ^

acd2d230 ^
a2726b6a ^
acd2d230 ^

524c7a86 ^
acd2d230 ^

2b7894cc ^
acd2d230 ^

d853284f ^


a2726b6a ^
32da6548 ^
665c3441 ^
a978bb12 ^
3aad0523 ^
a978bb12 ^
a2726b6a ^
83385cdb ^


665c3441 ^
a2726b6a ^
11181100 ^



0fb27dc4 ^
3e325a61 ^
a2726b6a ^
aa0c6383 ^
a0a4fd04 ^
c614cc28 ^
4e1ffa6b ^
3e325a61 ^
2c94ee5a ^


a2726b6a ^
2c94ee5a ^




3e325a61 ^
3e325a61 ^
a2726b6a ^
8c8c18c6 ^
a0a4fd04 ^
b6b7dd5a ^
3e325a61 ^
c81931c3 ^
3e325a61 ^
c81931c3 ^

a2726b6a ^
c81931c3 ^
3e325a61 ^
a2726b6a ^
8c8c18c6 ^
a0a4fd04 ^
a4b53550 ^
3e325a61 ^






53f2a4a3 ^


a2726b6a ^
11181100 ^




a2726b6a ^
53f2a4a3 ^
a2726b6a ^
83385cdb ^


41fe8c22 ^
a2726b6a ^
4ec005e4 ^



a9d55dec ^

a2726b6a ^
4e1ffa6b ^
a0a4fd04 ^
4ec005e4 ^
4e1ffa6b ^
a9d55dec ^
a2726b6a ^
4e1ffa6b ^
a0a4fd04 ^
a4b53550 ^
e69f9475 ^
a9d55dec ^







a2726b6a ^
4e1ffa6b ^
9224331d ^
a4b53550 ^
e69f9475 ^
41fe8c22 ^


a9d55dec ^

53f2a4a3 ^


a2726b6a ^
4ec005e4 ^




a2726b6a ^
53f2a4a3 ^
150015fa ^

77e819e8 ^

150015fa ^
a2726b6a ^

41fe8c22 ^
a2726b6a ^
8c8c18c6 ^
a0a4fd04 ^
50271493 ^
a0a4fd04 ^
41fe8c22 ^

8c8c18c6 ^
41fe8c22 ^
8c8c18c6 ^
150015fa ^
80665ea0 ^
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258