about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/commandlist.py11
-rw-r--r--test/tc_commandlist.py8
2 files changed, 19 insertions, 0 deletions
diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py
index 2ba22ef7..e66871ea 100644
--- a/ranger/container/commandlist.py
+++ b/ranger/container/commandlist.py
@@ -126,6 +126,17 @@ class CommandList(object):
 		self.commandlist.append(obj)
 		for key in obj.keys:
 			self.paths[key] = obj
+	
+	def alias(self, existing, *new):
+		"""bind the <new> keys to the command of the <existing> key"""
+		existing = self._str_to_tuple(existing)
+		new = tuple(map(self._str_to_tuple, new))
+
+		cmd = self.paths[existing]
+
+		for key in new:
+			self.paths[key] = cmd
+			cmd.keys |= set([key])
 
 	def unbind(self, *keys):
 		i = len(self.commandlist)
diff --git a/test/tc_commandlist.py b/test/tc_commandlist.py
index 86afdc99..5062be9f 100644
--- a/test/tc_commandlist.py
+++ b/test/tc_commandlist.py
@@ -51,6 +51,14 @@ class Test(TestCase):
 		self.assertEqual(dmy, cl['aaa'])
 		self.assertEqual(fnc, cl['aaaa'].execute)
 
+		cl.alias('aaaa', 'c')
+		cl.rebuild_paths()
+		self.assertEqual(cl['c'], cl['aaaa'])
+		cl.unbind('c')
+		cl.rebuild_paths()
+		self.assertEqual(fnc, cl['aaaa'].execute)
+		self.assertKeyError(cl, 'c')
+
 		cl.clear()
 		self.assertKeyError(cl, 'a')
 		self.assertKeyError(cl, 'aa')