summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-03 06:20:43 +0200
committerhut <hut@lavabit.com>2011-10-03 06:20:43 +0200
commit9c4f3cc87b9c15999cb07730caf9657a71b96d0c (patch)
tree6b1c5ab834aa9e7436e192cc229bf502c0f667c0 /ranger
parent4bea11d661ee302257966bc9fc60c712b72f4e7d (diff)
downloadranger-9c4f3cc87b9c15999cb07730caf9657a71b96d0c.tar.gz
defaults.commands: added alias command, overhauled alias system
Diffstat (limited to 'ranger')
-rw-r--r--ranger/api/commands.py15
-rw-r--r--ranger/core/helper.py2
-rw-r--r--ranger/defaults/commands.py15
-rw-r--r--ranger/defaults/rc.conf8
4 files changed, 24 insertions, 16 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index a22fd0b3..093e93da 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -21,20 +21,20 @@ from ranger.core.shared import FileManagerAware
 from ranger.ext.lazy_property import lazy_property
 from ranger.ext.command_parser import LazyParser as parse
 
-# A dummy that allows the generation of docstrings in ranger.defaults.commands
-def alias(*_):
-	pass
+def alias(*_): pass # COMPAT
 
 class CommandContainer(object):
 	def __init__(self):
-		self.aliases = {}
 		self.commands = {}
 
 	def __getitem__(self, key):
 		return self.commands[key]
 
 	def alias(self, new, old):
-		self.aliases[new] = old
+		try:
+			self.commands[new] = self.commands[old]
+		except:
+			pass
 
 	def load_commands_from_module(self, module):
 		for varname, var in vars(module).items():
@@ -47,11 +47,6 @@ class CommandContainer(object):
 						self.commands[varname] = var
 			except TypeError:
 				pass
-		for new, old in self.aliases.items():
-			try:
-				self.commands[new] = self.commands[old]
-			except:
-				pass
 
 	def load_commands_from_object(self, obj, filtr):
 		for attribute_name in dir(obj):
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 090a475a..9a403a15 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -89,7 +89,6 @@ def load_settings(fm, clean):
 		exclude = ['settings']
 		include = [name for name in dir(Actions) if name not in exclude]
 		comcont.load_commands_from_object(fm, include)
-		ranger.api.commands.alias = comcont.alias
 		try:
 			import commands
 			comcont.load_commands_from_module(commands)
@@ -155,7 +154,6 @@ def load_settings(fm, clean):
 		allow_access_to_confdir(ranger.arg.confdir, False)
 	else:
 		comcont = ranger.api.commands.CommandContainer()
-		ranger.api.commands.alias = comcont.alias
 		from ranger.defaults import commands, apps
 		comcont = ranger.api.commands.CommandContainer()
 		exclude = ['settings']
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index 60e3279d..a9a232b9 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -59,10 +59,17 @@ from ranger.api.commands import *
 from ranger.ext.get_executables import get_executables
 from ranger.core.runner import ALLOWED_FLAGS
 
-alias('e', 'edit')
-alias('q', 'quit')
-alias('q!', 'quitall')
-alias('qall', 'quitall')
+class alias(Command):
+	"""
+	:alias <newcommand> <oldcommand>
+
+	Copies the oldcommand as newcommand.
+	"""
+	def execute(self):
+		if not self.arg(1) or not self.arg(2):
+			self.fm.notify('Syntax: alias <newcommand> <oldcommand>', bad=True)
+		else:
+			self.fm.commands.alias(self.arg(1), self.arg(2))
 
 class cd(Command):
 	"""
diff --git a/ranger/defaults/rc.conf b/ranger/defaults/rc.conf
index 9ba2ed8f..ecd64501 100644
--- a/ranger/defaults/rc.conf
+++ b/ranger/defaults/rc.conf
@@ -17,6 +17,14 @@
 # on the UI such as :delete or :mark.
 # ===================================================================
 
+# ===================================================================
+# == Command Aliases in the Console
+# ===================================================================
+
+alias e    edit
+alias q    quit
+alias q!   quitall
+alias qall quitall
 
 # ===================================================================
 # == Define keys for the browser
6c96a437 ^
78c50205 ^
093b45e7 ^
b0bf5321 ^
eb45abde ^
21fc6180 ^


6c96a437 ^
78c50205 ^
21fc6180 ^

eb45abde ^
093b45e7 ^

85553e52 ^
b75d9d45 ^




78c50205 ^
cfa5a9f8 ^
b75d9d45 ^





c442a5ad ^
093b45e7 ^



dad3bedd ^
21fc6180 ^

eb45abde ^
21fc6180 ^
78c50205 ^
21fc6180 ^



3c4c9c08 ^
21fc6180 ^




3c4c9c08 ^
21fc6180 ^


c442a5ad ^
21fc6180 ^




3473c63a ^
af023b32 ^

d57bf669 ^
af023b32 ^
d57bf669 ^

3473c63a ^
8e60380e ^
af023b32 ^
8e60380e ^

514f0e34 ^








4a943d4e ^












b75d9d45 ^
dad3bedd ^


4a943d4e ^
















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