summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/commandlist.py30
-rw-r--r--test/tc_commandlist.py15
2 files changed, 35 insertions, 10 deletions
diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py
index c40d0a5b..302564c9 100644
--- a/ranger/container/commandlist.py
+++ b/ranger/container/commandlist.py
@@ -132,14 +132,10 @@ class CommandList(object):
 		existing = self._str_to_tuple(existing)
 		new = tuple(map(self._str_to_tuple, new))
 
-		try:
-			cmd = self.paths[existing]
-		except KeyError:
-			self.unbind(*new)
-		else:
-			for key in new:
-				self.paths[key] = cmd
-				cmd.keys |= set([key])
+		obj = AliasedCommand(_make_getter(self.paths, existing), new)
+
+		for key in new:
+			self.paths[key] = obj
 
 	def unbind(self, *keys):
 		i = len(self.commandlist)
@@ -179,6 +175,16 @@ class Command(object):
 #	def __str__(self):
 #		return 'Cmd({0})'.format(str(self.keys))
 
+class AliasedCommand(Command):
+	def __init__(self, getter, keys):
+		self.getter = getter
+		self.keys = set(keys)
+
+	def get_execute(self):
+		return self.getter()
+
+	execute = property(get_execute)
+
 class Hint(object):
 	"""Hints display text without clearing the keybuffer"""
 
@@ -191,3 +197,11 @@ class Hint(object):
 
 #	def __str__(self):
 #		return 'Hint({0})'.format(str(self.keys))
+
+def _make_getter(paths, key):
+	def getter():
+		try:
+			return paths[key].execute
+		except:
+			return lambda: None
+	return getter
diff --git a/test/tc_commandlist.py b/test/tc_commandlist.py
index 5062be9f..f1edfa20 100644
--- a/test/tc_commandlist.py
+++ b/test/tc_commandlist.py
@@ -10,6 +10,7 @@ class Test(TestCase):
 	def test_commandist(self):
 		cl = CL()
 		fnc = lambda arg: 1
+		fnc2 = lambda arg: 2
 		dmy = cl.dummy_object
 
 		cl.bind(fnc, 'aaaa')
@@ -51,14 +52,24 @@ class Test(TestCase):
 		self.assertEqual(dmy, cl['aaa'])
 		self.assertEqual(fnc, cl['aaaa'].execute)
 
+		# ------------------------ test aliases
 		cl.alias('aaaa', 'c')
 		cl.rebuild_paths()
-		self.assertEqual(cl['c'], cl['aaaa'])
+
+		self.assertEqual(cl['c'].execute, cl['aaaa'].execute)
+
+		cl.bind(fnc2, 'aaaa')
+		cl.rebuild_paths()
+
+		self.assertEqual(cl['c'].execute, cl['aaaa'].execute)
+
 		cl.unbind('c')
 		cl.rebuild_paths()
-		self.assertEqual(fnc, cl['aaaa'].execute)
+
+		self.assertEqual(fnc2, cl['aaaa'].execute)
 		self.assertKeyError(cl, 'c')
 
+		# ----------------------- test clearing
 		cl.clear()
 		self.assertKeyError(cl, 'a')
 		self.assertKeyError(cl, 'aa')