summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/defaults/commands.py15
-rw-r--r--ranger/ext/keybindings.py26
2 files changed, 36 insertions, 5 deletions
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index a909cee9..870fd127 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -810,6 +810,21 @@ class help_(Command):
 		self.fm.display_help()
 
 
+class copymap(Command):
+	"""
+	:copymap <keys> <newkeys1> [<newkeys2>...]
+	Copies a keybinding from <keys> to <newkeys>
+	"""
+	context = 'browser'
+
+	def execute(self):
+		if not self.arg(1) or not self.arg(2):
+			return self.notify("Not enough arguments", bad=True)
+
+		for arg in self.args[1:]:
+			self.fm.env.keymaps.copy(self.context, self.arg(1), arg)
+
+
 class map_(Command):
 	"""
 	:map <keysequence> <command>
diff --git a/ranger/ext/keybindings.py b/ranger/ext/keybindings.py
index 133da83b..fba025f8 100644
--- a/ranger/ext/keybindings.py
+++ b/ranger/ext/keybindings.py
@@ -16,6 +16,7 @@
 from ranger.ext.keybinding_parser import (parse_keybinding,
 	ANYKEY, PASSIVE_ACTION, QUANT_KEY)
 import sys
+import copy
 
 PY3 = sys.version > '3'
 
@@ -27,6 +28,12 @@ class KeyMaps(dict):
 		self.keybuffer = keybuffer
 		self.used_keymap = None
 
+	def use_keymap(self, keymap_name):
+		self.keybuffer.keymap = self.get(keymap_name, dict())
+		if self.used_keymap != keymap_name:
+			self.used_keymap = keymap_name
+			self.keybuffer.clear()
+
 	def bind(self, context, keys, leaf):
 		try:
 			pointer = self[context]
@@ -45,11 +52,20 @@ class KeyMaps(dict):
 				pointer[key] = pointer = dict()
 		pointer[last_key] = leaf
 
-	def use_keymap(self, keymap_name):
-		self.keybuffer.keymap = self.get(keymap_name, dict())
-		if self.used_keymap != keymap_name:
-			self.used_keymap = keymap_name
-			self.keybuffer.clear()
+	def copy(self, context, source, target):
+		try:
+			pointer = self[context]
+		except:
+			self[context] = pointer = dict()
+		if PY3:
+			source = source.encode('utf-8').decode('latin-1')
+		source = list(parse_keybinding(source))
+		if not source:
+			return
+
+		for key in source:
+			pointer = pointer[key]
+		self.bind(context, target, copy.deepcopy(pointer))
 
 
 class KeyBuffer(object):
ed8d4c173d9abbd0a1bd76d6afe69ccb'>^
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