summary refs log tree commit diff stats
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
parentc5450bd180efd57f9cbd9d3315391b8cc8238be3 (diff)
downloadranger-8f2f1767a970422c104761b1666c718c54c29d91.tar.gz
finished #52, special characters in tab completion
-rw-r--r--TODO2
-rw-r--r--ranger/ext/shell_escape.py14
-rw-r--r--ranger/fsobject/fsobject.py9
-rw-r--r--ranger/gui/widgets/console.py4
4 files changed, 26 insertions, 3 deletions
diff --git a/TODO b/TODO
index d475f099..78aaeb97 100644
--- a/TODO
+++ b/TODO
@@ -61,7 +61,7 @@ Bugs
    (X) #41  10/01/17  capital file extensions are not recognized
    (X) #46  10/01/19  old username displayed after using su
    (X) #49  10/01/19  fix unit tests :'(
-   ( ) #52  10/01/23  special characters in tab completion
+   (X) #52  10/01/23  special characters in tab completion
    (X) #54  10/01/23  max_dirsize_for_autopreview not working
    ( ) #60  10/02/05  utf support improvable
    (X) #62  10/02/15  curs_set can raise an exception
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 = {}
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488