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
to CLI, cleanups' href='/akspecs/ranger/commit/ranger.rb?h=v0.2.6&id=8a6f5eab0b884acd58ed86c00a30b57901442be6'>8a6f5eab ^
34bfb32e ^
adfea091
8a6f5eab ^



adfea091
adfea091
7fe51696 ^


34bfb32e ^




a0de7f95 ^

8a6f5eab ^
2887ca25 ^
adfea091
adfea091
a0de7f95 ^
34bfb32e ^





adfea091
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